Java Program calculating student average, class average, and letter grade using array

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • aphip13
    New Member
    • Apr 2017
    • 1

    Java Program calculating student average, class average, and letter grade using array

    im struggling with the man/driver class

    heres what i have for code

    package GradebookProg3;

    import java.io.FileNot FoundException;
    import java.io.FileRea der;
    import java.util.Scann er;

    public class mainGradeBook {

    public static void main(String[] args) throws FileNotFoundExc eption
    {
    GradeBook [] gradeBook = new GradeBook [10];

    String fName, lName;
    double[] testScores = new double[5];

    double classAverage = 0.0;

    Scanner inFile = new Scanner(new FileReader("tes tScores.txt"));


    //STRUGGLING HERE..HOW SHOULD I WRITE THIS?

    for (int i = 0; i < 10; i++)
    fName = inFile.next();
    lName = inFile.next();


    gradeBook [a,b,c ] = new GradeBook();



    System.out.prin tln("First_Name Last_Name Test1 Test2 "
    + "Test3 Test4 Test5 Average Grade");

    for (int i = 0; i < 10; i++)
    {
    System.out.prin tln(gradeBook[i]);

    classAverage = classAverage + gradeBook[i].getAverage();
    }

    classAverage = classAverage / 10;

    System.out.prin tln();

    System.out.prin tf("Class average = %.2f%n", classAverage);
    }//end main



    }
  • chaarmann
    Recognized Expert Contributor
    • Nov 2007
    • 785

    #2
    First: don't use arrays, use ArrayList instead. They are more flexible and you don't need to resize or handle error conditions like ArrayIndexOutOf Bounds etc.

    Using a for-loop for the data entry is bad.
    Maybe the user wants to enter only 3 records instead 10.
    You have to give the user the possibility to quit after every record entered.

    So use while-loop:
    Code:
    while(true)
    {
      enterRecord(inFile); // you have to write that
      System.out.println("Do you want to enter more records (Y) or quit (N)?");
      String answer = inFile.next();
      if (answer.toUpperCase.equals("N")) break; 
    }

    Comment

    Working...