Passing array to another class?

I have this code which reads in a text file and stores the data in the race array.
import java.io.*;
import java.util.*;
public class Runner {
    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new FileReader("race1.txt"));
        String line;
        while ((line = in.readLine()) != null) {
            String[] race = line.split(",");
            int position = Integer.parseInt(race[0]);
            String name = race[1];
            String team = race[2];
            System.out.println("position=" + position + ", name=" + name + ", team=" + team);
               in.close();
   }What I want to do is use the race array in another class called Results to perform some calculation methods with the results. So far I haven't been able to get anything to work. Anyone got any advice?

I was mistaken. Your array isn't of type Race[] or Runner[], but of String[]. Change the declaration accordingly.
It's not difficult to understand. At one point, you declare a method and define the parameters (in this case a String[]). Once you do that, you have to make sure that you actually do pass a String[] if the method needs one.
There's no difference in handling parameters, regardless if it's an object, an array, or a primitive value.

Similar Messages

  • How to copy an array element in one class to an array in another class?

    Hi,
    I have a ClassRoom class that stores a list of Student objects in an array. How would I copy a Student object from the Student[] array in the ClassRoom class to an array in another class?
    Is it something like this:
    System.arraycopy(Students, 2, AnotherClass.Array, 0, 2);In an array do the items get copied over existing array elements or can the be added to the end? If so, how would I specify add copied object reference to the end of the array in the other class?

    drew22299 wrote:
    Hi,
    I have a ClassRoom class that stores a list of Student objects in an array. How would I copy a Student object from the Student[] array in the ClassRoom class to an array in another class?
    Is it something like this:
    System.arraycopy(Students, 2, AnotherClass.Array, 0, 2);In an array do the items get copied over existing array elements or can the be added to the end? If so, how would I specify add copied object reference to the end of the array in the other class?System.arrayCopy will overwrite whatever is already in the array. It is your job to make sure it copies into the proper array location.
    That being said, you're only moving a single student. This is not something you would use arrayCopy for, as you can just do that with simple assignment. Also, you should consider giving Class a method to add a student to its student list, as the class should know how many students it has and can easily "append" to the array.
    Note: I hope you noticed the quotes around append. Java's arrays are fixed size. Once allocated, their size cannot change. You may want to consider using one of the List implementations (ArrayList, for example) instead.

  • Passing Array to Another Method

    Hello, I created a program with an array in one of the methods. I have been trying to figure out how to correctly pass the array to another method in the same class. I know my problem is in my method delcaration statements. Could someone please show me what I am doing wrong? Please let me know if you have any questions. Thanks for your help.
    import javax.swing.*;
    import java.util.*;
    class Bank1 {
         public static void main(String[] args) {
              Bank1 bank = new Bank1();
              bank.menu();
         //Main Menu that initializes other methods
         public void menu( ) {
              Scanner scanner = new Scanner(System.in);
              System.out.println("Welcome to the bank.  Please choose from the following options:");
              System.out.println("O - Open new account");
              System.out.println("T - Perform transaction on an account");
              System.out.println("Q - Quit program");
              String initial = scanner.next();
              char uInitial = initial.toUpperCase().charAt(0);
              while (uInitial != 'O' && uInitial != 'T' && uInitial != 'Q') {
                   System.out.println("That was an invalid input. Please try again.");
                   System.out.println();
                   initial = scanner.next();
                   uInitial = initial.toUpperCase().charAt(0);
              if (uInitial == 'O') newAccount();
              if (uInitial == 'T') transaction();
         //Method that creates new bank account
         public Person[] newAccount( ) {
              Person[] userData = new Person[1];
              for (int i = 0; i < userData.length; i++) {
                   Scanner scanner1 = new Scanner(System.in);
                   System.out.println("Enter your first and last name:");
                   String name = scanner1.next();
                   Scanner scanner2 = new Scanner(System.in);
                   System.out.println("Enter your address:");
                   String address = scanner2.next();
                   Scanner scanner3 = new Scanner(System.in);
                   System.out.println("Enter your telephone number:");
                   int telephone = scanner3.nextInt();
                   Scanner scanner4 = new Scanner(System.in);
                   System.out.println("Enter an initial balance:");
                   int balance = scanner4.nextInt();
                   int account = i + 578;
                   userData[i] = new Person( );
                   userData.setName               ( name );
                   userData[i].setAddress          ( address );
                   userData[i].setTelephone     ( telephone );
                   userData[i].setBalance          ( balance     );
                   userData[i].setAccount          ( account     );
                   System.out.println();
                   System.out.println("Your bank account number is: " + userData[i].getAccount());
              return userData;
              menu();
         //Method that gives transaction options
         public void transaction(Person userData[] ) {
              System.out.println(userData[0].getBalance());

    Thank you jverd, I was able to get that to work for me.
    I have another basic question about arrarys now. In all of the arrary examples I have seen, the array is populated all at once using a for statement like in my program.
    userData = new Person[50];
    for (int i = 0; i < userData.length; i++) In my program though, I want it to only fill the first array parameter and then go up to the main menu. If the user chooses to add another account, the next spot in the array will be used. Can someone point me in the right direction for doing this?

  • Help please! Using an array in another class

    Hello, I'm new to JAVA and I'm trying to pass an array from one class to another, but I can't get it right. I've been able to get individual values on at a time.
    If any one can help me out and give me a quick sample of how to do it,
    I've done this below.
    Is it as simple as an individual value - but just calling it an array - instead of say a string - or is it more complex. Please Help
    class BoxVol extends Box {
    public static void main (String args[]) {
    Box ob1 = new Box();
    int[] vol;
    ob1.getLength();
    vol = ob1.getLength();
    System.out.println("Volume is : " + vol);
    } class Box {
    // what are the properties or fields
         private int innerData [];
    //public String length2 = "text";
    // what are the actions or methods
    public void setLength(String p)
         innerData = new int [5];
         for (int i=0; i < innerData.length; i++)  {
              innerData = i;
    public int[] getLength()
         return innerData;

    Guss46 wrote:
    hmmm I see, I shouldve seen that last night when I was working on this....but I was very tired....
    I don't have a compiler in front of me now,
    would this solve my problem
    1st :
    ob1.getLength();
    //Should be....
    vol = ob1.getLength();
    No you are missing my point. You original code was calling the getLength method twice. On the first line it did nothing with the returned value and on the second you assigned the returned value to vol. But the setLength method is where you actually create the array and assign values to it. So unless you call that method first then you will not have an array at all.
    >
    2nd:
    System.out.println("Volume is : " + vol);
    should be
    System.out.println("Volume is : " + vol.length);
    Yes you could do that but all that will tell you is the length of the array and not what values are in it.
    .or vol[i] to go through it if I make a loop around it??Yep, sounds like a much better idea to me.

  • Calling an array from another class

    Ok I have this little program that I created to display values stored in an array. Well, I want my array to automatically be populated with the same values that are in another array that resides in a different class. Here is my code for the class that I want the values to be displayed:
    import javax.swing.*;
    import java.awt.*;
    public class GUIRead extends JFrame
         double[] interest = new double[3];
         MemicCSVReader[] interestObjectArray = new MemicCSVReader[3];
         interestObjectArray[0] = new MemicCSVReader();
         interestObjectArray[1] = new MemicCSVReader();
         interestObjectArray[2] = new MemicCSVReader():
         for(int x = 0; x < 3; x++)
         JPanel display = new JPanel();
         JTextField interestText = new JTextField(10);
         JPanel display2 = new JPanel();
         JTextField interestText2 = new JTextField(10);
         JPanel display3 = new JPanel();
         JTextField interestText3 = new JTextField(10);
         public GUIRead()
              super("Test");
              setSize(160,200);
              setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              setVisible(true);
              GridLayout config = new GridLayout(3,1);
              FlowLayout config2 = new FlowLayout(FlowLayout.LEFT,10,10);
              Container pane = getContentPane();
              pane.setLayout(config2);
              display.setLayout(config2);
              display.add(interestText);
              interestText.setText(interest[0]);
              interestText.setEditable(false);
              pane.add(display);
              display2.setLayout(config2);
              display2.add(interestText2);
              interestText2.setText(interest[1]);
              interestText2.setEditable(false);
              pane.add(display2);
              display3.setLayout(config2);
              display3.add(interestText3);
              interestText3.setText(interest[2]);
              interestText3.setEditable(false);
              pane.add(display3);
              setContentPane(pane);
         public static void main(String[] args)
              GUIRead run = new GUIRead();
    Here is my code that I want the double[] interest array to pull it's data from:
    public class MemicCSVReader
         double interestArray[];
         MemicCSVReader()
              String[] interestString = {"5.5","5.35","5.75"};
              for(int x = 0; x < 3; x++)
                   interestArray[x] = Double.parseDouble(interestString[x]);
    }

    Ok, thanks for your help. Now I have another problem. I can't get the values to display. Here is my code:
    This is the program that runs the application:
    import javax.swing.*;
    import java.awt.*;
    public class GUIRead extends JFrame
         MemicCSVReader readCSV = new MemicCSVReader();
         double[] interestDouble = readCSV.getInterestArray();
         String[] interest;
         JPanel display = new JPanel();
         JTextField interestText = new JTextField(10);
         JPanel display2 = new JPanel();
         JTextField interestText2 = new JTextField(10);
         JPanel display3 = new JPanel();
         JTextField interestText3 = new JTextField(10);
         public GUIRead()
              super("Test");
              setSize(160,200);
              setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              setVisible(true);
              GridLayout config = new GridLayout(3,1);
              FlowLayout config2 = new FlowLayout(FlowLayout.LEFT,10,10);
              Container pane = getContentPane();
              pane.setLayout(config2);
              display.setLayout(config2);
              display.add(interestText);
              interestText.setEditable(false);
              pane.add(display);
              display2.setLayout(config2);
              display2.add(interestText2);
              interestText2.setEditable(false);
              pane.add(display2);
              display3.setLayout(config2);
              display3.add(interestText3);
              interestText3.setEditable(false);
              pane.add(display3);
              setContentPane(pane);
         public void actionPerformed()
              for(int x = 0; x < 3; x++)
                   interest[x] = Double.toString(interestDouble[x]);
              interestText.setText(interest[0]);
              interestText2.setText(interest[1]);
              interestText3.setText(interest[2]);
         public static void main(String[] args)
              GUIRead run = new GUIRead();
    This is the file that it pulls the array from:
    public class MemicCSVReader
         private double[] InterestArray = new double[3];
         MemicCSVReader()
              double[] InterestArray = {5.5,5.35,5.75};
         public double[] getInterestArray()
              return InterestArray;
    }

  • Using an array in another class to set text of a button

    I am trying to use an array from one class in another to set the text of a button.
    This is the code in the class where i have made the array.
    public class EnterHomeTeam
         public int NumberOfPlayers = 11;
         public String[] PlayerName = new String [NumberOfPlayers];
    private void button1_Click (Object sender, System.EventArgs e)
              PlayerName [0] = this.HGoalKeeper.toString();
              PlayerName [1] = this.HDef1.toString();
              PlayerName [2] = this.HDef2.toString();
              PlayerName [3] = this.HDef3.toString();
              PlayerName [4] = this.HDef4.toString();
              PlayerName [5] = this.HMid1.toString();
              PlayerName [6] = this.HMid2.toString();
              PlayerName [7] = this.HMid3.toString();
              PlayerName [8] = this.HMid4.toString();
              PlayerName [9] = this.HAtt1.toString();
              PlayerName [10] = this.HAtt2.toString();     
              Players IM = new Players();
              this.Hide();
              IM.Show();
    }Then in the class where i want to use the variables (ie. PlayerName[0]) I have got
    public class Players
    EnterHomeTeam HT = new EnterHomeTeam();
    //and included in the button code
    this.button1.set_Text(HT.PlayerName[0]);I hope i have explained this well enough and hope someone can help me solve this problem! Im not a very competent programmer so i apologise if I havent explained this well enough!
    Adam

    .NET automatically generates quite a bit of code.... this is button1:
    private void InitializeComponent()
              this.button1 = new System.Windows.Forms.Button();
    // button1
              this.button1.set_BackColor(System.Drawing.Color.get_LightBlue());
              this.button1.set_Location(new System.Drawing.Point(88, 32));
              this.button1.set_Name("button1");
              this.button1.set_Size(new System.Drawing.Size(72, 56));
              this.button1.set_TabIndex(0);
              this.button1.set_Text(HT.PlayerName[0]);
              this.button1.add_Click( new System.EventHandler(this.button1_Click) );
    this.get_Controls().Add(this.button1);
         private void button1_Click (Object sender, System.EventArgs e)
              System.out.print(HT.PlayerName[0]);
              GKAction GK = new GKAction();
              this.Hide();
              GK.Show();
         }Hope that helps - im pretty sure that's all the button1 code

  • How to pass params to another class which accepts keyboard input?

    How can I pass params to a stand-alone Java class that, when executed, gathers params using readLine()?
    In other words, MyClass, when executed from the command-line, uses readLine to gather params for program execution. I'd like to test this class by calling it from another class using Runtime.exec("java MyClass") or calling MyClass.main(args) directly. But, how can I simulate the input expected from the keyboard?
    Thanks!

    Alright, so it looks like this:
    proc = Runtime.getRuntime().exec("java Client");
    br = new BufferedReader(new InputStreamReader(proc.getInputStream()));
    bw = new BufferedWriter(new OutputStreamWriter(proc.getOutputStream()));
    bw.write("test");
    bw.newLine();
    But, how can write doesn't seem to be passed to the original client class.
    Suggestions?

  • How do i view an array which is in another class?

    I know how to view variables from another class but i dont know how to view arrays from another class. Im trying to get my class to view data from the other class's arrays. Can it be done in Java? If it can, then how?
    These are my arrays, i want these to be viewable by the other class:
        public int arraySmallWhiteStars[][] = new int [600][3];
        public int arrayLargeWhiteStars[][] = new int [3][3];
        public int arrayYellowStars[][] = new int [3][3];
        public int arrayMars[][] = new int [1][3];How can i do it?
    Ant...

    what, so i would do it like this:
    pnlDraw.drawShip(arrayOne[][]);i dont think that will work!
    are you sure?
    Ant...Are these instance variable or local variables? What I'm saying is. are these arrays declared in the drawShip method?
    and passing parameters to a method is NOT how you gets public variables from a class. Are you sure you know how to do that?
    If I have a class with a public instance variable called, say int[] myInt I can access values of that via.
    int fromOtherClass = myClassInstance.myInt[0];

  • How can I use my array in another method.... Or better yet, what's wrong?

    I guess I'll show you what I am trying to do rather and then explain it
    public class arraycalc
    int[] dog;
    public void arraycalc()
    dog = new int[2];
    public void setSize(int size)
    dog[1] = size;
    public int getSize()
    return dog[1];
    This gives me a null pointer exception...
    How can I use my array from other methods?

    You have to make the array static. :)
    Although I must admit, this is rather bad usage. What you want to do is use an object constructor to make this class an object type, and then create the array in your main class using this type, and then call the methods from this class to modify your array. Creating the array inside the other method leads to a whole bunch of other stuff that's ... well, bad. :)
    Another thing: Because you're creating your array inside this class and you want to call your array from another class, you need to make the array static; to make it static, you must make your methods static. And according to my most ingenious computer science teacher, STATIC METHODS SUCK. :D
    So, if you want to stick with your layout, it would look like:
    public class arraycalc
         static int[] dog;
         public static void arraycalc()
              dog = new int[2];
         public static void setSize(int size)
              dog[1] = size;
         public static int getSize()
              return dog[1];
    }But I must warn you, that is absolutely horrible code, and you shouldn't use it. In fact, I don't even know why I posted it.
    You should definitely read up on OOP, as this problem would be better solved by creating a new object type.

  • Accessing arrays in other classes

    I want to access an array in another class. How do I do it.
    Class1
    Method1()
    Fill OriginalArray[]
    Class2
    Method2()
    If OriginalArray[0] = whatever //how can i access this array

    I want to access an array in another class. How do I
    do it.
    Class1
    Method1()
    Fill OriginalArray[]
    Class2
    Method2()
    If OriginalArray[0] = whatever //how can i access
    s this array
    }It depends. If the array is declared as public you'll be able to access it using the '.' notation:
    public class One{
      public Object[] a;
      public One(){
        a = new Object[1];
        a[0] = new String("hi");
    public class Two{
      public void myMethod(){
        One one = new One();
        System.out.println(one.a[0].toString());
    }Otherwise you'll need accessor methods, (get/set).

  • Using an array in one class from another

    If I create a new string array in a class, and then set the values in that class, how can I use these value in another class? The way I have tried is to create a new instance of the class that holds the array, but when thinking about it, if I create a new instance surely the value in the array wont have been set? hence why when I am trying to use the array all the values are null.
    Thanks

    You could create a member variable in one class, making the the variable of the other class' type. Then simply call one of the member object's methods, passing the array reference as an argument.

  • Passing array of Types to java class

    I am trying to pass a user defined type (that is an array) from PL/Sql to a javaclass. Here are the definitions that make-up the parameter to pass from PL/Sql to Java (uri_digest_array):
    CREATE OR REPLACE TYPE uri_digest as object (uri VARCHAR2(256),
    digest_value CLOB);
    CREATE OR REPLACE TYPE uri_digest_array AS VARRAY(10) OF uri_digest;
    In Oracle-land, java classes are published to PL/Sql by way of the following definition. Note that the intent here is to have compatible data-types.
    CREATE OR REPLACE FUNCTION SIGNRETURNINGXML (p_array IN uri_digest_array)
    RETURN LONG
    AS LANGUAGE JAVA
    NAME 'SignReturningXml.main(oracle.sql.Array) return java.lang.String';
    Here is a fragment of the java class code:
    class SignReturningXml {
    public static String main(String [] [] signItems ) // I have no idea what datatype to use here!
    { . . . . The code in here would process the passed array normally from first entry to last.
    Currently I get the following error:
    PLS-00311: the declaration of
    "SignReturningXml.main(oracle.sql.Array) return
    java.lang.String" is incomplete or malformed
    I could use some suggestions on resolving the datatype conflicts. Any ideas? Has anyone tried this kind of thing?
    Thanks,
    Michael

    Michael,
    At the risk of another [non] useful response, I meant that you should try searching the "Ask Tom" Web site, because usually you will find an answer to your question that has already been asked by someone else. Perhaps these will be helpful:
    [url=http://asktom.oracle.com/pls/ask/f?p=4950:8:1320383202207153292::NO::F4950_P8_DISPLAYID,F4950_P8_CRITERIA:8908169959941
    ]Can I Pass a nested table to Java from a pl/sql procedure
    [url=http://asktom.oracle.com/pls/ask/f?p=4950:8:::::F4950_P8_DISPLAYID:712625135727
    ]passing arrays into pl/sql stored procedures
    Good Luck,
    Avi.

  • Instantiating an Array declared in a class from another class

    Hi Guys,
    I am working on a project for University and I'm stuck with this thins, which I'm sure is pretty easy when you know how...
    I have a first class "Courses" in which I declare my Array, here is the code:
    import java.util.*;
    public class Courses
    private String[][] Listing;
    Courses(String[][] l)
       l = Listing;
    }This class compiles just fine but I have 2 problems:
    1/ Can I make sure that this array will be [3][4] ?
    When I try : "private String[3][4] Listing;" or "Courses(String[3][4] l)" the class doesn't compile anymore...
    FYI: I want to store the followings in my array:
    French Language, 250, 130, 70
    Painting, 270, 140, 70
    Yoga, 250, 130, 70
    2/ How can I instantiate this from another class?
    From a class "Booking" I want to be able to create a new array "Listing" by calling my constructor from the Courses class and populate it with the above data (course,full-time price, part-time price, Concessions price )
    How do I do that?

    Thanks, I've modofied my code as follows:
    import java.util.*;
    public class Courses
    private String[][] Listing = new String[3][4]; //create array 3 rows * 4 columns
    Courses(String[][] l)
       l = Listing;
    int i;
    int j;
    int p;
    String t;
    String p1;
    String getTitle(int i)  //return Course Title
       t=Listing[0];
    return t;
    int getPrice(int i, int j) //return Price (Full-Time, Part-Time, Concessions)
    p1=Listing[i][j];
    p=Integer.parseInt(p1);
    return p;
    now from my nex class Booking I want to instantiate Courses:
    public class Booking
    Courses c = new Courses()
    }How do I actually pass the data to this...what's the syntax so that my instance will be:
    c[0][0]="French Language"
    c[0][1]="250"
    c[0][2]="130"
    c[0][3]="70"
    c[1][0]="Painting"
    c[1][1]="270"
    c[1][2]="140"
    c[1][3]="70"
    c[2][0]="Yoga"
    c[2][1]="250"
    c[2][2]="130"
    c[2][3]="70"
    Thanks in advance,
    Tom

  • Pass The Variable Value to another class

    maybe just simple question, but i can't find out how to resolve it
    I want to use the ResultSet for my database connection result to another class ..
    this is my code
    private static select(){
    String URL = "jdbc:mysql://localhost/Chat";
    String username = "root";
    String password ="";
    try{
    Class.forName("com.mysql.jdbc.Driver")
    }catch(exception e){
    System.out.println("Failed to load MySQL driver");
    Statement stmt = null;
    Connection con = null;
    try{
    con = DriverManager.getConnection(URL,username,password);
    stmt = con.createStatement();
    ResultSet RS = stmt.executeQuery("SELECT * FROM message;");
    while (RS.next()){
    String command = RS.getString("command");
    String source = RS.getString("source");
    String target = RS.getString("target");
    RS.close();
    stmt.close();
    con.close();
    i want to retrieve those three string variable "command", "source", "target"
    for example
    public void run(){
    while(true){
    try{
    select()
    ...... next line is to retrive those three value of string
    how can do it ?
    TIA

    than you limeybrit9 for the answer..
    i get the point, buat i still can't figure it how exactly it has to be done ..
    let me try with arrayList
    private static select(){
    String URL = "jdbc:mysql://localhost/Chat";
    String username = "root";
    String password ="";
    String[] result = new String[3];
    Arrays array = new Arrays();
    try{
    Class.forName("com.mysql.jdbc.Driver")
    }catch(exception e){
    System.out.println("Failed to load MySQL driver");
    Statement stmt = null;
    Connection con = null;
    try{
    con = DriverManager.getConnection(URL,username,password);
    stmt = con.createStatement();
    ResultSet RS = stmt.executeQuery("SELECT * FROM message;");
    while (RS.next()){
    Result[0] = RS.getString("command");
    Result[1] = RS.getString("source");
    Result[2] = RS.getString("target");
    array.asList(Result);
    RS.close();
    stmt.close();
    con.close();
    and i still dont know how to pass those arraylist in other class

  • Using Variables/Arrays from one class in another

    Hello all,
    First, to explain what I am attempting to create, is a program that will accept input of employee names and hours worked into an array. The first class will accept a command line argument when invoked. If the argument is correct, it will call another class that will gather information from the user via an input box. After all names and hours have been input for employees, this class will calculate the salary based upon the first letter of each employee name and print the total hours, salary, etc. for each employee.
    What I need to do now is to split the second class into two: one that will gather the data and another that will calculate and print the data. Yes, this is an assignment. However, I am trying to learn and I have gotten this far, but I am stuck on how to get a class to be able to use an array/variables from another class.
    I realize the below code isn't exactly cleaned up...yet.
    Code for AverageSalaryGather class:
    import javax.swing.JOptionPane; // uses class JOptionPane
    import java.lang.reflect.Array;     
    import java.math.*;
    public class AverageSalaryGather {
         public static void gatherData() {     
              char[] alphaArray = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','x','y','z'};
              String[][] empInfoArray = new String[100][4];
              String[] empNameArray = new String[100];
              String finalOutput = "Name - Rate - Hours - Total Pay\n";
              String averageHoursOutput = "Average Hours Worked:\n";
              String averageSalaryOutput = "Average Hourly Salary:\n";
              String averageGroupSalaryOutput = "Average Group Salary:\n";
                        String[] rateArray = new String[26];
                        char empNameChar = 'a';
              int empRate = 0;
              int payRate = 0;
                        for (int i = 0; i < 26; i++) {
                   payRate = i + 5;
                   rateArray[i] = Integer.toString(payRate);
                        int countJoo = 0;
              while (true) {
                   String namePrompt = "Please enter the employee name: ";
                   String empName = JOptionPane.showInputDialog(namePrompt);
                                  if (empName == null | empName.equals("")) {
                        break;
                   else {
                        empInfoArray[countJoo][0] = empName;
                        for (int i = 0; i < alphaArray.length; i++) {
                             empNameChar = empName.toLowerCase().charAt(0);
                                                      if (alphaArray[i] == empNameChar) {
                                  empInfoArray[countJoo][1] = rateArray;
                                  break;
                        countJoo++;
              // DecimalFormat dollarFormat = new DecimalFormat("$#0.00");
              for (int i = 0; i < empInfoArray.length; i++) {
                   if (!(empInfoArray[i][0] == null)) {
                        String hourPrompt = "Please enter hours for " + empInfoArray[i][0] + ": ";
                        String empHours = JOptionPane.showInputDialog(hourPrompt);
                        int test = 0;
                        empInfoArray[i][2] = empHours;
                        // convert type String to double
                        //double tmpPayRate = Double.parseDouble(empInfoArray[i][1]);
                        //double tmpHours = Double.parseDouble(empInfoArray[i][2]);
                        //double tmpTotalPay = tmpPayRate * tmpHours;
                        // create via a string in empInfoArray
                             BigDecimal bdRate = new BigDecimal(empInfoArray[i][1]);
                             BigDecimal bdHours = new BigDecimal(empInfoArray[i][2]);
                             BigDecimal bdTotal = bdRate.multiply(bdHours);
                             bdTotal = bdTotal.setScale(2, RoundingMode.HALF_UP);
                             String strTotal = bdTotal.toString();
                             empInfoArray[i][3] = strTotal;
                        //String strTotalPay = Double.toString(tmpTotalPay);
                        //empInfoArray[i][3] = dollarFormat.format(tmpTotalPay);
                        else {
                             break;
              AverageSalaryCalcAndPrint averageSalaryCalcAndPrint = new AverageSalaryCalcAndPrint();
              averageSalaryCalcAndprint.calcAndPrint();
    Code for AverageSalaryCalcAndPrint class (upon compiling, there are more than a few complie errors, and that is due to me cutting/pasting the code from the other class into the new class and the compiler does not know how to access the array/variables from the gatherData class):
    import javax.swing.JOptionPane; // uses class JOptionPane
    import java.lang.reflect.Array;
    import java.math.*;
    public class AverageSalaryCalcAndPrint
         public static void calcAndPrint() {     
              AverageSalaryGather averageSalaryGather = new AverageSalaryGather();
              double totalHours = 0;
              double averageHours = 0;
              double averageSalary = 0;
              double totalSalary = 0;
              double averageGroupSalary = 0;
              double totalGroupSalary = 0;
              int countOfArray = 0;
              for (int i = 0; i < empInfoArray.length; i++) {
                   if (!(empInfoArray[0] == null)) {
                        totalSalary = totalSalary + Double.parseDouble(empInfoArray[i][1]);
                        totalHours = totalHours + Double.parseDouble(empInfoArray[i][2]);
                        totalGroupSalary = totalGroupSalary + Double.parseDouble(empInfoArray[i][3]);
                        countOfArray = i;
              averageHours = totalHours / (countOfArray + 1);
              averageSalary = totalSalary / (countOfArray + 1);
              averageGroupSalary = totalGroupSalary / (countOfArray + 1);
              String strAverageHourlySalary = Double.toString(averageSalary);
              String strAverageHours = Double.toString(averageHours);
              String strAverageGroupSalary = Double.toString(averageGroupSalary);
              for (int i = 0; i < empInfoArray.length; i++) {
                   if (!(empInfoArray[i][0] == null)) {
                        finalOutput = finalOutput + empInfoArray[i][0] + " - " + "$" + empInfoArray[i][1] + "/hr" + " - " + empInfoArray[i][2] + " - " + "$" + empInfoArray[i][3] + "\n";
              averageHoursOutput = averageHoursOutput + strAverageHours + "\n";
              averageSalaryOutput = averageSalaryOutput + strAverageHourlySalary + "\n";
              averageGroupSalaryOutput = averageGroupSalaryOutput + strAverageGroupSalary + "\n";
              JOptionPane.showMessageDialog(null, finalOutput + averageHoursOutput + averageSalaryOutput + averageGroupSalaryOutput, "Totals", JOptionPane.PLAIN_MESSAGE );

    Call the other class's methods. (In general, you
    shouldn't even try to access fields from the other
    class.) Also you should be looking at an
    instance of the other class, and not the class
    itself, generally.Would I not call the other classes method's by someting similar as below?:
    AverageSalaryCalcAndPrint averageSalaryCalcAndPrint = new AverageSalaryCalcAndPrint();
              averageSalaryCalcAndprint.calcAndPrint(); Well... don't break down classes based on broad steps
    of the program. Break them down by the information
    being managed. I'm not expressing this well...Could you give an example of this? I'm not sure I'm following well.
    Anyway, you want one or more objects that represent
    the data, and operations on that data. Those
    operations include calculations on the data. Other
    classes might represent the user interface, and
    different output types (say, a file versus the
    console).Yes, the requirements is to have a separate class to gather the data, and then another class to calculate and print the data. Is this what you mean in the above?

Maybe you are looking for

  • Retention amount paid to vendor is not updated in PO history tab

    Dear All, I had activated business function 'LOG_MMFI_P2P'. As a result i am getting Payment processing tab in PO. There i can define Down payment and Retention percentages. I had created a service purchase order and then service entry sheet. After t

  • Gradient Issue iMac

    Since a couple of weeks I am experiencing problems with my iMac Display. From the bottom to the middle of my screen I am seeing a gradient. I have been searching this community and via Google but can't really find what the problem is and if it is eas

  • TRYING TO BURN A DVD FOR BACK UP PROCESS HELP

    I ripped a DVD to my hard drive for back up use, but I accidently clicked on data and when I put it in the DVD player it said disk error, is this because I was suppose to click on copy (i use toast 7) instead of data? please, I need help. thank you

  • IDCS Win - Error message deciphering

    I am debugging a plugin when I come across this line of code: b if( CmdUtils::ProcessCommand(newWinCmd) != kSuccess) InDesign spins off this assert: b Calling Selection Extension Registry::Initialize more than once followed by 21 occurrences of this

  • MMAPI in JVM

    Dear All, I wrote a small midp application that plays a media file. I run my application in my IPAQ that runs esmertec JVM and I noticed that the MMAPI of the JVM cannot play any video file(no video supported by mmapi). I downloaded the IBM websphere