Java程序辅导

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

客服在线QQ:2653320439 微信:ittutor Email:itutor@qq.com
wx: cjtutor
QQ: 2653320439
Java Lab 6: GradebookOO – Part 2                                 Tuesday, June 22, 2004 
 
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 files GradeBookOO.java and 
GBProgram.java that you created for lab 5. 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 5 
and that you have corrected all the mistakes that we pointed out for that lab before you 
start working on today’s lab. 
 
1. (2 points) Add appropriate access modifiers to all your fields and methods in 
GradebookOO and GBProgram. Compile. 
 
2. (5 points) Add a method to GradebookOO called addGrade which accepts a 
double argument and adds it to the array of grades. This is difficult.  Two things you 
should note: 
• arrays always have the same length, so you can't increase it the size of it 
• arrays are objects not primitives, so variables of type array hold references to arrays 
 
Here are the steps your addGrade method should follow: 
 
a) When addGrade is called, the grades field holds a reference to an array of grades: 
 grades —————————————————————> [83.2, 97.4, 76.8] 
 
b) Create a new array, maybe call it temp, that is a size 1 bigger than grades: 
 grades —————————————————————> [83.2, 97.4, 76.8] 
   temp —————————————————————> [    ,     ,     ,     ] 
 
c) Copy over all the elements from grades into temp: 
 grades —————————————————————> [83.2, 97.4, 76.8] 
   temp —————————————————————> [83.2, 97.4, 76.8,     ] 
 
d) Add the new grade into the last slot of temp: 
 grades —————————————————————> [83.2, 97.4, 76.8] 
   temp —————————————————————> [83.2, 97.4, 76.8, 90.5] 
 
e) Change grades so it points to the temp array: 
 grades —————————————————————> [83.2, 97.4, 76.8, 90.5] 
 
3. (3 points) Delete the GradebookOO constructor that takes an array of doubles as an 
argument. And change the main method of GBProgram so that it instantiates an empty 
GradebookOO and adds the grades one-by-one to it with the addGrade method. 
Compile and run. 
 
4. (Optional – 2 points) If you have not done so in the past few labs, use EasyReader 
to read the grades from the user and print out a menu to the user. See Labs 4 and 5 for 
more details. 
 
5. (Optional – 3 points) Add a method deleteGrade to GradebookOO which accepts 
a grade as an argument and removes it from the array if it's there. This is tricky. Compile 
and run. 
 
6. CheckOff 
Please ensure that you have the files GradeBookOO.java and GBProgram.java in the 
folder named lab5. These files should compile successfully. Failure to compile will 
automatically cost you 1 point.  
  
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.