Question: Assignment: a. Complete the derived class CollegeStudent b. Test (write a driver) the class with 3 instants of College students of your choice. c. Verify

Assignment: a. Complete the derived class CollegeStudent b. Test (write a driver) the class with 3 instants of College students of your choice. c. Verify that all the methods function properly

public class CollegeStudent extends Student { private int year; // year of graduation private String degree; // degree sought public CollegeStudent () { super (); // must be first year = 0; degree = ""; } // end default constructor

public CollegeStudent (Name studentName, String studentId, int graduationYear, String degreeSought) { super (studentName, studentId); // must be first year = graduationYear; degree = degreeSought; } // end constructor

public void setStudent (Name studentName, String studentId, int graduationYear, String degreeSought) { setName (studentName); // NOT fullName = studentName; setId (studentId); // NOT id = studentId; // or setStudent(studentName, studentId); (see Segment 2.21) year = graduationYear; degree = degreeSought; } // end setStudent

< The methods setYear, getYear, setDegree, and getDegree go here. > . . . public String toString () { return super.toString () + ", " + degree + ", " + year; } // end toString public static void main(String[] args){ // testing the derived class here.. }// end of main } // end CollegeStudent

public class Student { private Name fullName; private String id; // identification number

public Student () { fullName = new Name (); or null; id = ""; } // end default constructor

public Student (Name studentName, String studentId) { fullName = studentName; id = studentId; } // end constructor

public void setStudent (Name studentName, String studentId) { setName (studentName); // or fullName = studentName; setId (studentId); // or id = studentId; } // end setStudent

public void setName (Name studentName) { fullName = studentName; } // end setName

public Name getName () { return fullName; } // end getName

public void setId (String studentId) { id = studentId; } // end setId

public String getId () { return id; } // end getId

public String toString () { return id + " " + fullName.toString (); } // end toString

public static void main(String[] args){ Name stud1 = new Name (" John", " Doe"); Student student1 = new Student( stud1, " B29384"); System.out.println(" The student's information is : "+student1.toString());

} // end main

} // end Student

public class Name { private String first; // first name private String last; // last name

public Name () { first = ""; last = ""; } // end default constructor

public Name (String firstName, String lastName) { first = firstName; last = lastName; } // end constructor

public void setName (String firstName, String lastName) { setFirst (firstName); setLast (lastName); } // end setName

public String getName () { return toString (); } // end getName

public void setFirst (String firstName) { first = firstName; } // end set First

public String getFirst () { return first; } // end getFirst

public void setLast (String lastName) { last = lastName; } // end setLast

public String getLast () { return last; } // end getLast

public void giveLastNameTo (Name aName) { aName.setLast (last); } // end giveLastNameTo

public String toString () { return first + " " + last; } // end toString } // end Name

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!