Question: Question5. Write a Java interface StudentInterface.java that specifies and declares methods for a class Student . Use the attached Student.java for the method headers. Use

Question5. Write a Java interface StudentInterface.java that specifies and declares methods for a class Student. Use the attached Student.java for the method headers.

  • Use the attached file Student.java to design Question5 and then implements the StudentInterface from #5.
  • Now write a main() that uses StudentInterface. Use yourself and Mr. Reed as two students in main(). hwP18Q5.java
  • Use JavaDoc for preconditions and postconditions, i.e. tags @param and @return.

Student.java

/** A class that represents a student. @author Frank M. Carrano @author Timothy M. Henry @version 5.0 */ public class Student { private Name fullName; private String id; // Identification number public Student() { fullName = new Name(); 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 } // end Student

Name.Java

/** A class that represents a person's name. Listing B-1 in Segment B.16 of Appendix B. @author Frank M. Carrano @author Timothy M. Henry @version 5.0 */ public class Name //implements Comparable { private String first; // First name private String last; // Last name public Name() { } // 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 setFirst 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 public int compareTo( Name name2 ) { return last.compareTo( name2.getLast() ); } public static void main( String[] args ) { Name n0 = new Name( "Mr.", "Reed" ); Name n1 = new Name( "Mrs.", "Read" ); System.out.println( n0.compareTo( n1 ) ); } } // 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!