Starting from:

$25

Computer Science 221 Program 6




Learning objective:


To use
inheritance.





Assignment:

Write
a Java application that implements a small student grade system as defined
below. Write the hierarchy so that all fields and methods are as high in the
hierarchy as possible.



Define
a class Course that has a department (String),
a number (int), credit hours (int),
and a grade (String or char). Don't initialize the grade in the constructor.
(The professor doesn't know what grade you will make at the beginning of the
course.) Each field should have a getter and a setter, and there is a toString()
method.



Define
a class Person. A Person has a first name, a
last name, and ID number (int). Each field should
have a getter and a setter, and there is a toString() method.



Derive
the class Student from the class Person.
A Student has a major and a list of
courses (ArrayList<Course). (Remember that
courses are a component, not part of the inheritance hierarchy.) There is a
class variable that keeps track of the total number of students. There are two
constructors, one without a major and one with; a setter that changes the
major, a method that adds a course to the course list, a method that changes
the grade of a course, and a method that computes the GPA of the courses in the
list. There is a toString() method that lists
name, ID, major or "undeclared", GPA, and if the student has a GPA
less than 2.0, "On probation". Use a grade points of A = 4, B = 3, C
= 2, D = 1, F = 0. Do not use plus and minus grades. The GPA is sum of grade
points divided by sum of hours.



The
method find() locates a course within the
student's course list. It will have to search the ArrayList for a match on
department and a match on number. It
returns the position that it finds. The method changeGrade() uses the position and
calls the Course's
setGrade()
to change the grade.



The
class GraduateStudent, derived from the class Student,
has a thesis topic. There are one constructor with a major, and a setter that
changes the thesis topic. There is a toString() method that lists
name, ID, major , GPA, and if the student has a GPA less than 3.0, "On
probation". It also lists the thesis topic or "none".



Write
a class Test.java that has no input. In Test.java
add some students and graduate students with majors and some without. Add
majors to some without, and leave some majorless. Add courses to all students.
Then add grades to the courses. Make an ArrayList<Person of Student
and GraduateStudent and put all students and
graduate students into it. Print the information as described above on all Students
and GraduateStudents. Then print the total number of
students from the class variable.



All
class names and method signatures should be exactly as specified. Thus I should
be able to substitute my test program for yours, and everything should work
perfectly.



Constructor and Method Signatures (except for simple
getters and setters):

public
Course ( String dept, int number, int hours )...

public
Person ( int ID, String first, String last )...

public
Student( int ID, String first, String last )...

public
Student( int ID, String first, String last, String major )...

public
void addCourse( String dept, int num, int hours )...

public
void changeGrade ( String dept, int num, char grade )...

public
GraduateStudent( int ID, String first, String last, String major )...



Submission instructions:

Upload the files Course.java, Person.java, Student.java, GraduateStudent.java, and Test.java to "Program 6".
Do not submit class files or any of the BlueJ control files. Be sure to press
the submit button.



Policies:

The policies given on WebCT are in effect
for this and all assignments.



You may submit on WebCT multiple times, so
there is no excuse for not submitting partial solutions.

More products