12.07.2015 Views

HW Set 7 - thecubscientist.com

HW Set 7 - thecubscientist.com

HW Set 7 - thecubscientist.com

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

P7D. College Tuition! In this program, you will write an abstract class “Student”and three concrete classes, “UnderGrad” and “Graduate” (that inherit from“Student”) and “PostGraduate” that inherits from “Graduate.” Therequirements for each of the classes are shown below:Part 1: Write the class definition for the abstract class “Student.” The class definitionshould include private instance variables of type String to hold the student’s firstname, a String for his/her major and an int to hold the number of units taken.Getter and setter methods for each of the variables should be included in the classdefinition. It should also include an abstract method “calculateTuition()” asshown below:abstract public int calculateTuition(int units);Part 2: Write a three-argument constructor in the Student class to initialize eachstudent’s name, major, and number of units taken.Part 3: Write the class definitions for the “UnderGrad,” “Graduate,” and“PostGraduate” classes. These concrete classes should override the abstract method“calculateTuition()” according to the following rule:UnderGrad tuition is calculated by multiplying the number of units by $250.Graduate tuition is calculated by multiplying the number of units by $500.PostGraduate tuition is calculated by multiplying the number of units by $750.Part 4: Write a “StudentDriver” class to create two instances of each type of eachconcrete class, “UnderGrad”, “Graduate”, and “PostGraduate”. Add them to a3x2 2D array named “studentBody”. Use a for or for-each loop to print eachstudent’s name and major along with the student’s tuition based on the number of unitsthe student is taking. Organize the Students in the 2D array as shown below:P7E. AP 2005 #2 TicketPage 6AP Computer Science – <strong>HW</strong> <strong>Set</strong> 7 Programshttp://<strong>thecubscientist</strong>.<strong>com</strong>

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!