Results 1 to 3 of 3
- 01-15-2011, 09:26 AM #1
Member
- Join Date
- Jan 2011
- Posts
- 2
- Rep Power
- 0
Help displaying an array from a seperate class
Okay, What I'm trying to do is take data from an array in my main class, and display it in a different class.
here is my main class:
Java Code:public class CharCreate { public static void main(String args[])throws Exception { int AddSkillPoints = 5; int[] dials = new int[5]; dials[0] = 5; dials[1] = 5; dials[2] = 5; dials[3] = 5; dials[4] = 5; char Input; System.out.println("-----"); System.out.println(""); System.out.println("Press 1 to assign skill points"); System.out.println(""); System.out.println("-----"); do{ Input = (char) System.in.read(); if(Input == '1') { System.out.println("-----"); System.out.println(""); System.out.println("Press A to add 1 point to Dialouge. Current Dialouge points: " + dials[0]); System.out.println(""); System.out.println("Press B to add 1 point to Intellegince. Current Intellegince points:" + dials[1]); System.out.println(""); System.out.println("Press C to add 1 point to Agility. Current Agility points: " + dials[2]); System.out.println(""); System.out.println("Press D to add 1 point to Luck. Current Luck points: " + dials[3]); System.out.println(""); System.out.println("Press E to add 1 point to Strength. Current Strength points: " + dials[4]); System.out.println(""); System.out.println("Unassigned points remaining: " + AddSkillPoints); System.out.println(""); System.out.println("-----"); } else if(Input == 'A') { dials[0] = dials[0] + 1; AddSkillPoints = AddSkillPoints - 1; System.out.println("-----"); System.out.println(""); System.out.println("Press A to add 1 point to Dialouge. Current Dialouge points: " + dials[0]); System.out.println(""); System.out.println("Press B to add 1 point to Intellegince. Current Intellegince points:" + dials[1]); System.out.println(""); System.out.println("Press C to add 1 point to Agility. Current Agility points: " + dials[2]); System.out.println(""); System.out.println("Press D to add 1 point to Luck. Current Luck points: " + dials[3]); System.out.println(""); System.out.println("Press E to add 1 point to Strength. Current Strength points: " + dials[4]); System.out.println(""); System.out.println("Unassigned points remaining: " + AddSkillPoints); System.out.println(""); System.out.println("-----"); } else if(Input == 'B') { dials[1] = dials[1] + 1; AddSkillPoints = AddSkillPoints - 1; System.out.println("-----"); System.out.println(""); System.out.println("Press A to add 1 point to Dialouge. Current Dialouge points: " + dials[0]); System.out.println(""); System.out.println("Press B to add 1 point to Intellegince. Current Intellegince points:" + dials[1]); System.out.println(""); System.out.println("Press C to add 1 point to Agility. Current Agility points: " + dials[2]); System.out.println(""); System.out.println("Press D to add 1 point to Luck. Current Luck points: " + dials[3]); System.out.println(""); System.out.println("Press E to add 1 point to Strength. Current Strength points: " + dials[4]); System.out.println(""); System.out.println("Unassigned points remaining: " + AddSkillPoints); System.out.println(""); System.out.println("-----"); } else if(Input == 'C') { dials[2] = dials[2] + 1; AddSkillPoints = AddSkillPoints - 1; System.out.println("-----"); System.out.println(""); System.out.println("Press A to add 1 point to Dialouge. Current Dialouge points: " + dials[0]); System.out.println(""); System.out.println("Press B to add 1 point to Intellegince. Current Intellegince points:" + dials[1]); System.out.println(""); System.out.println("Press C to add 1 point to Agility. Current Agility points: " + dials[2]); System.out.println(""); System.out.println("Press D to add 1 point to Luck. Current Luck points: " + dials[3]); System.out.println(""); System.out.println("Press E to add 1 point to Strength. Current Strength points: " + dials[4]); System.out.println(""); System.out.println("Unassigned points remaining: " + AddSkillPoints); System.out.println(""); System.out.println("-----"); } else if(Input == 'D') { dials[3] = dials[3] + 1; AddSkillPoints = AddSkillPoints - 1; System.out.println("-----"); System.out.println(""); System.out.println("Press A to add 1 point to Dialouge. Current Dialouge points: " + dials[0]); System.out.println(""); System.out.println("Press B to add 1 point to Intellegince. Current Intellegince points:" + dials[1]); System.out.println(""); System.out.println("Press C to add 1 point to Agility. Current Agility points: " + dials[2]); System.out.println(""); System.out.println("Press D to add 1 point to Luck. Current Luck points: " + dials[3]); System.out.println(""); System.out.println("Press E to add 1 point to Strength. Current Strength points: " + dials[4]); System.out.println(""); System.out.println("Unassigned points remaining: " + AddSkillPoints); System.out.println(""); System.out.println("-----"); } else if(Input == 'E') { dials[4] = dials[4] + 1; AddSkillPoints = AddSkillPoints - 1; System.out.println("-----"); System.out.println(""); System.out.println("Press A to add 1 point to Dialouge. Current Dialouge points: " + dials[0]); System.out.println(""); System.out.println("Press B to add 1 point to Intellegince. Current Intellegince points:" + dials[1]); System.out.println(""); System.out.println("Press C to add 1 point to Agility. Current Agility points: " + dials[2]); System.out.println(""); System.out.println("Press D to add 1 point to Luck. Current Luck points: " + dials[3]); System.out.println(""); System.out.println("Press E to add 1 point to Strength. Current Strength points: " + dials[4]); System.out.println(""); System.out.println("Unassigned points remaining: " + AddSkillPoints); System.out.println(""); System.out.println("-----"); } if(AddSkillPoints == 0) { Review Review = new Review(); } }while(Input != '*'); } }
and the other class
I want to take the array "dials" from the main class and display it in the "Review" class.Java Code:public class Review { public static void Review(String args[])throws Exception { char Input; System.out.println("-----"); System.out.println(""); System.out.println("Your Final Skill levels are:"); System.out.println(""); System.out.println("Dialouge: " + CharCreate.dials[0]); System.out.println(""); System.out.println("Intellegince: " + CharCreate.dials[1]); System.out.println(""); System.out.println("Agility: " + CharCreate.dials[2]); System.out.println(""); System.out.println("Luck: " + CharCreate.dials[3]); System.out.println(""); System.out.println("Strength: " + CharCreate.dials[4]); System.out.println(""); System.out.println("---"); System.out.println(""); System.out.println("Are you happy with these results?"); System.out.println(""); System.out.println("A. Yes"); System.out.println(""); System.out.println("B. No"); System.out.println(""); System.out.println("-----"); do{ Input = (char)System.in.read(); if(Input == 'A') { System.out.println("Done"); } else if(Input == 'B') { CharCreate CharCreate = new CharCreate(); } }while(Input != '*'); } }
When I compile "CharCreate.dials[]" " get a message saying "cannont find variable dials"
What is the correct syntax for this?
- 01-15-2011, 12:51 PM #2
declare the variable outside of the main() method,
Java Code:public class CharCreate { + public static int[] dials = new int[5]; public static void main(String args[])throws Exception { int AddSkillPoints = 5; - int[] dials = new int[5]; dials[0] = 5; dials[1] = 5; dials[2] = 5;
- 01-16-2011, 08:15 AM #3
Member
- Join Date
- Jan 2011
- Posts
- 2
- Rep Power
- 0
Similar Threads
-
Displaying an image through an array
By BariMutation in forum New To JavaReplies: 0Last Post: 12-04-2010, 04:20 AM -
Keyboard Input In A Seperate Class?
By FatalSylence in forum New To JavaReplies: 6Last Post: 10-12-2010, 05:29 AM -
Adding a menu from a seperate class to a JFrame
By minime12358 in forum Advanced JavaReplies: 2Last Post: 07-23-2010, 05:50 PM -
Manipulating components of a seperate GUI Class
By ribbs2521 in forum New To JavaReplies: 1Last Post: 10-20-2009, 10:53 PM -
Problems displaying and array of JPanels
By dousedfirepants in forum New To JavaReplies: 3Last Post: 11-13-2008, 05:47 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks