Java程序辅导

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

客服在线QQ:2653320439 微信:ittutor Email:itutor@qq.com
wx: cjtutor
QQ: 2653320439
Java Lab 10: Students – Part 1                                      Monday, June 28, 2004 
 
Read instructions carefully! Following instructions is part of the grade for this lab.  
 
This lab is due at 5 pm today, at which point solutions will be posted at a location to be 
announced to the class. Having the lab due at 5 pm implies that you should save all 
your files and leave your machine by 5 pm. Failure to turn in the lab promptly at 5 pm 
will be penalized by taking off 1 point.  
 
Make sure you read through the entire lab before attempting any of the parts to manage 
your time appropriately. We will also be grading the neatness of and comments in your 
code. Please look over the solutions that we give you for guidelines on how to present 
your code. 1 point will be taken off for code that is not neat or has no comments. 
 
0. Create a new folder named lab10 in the folder C:\java\lastName (where lastName is 
the variable that stores your last name). This is the folder to which you will be saving all 
the files required for this lab.  
 
For this lab, you will be putting all your .class files in a package called students. In 
order to do this in JCreator, save all your .java files in the lab10 folder and add a 
“package student;” statement to all your classes. JCreator will then automatically put all 
the .class files in the folder lab10/student. 
 
1. (1 point) Create a class called Student, which should have two properties: a name 
and a year, and methods to get the name and get the year of the student. Initialize these 
properties to arguments passed into the constructor. 
 
2. (2 points) Create a subclass of Student called Undergrad. The Undergrad 
constructor should accept name and year arguments. Add a method to Undergrad 
called description which returns a String containing the name of the undergrad, 
then a space, then a capital 'U', then a space, and then the year of the undergrad. For 
example, the description method of an Undergrad instance with the name 
"Appiah" and the year 2006, should return the String "Appiah U 2006". 
 
3. (2 points) Create a subclass of Student called Grad. The Grad constructor should 
accept only the name of the Grad as an argument, and it should always initialize the 
Grad's year to 5. Add a description method to Grad which returns a String 
containing the name of the Grad, followed by a space and then the letter 'G'. The 
description method of a Grad named "Jennifer" should return the String 
"Mensah G". 
 
4. (2 points) Create a subclass of Undergrad called Intern. In addition to the name 
and year properties, Intern should have a wage and a number of hours that are 
initialized in the constructor. Add a getPay method to Intern which returns the wage 
times the number of hours. Add a description method to Intern which returns a 
String containing the result of calling Undergrad's description method followed by 
the return value of the getPay method. The description method of an 
Undergrad named "Akoto" whose year is 2005 and worked 20 hours at $10.32/hour, 
should return the String "Akoto U 2005 206.4". 
 
5. (2 points) Create a subclass of Grad called ResearchAssistant. 
ResearchAssistant has a salary that is initialized in the constructor and a getPay 
method that returns the salary. Add a description method to 
ResearchAssistant which returns a String containing the result of Grad's 
description method, followed by the result of getPay. The description 
method of a ResearchAssistant with the name "Kukula" and a $2000.00 salary 
would return the String "Kukula G 2000.0". 
 
6. (1 point) Create a class called StudentTest that has a main method. Use the main 
method to test the class hierarchy you just built. Create some instances of Undergrad, 
Grad, Intern, and Research Assistant. Print out the result of their 
description methods. Compile and run. 
 
7. CheckOff  
Please ensure that you have all the required files in the folder named lab10. These files 
should compile successfully. Failure to compile will automatically cost you 1 point.   
  
If you are ready to be checked off before 5 pm, call one of the team members who will 
assign you a grade for the lab. Otherwise, you should 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.