title: How to connect two class modules together in Java?
body: <p>I have a program that contains five .txt files. These files are read in and put into different arrays. One is an array of names. The other four are arrays with test scores.</p>
  <p>Currently, the program does create the arrays correctly. Next the program is to calculate and display the average for each test (this works fine). Then the program prompts the user for a name. If a name is found a new menu will prompt the user to select which test they want the data on. (This works fine).</p>
  <p>The problem: I have the main program class and another GradeBook class (does calculations) on another page. How do I connect the two pages together?</p>
  <p>For example: If the studentName is 'Andrew' and it is found in studentNameArray, and I select 1 for which test score I want to see (scoreOneArray), say the number 88. My program finds 'Andrew' and '88'. What it does not do is send 'Andrew' and '88' to GradeBook to have the data compute test percentage (88/100) and find the corresponding letter grade (in this case 'B'). Lastly, then print students name, test score (88%), and the letter grade.</p>
  <p>Program (main):</p>
  <pre><code>import java.io.*;
  import java.util.ArrayList;
  import java.util.Arrays;
  import java.util.List;
  import java.util.Scanner;
  
  public class Main {
      public static void main(String[] args) throws IOException {
          double test1Calculation;
          double test2Calculation;
          double test3Calculation;
          double test4Calculation;
          int i, j, k, l;
          int testOneSum = 0;
          int testTwoSum = 0;
          int testThreeSum = 0;
          int testFourSum = 0;
          int checker = 0;
          int index=0;
          String choice;
  
          Scanner students = new Scanner(new File(&quot;names.txt&quot;));
          Scanner TestOne = new Scanner(new File(&quot;testOne.txt&quot;));
          Scanner TestTwo = new Scanner(new File(&quot;testTwo.txt&quot;));
          Scanner TestThree = new Scanner(new File(&quot;testThree.txt&quot;));
          Scanner TestFour = new Scanner(new File(&quot;testFour.txt&quot;));
  
          String token1 = &quot;&quot;;
          List&lt;String&gt; studentName = new ArrayList&lt;&gt;();
          while (students.hasNext()) {
              // find next line
              token1 = students.next();
              studentName.add(token1);
          }
  
          String[] studentNameArray = studentName.toArray(new String[0]);
  
          List&lt;Integer&gt; scoreOne = new ArrayList&lt;&gt;();
  
          // while loop
          while (TestOne.hasNext()) {
              // find next line
              Integer token2 = TestOne.nextInt();
              scoreOne.add(token2);
          }
  
          Integer[] scoreOneArray = scoreOne.toArray(new Integer[0]);
  
          List&lt;Integer&gt; scoreTwo = new ArrayList&lt;&gt;();
  
          // while loop
          while (TestTwo.hasNext()) {
              // find next line
              Integer token3 = TestTwo.nextInt();
              scoreTwo.add(token3);
          }
  
          Integer[] scoreTwoArray = scoreTwo.toArray(new Integer[0]);
  
          List&lt;Integer&gt; scoreThree = new ArrayList&lt;&gt;();
  
          // while loop
          while (TestThree.hasNext()) {
              // find next line
              Integer token4 = TestThree.nextInt();
              scoreThree.add(token4);
          }
  
          Integer[] scoreThreeArray = scoreThree.toArray(new Integer[0]);
  
          List&lt;Integer&gt; scoreFour = new ArrayList&lt;&gt;();
  
          // while loop
          while (TestFour.hasNext()) {
              // find next line
              Integer token5 = TestFour.nextInt();
              scoreFour.add(token5);
          }
  
          Integer[] scoreFourArray = scoreFour.toArray(new Integer[0]);
  
          for (i = 0; i &lt; scoreOneArray.length; i++)
              testOneSum += scoreOneArray[i];
          test1Calculation = (double) testOneSum / 5;
  
          for (j = 0; j &lt; scoreTwoArray.length; j++)
              testTwoSum += scoreTwoArray[j];
          test2Calculation = (double) testTwoSum / 5;
  
          for (k = 0; k &lt; scoreThreeArray.length; k++)
              testThreeSum += scoreThreeArray[k];
          test3Calculation = (double) testThreeSum / 5;
  
          for (l = 0; l &lt; scoreFourArray.length; l++)
              testFourSum += scoreFourArray[l];
          test4Calculation = (double) testFourSum / 5;
  
          System.out.println(&quot;The average for test one is: &quot; + test1Calculation);
          System.out.println(&quot;The average for test two is: &quot; + test2Calculation);
          System.out.println(&quot;The average for test three is: &quot; + test3Calculation);
          System.out.println(&quot;The average for test four is: &quot; + test4Calculation);
  
          Scanner studentSearch = new Scanner(System.in);
          System.out.println(&quot;Enter student name : &quot;);
          String foundStudent = studentSearch.nextLine();
          boolean found = Arrays.stream(studentNameArray).anyMatch(t -&gt; t.equals(foundStudent));
          if (found) {
              index++;
              System.out.println(foundStudent + &quot; is found.&quot;);
  
              //menu loop
              do {
                  //displayed user options
                  System.out.println(&quot;1. To find score for first test&quot;);
                  System.out.println(&quot;2. To find score for second test&quot;);
                  System.out.println(&quot;3. To find score for third test&quot;);
                  System.out.println(&quot;4. To find score for fourth test&quot;);
  
                  //menu choices
                  Scanner keyboard = new Scanner(System.in);
                  System.out.print(&quot;\nEnter your choice: &quot;);
                  choice = keyboard.next();
  
                  if (choice.equals(&quot;1&quot;)) {
                      int  score= scoreOneArray[index];
  
                      System.out.println(score);
                      checker = -1;
                  } else if (choice.equals(&quot;2&quot;)) {
                      int  score= scoreTwoArray[index];
                      System.out.println(score);
                      checker = -1;
                  } else if (choice.equals(&quot;3&quot;)) {
                      int  score= scoreThreeArray[index];
                      System.out.println(score);
                      checker = -1;
                  } else if (choice.equals(&quot;4&quot;)) {
                      int  score= scoreFourArray[index];
                      System.out.println(score);
                      checker = -1;
                  } else {
                      //Error message
                      System.out.println(&quot;invalid choice&quot;);
                  }
              }
              while (checker != -1);
          } // End of Menu Method
          else {
              System.out.println(foundStudent + &quot; is not found.&quot;);}
          
  
          students.close();
          TestOne.close();
          TestTwo.close();
          TestThree.close();
          TestFour.close();
  
      }
  }
  </code></pre>
  <p>Calculations(GradeBook):</p>
  <pre><code>import java.util.ArrayList;
  
  public class GradeBook {
  
      private char[] letterGrade = {'A', 'B', 'C', 'D', 'F'};
      private ArrayList&lt;String&gt; names = new ArrayList&lt;&gt;();
      private double [][] scores = new double[5][4];
  
      public GradeBook(ArrayList&lt;String&gt; studentNames, double[][] studentScores){
          this.names = studentNames;
  
          for (int i = 0; i &lt; 5; i++){
              for (int j = 0; j &lt; 4; j++){
                  scores [i][j] = studentScores[i][j];
              }
          }
      }
      public  String getName(int studentIndex){
          return names.get(studentIndex);
      }
      public double getAverage(int studentIndex){
          double total = 0;
  
          for (int i = 0; i &lt; 4; i++){
              total += scores[studentIndex][i];
          }
          return (total / 4);
      }
      public char getLetterGrade(double avgScore){
  
          if (avgScore &gt;= 90 &amp;&amp; avgScore &lt;= 100){
              return letterGrade[0];
          }
          else if (avgScore &gt;= 80 &amp;&amp; avgScore &lt;= 89){
              return letterGrade[1];
          }
          else if (avgScore &gt;= 70 &amp;&amp; avgScore &lt;= 79){
              return letterGrade[2];
          }
          else if (avgScore &gt;= 60 &amp;&amp; avgScore &lt;= 69){
              return letterGrade[3];
          }
          else if (avgScore &gt;= 0 &amp;&amp; avgScore &lt;= 59){
              return letterGrade[4];
          }
          return ' ';
      }
      public void getStudent(){
  
          for (int i = 0; i &lt; names.size(); i++){
  
              System.out.println(&quot;\nStudent #&quot; + (i+1)
              +&quot;\n\t\tName: &quot; + names.get(i)
              +&quot;\n\t\tAverage: &quot; + getAverage(i) + &quot;%&quot;
              +&quot;\n\t\tLetter Grade: &quot; + getLetterGrade(getAverage(i))
              +&quot;\n\n&quot;);
          }
  
      }
  } 
  </code></pre>