MIT | MIT-AITI | Ethiopia 2004

Java Lab 4: Gradebook - Part II

  1. Add a method to Gradebook called printGrades that accepts an array of doubles as an argument and prints out all the grades in the array. Replace the loop in the main method that prints out all the grades with a class to printGrades method. Compile and run.
  2. Add a method to Gradebook called averageGrade that takes an array of doubles as an argument and returns the average grade. Replace the loop and calculations in the main method that determines the average grade with a call to the averageGrade method. Your main method should still print out the user's average grade and the letter grade the user earned. Compile and run.
  3. Change the main method of Gradebook so that it converts its String arguments into doubles and intializes the grades in the array to those numbers. Use the method Double.parseDouble to convert a String containing a double to an acutal double. Compile and run and provide arugments at the command line like this:
    java Gradebook 82.4 72.5 90 96.8 86.1
  4. (Optional) Download the EasyReader.class file in to your directory. EasyReader is a file we wrote for you that makes it easy to read data the user types in. It has several methods, two of which are readInt and readDouble. The readInt method waits for the user to type in an integer and press enter, and it returns the integer the user types in. The readDouble does the same thing, but for doubles.

    To call the readInt or readDouble method, you have to type EasyReader.readInt() or EasyReader.readDouble(). For example, to read a double from the user and assign to it a varible d, you could use the following code:
    double d = EasyReader.readDouble():
    
    Try modifying your code so that instead of just taking the array of grades from the main method, theprogram asks the user to enter the grades. Hint: use the two EasyReader methods discussed!
  5. (Optional) Change the main method so that after asking the user to enter the grades, it prints out a menu of two options for them:
    1. Print out all the grades
    2. Find the average grade
    It should ask the user to enter the number of his choice and do what the user chooses.

Submission: Submit all of your code for this lab.

Hosted by www.Geocities.ws

1