Java程序辅导

C C++ Java Python Processing编程在线培训 程序编写 软件开发 视频讲解

客服在线QQ:2653320439 微信:ittutor Email:itutor@qq.com
wx: cjtutor
QQ: 2653320439
Java Lab 4: GradeBook 2 
 
Read instructions carefully! Following instructions is part of the grade for this lab.  
 
This lab is due at 5pm today, at which point solutions will be posted at a location to be 
announced to the class. Make sure you read through the entire lab before attempting any 
of the parts to manage your time appropriately. 
 
0. In this lab, you will continue working on the file GradeBook.java that you created for 
yesterday’s lab (GradeBook 1). You therefore need not create a new folder or file to 
complete this lab. However, please ensure that we have checked you off for lab 3 and that 
you have corrected all the mistakes that we pointed out for that lab before you start 
working on this lab. 
 
That said and done, you should note that today’s lab is slightly more challenging than 
what you have worked with so far in the course. All students are therefore advised to 
check off the required part of the lab before proceeding to the more intensive 
optional part. Do not get frustrated if you cannot successfully complete the optional part 
because it draws from different concepts introduced this week in a not so obvious 
manner.   
 
1. (3 points) 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 call to the printGrades method. 
Compile and run. 
 
2. (3 points) 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.(4 points) Change the main method of GradeBook so that it converts its String 
arguments into doubles and initializes the grades in the array to those numbers. Use the 
method Double.parseDouble to convert a String containing a double to an 
actual double. Compile and run and provide arguments at the command line, like this: 
    java GradeBook 82.4 72.5 90 96.8 86.1 
Note: In order to complete this part (part 3), you will need to use the Command Prompt 
to run your program. This is because JCreator does not allow you to provide arguments to 
the main method as specified above. 
 
4. (Optional) Do not proceed to this part before we check off the required section of 
the lab.  Copy the EasyReader.class file provided with this lab into your lab3 
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 it to a variable 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, the program asks the user to enter the grades.   
Hint: use the two EasyReader methods discussed. A proposed solution would first ask 
the user to enter the number of grades that he/she wants to enter before collecting the 
grades themselves from the user one by one. 
 
5. (Optional) For this part, add a method to GradeBook called letterGrade that 
takes a double as an argument and prints out the letter grade (see lab 3’s optional question 
for details). If applicable, remove the code in the main method that prints the letter grade. 
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 or 2) find the average and letter 
grades. It should ask the user to enter the number of their choice and do what the user 
chooses. 
 
6. CheckOff 
Please ensure that you have the file GradeBook.java in the folder named lab3 that you 
created in step 0 of lab 3.  
 
If you are ready to be checked off before 5pm, call one of the team members who will 
assign you a grade for the lab. Otherwise, you may leave the required files on your 
machine for us to evaluate at our own convenience.  
 
We will not accept modifications to the required files after the lab is officially due.