Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Run the Demo attached to this lab. You will need to muscle some code to get it to work. In particular the getters and setters

Run the Demo attached to this lab. You will need to muscle some code to get it to work. In particular the getters and setters in CollegeStudent.java.

1) Once the demo runs then attach CollegeStudent.java.

2) Now write a HomeworkC8.java that makes you a CollegeStudent and makes me, Mr. Reed (M.A. 1985), a CollegeStudent. Then make a second you that is new memory, i.e.

CollegeStudent c2 = new CollegeStudent();

println() the three CollegeStudents - you, me, you2. Now attach HomeworkC8.java.

3) copyAndPaste the output and [Submit] the HomeworkC8.java (and CollegeStudent.java).

4) P.s. (post script) Please use JavaDoc with tags. SR

ATTACHED FILES

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 

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

CollegeStudent.java

/** A class that represents a college student. (Listing D-3 in Appendix D.) @author Frank M. Carrano @author Timothy M. Henry @version 4.0 */ public class CollegeStudent //extends Student { private int year; // Year of graduation private String degree; // Degree sought public CollegeStudent() { super(); // Must be first statement in constructor year = 0; degree = ""; // Or replace the previous three statements with // this(studentName, studentId, 0, ""); (see Segment D.10) } // 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 D.16) 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 } // end CollegeStudent

CollegeStudentDemo.Java

/** A driver that demonstrates the classes Student and CollegeStudent. @author Frank M. Carrano @author Timothy M. Henry @version 4.0 */ public class CollegeStudentDemo { public static void main(String[] args) { // Test Student System.out.println("Test Student"); Student bob = new Student(); bob.setStudent(new Name("Bob", "Bean"), "555-55"); System.out.println(bob); Student friend = new Student(new Name("Kris", "Smythe"), "111-22"); System.out.println(friend); Student kyle = new Student(); kyle.setName(new Name("Kyle", "Skye")); kyle.setId("345-01"); System.out.println(kyle); System.out.println(kyle.getId() + " " + kyle.getName()); System.out.println(); // Test CollegeStudent System.out.println("Test CollegeStudent"); CollegeStudent joe = new CollegeStudent(); joe.setStudent(new Name("Joe", "Student"), "000-09", 2012, "B.A."); System.out.println(joe); System.out.println(joe.toString()); CollegeStudent jill = new CollegeStudent(new Name("Jill", "Student"), "543-21", 2010, "B.S."); System.out.println(jill); CollegeStudent kristen = new CollegeStudent(); kristen.setName(new Name("Kristen", "Student")); kristen.setId("678-02"); //kristen.setYear(2011); //kristen.setDegree("M.A."); System.out.println(kristen); //System.out.println(kristen.getYear() + " " + kristen.getDegree()); System.out.println(" Done!"); } // end main } // end Driver /* Test Student 555-55 Bob Bean 111-22 Kris Smythe 345-01 Kyle Skye 345-01 Kyle Skye Test CollegeStudent 000-09 Joe Student, B.A., 2012 000-09 Joe Student, B.A., 2012 543-21 Jill Student, B.S., 2010 678-02 Kristen Student, M.A., 2011 2011 M.A. Done! */

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Transactions On Large Scale Data And Knowledge Centered Systems Vi Special Issue On Database And Expert Systems Applications Lncs 7600

Authors: Abdelkader Hameurlain ,Josef Kung ,Roland Wagner ,Stephen W. Liddle ,Klaus-Dieter Schewe ,Xiaofang Zhou

2012th Edition

3642341780, 978-3642341786

More Books

Students also viewed these Databases questions

Question

How is a not-for-profit entity defined in the Codification?

Answered: 1 week ago

Question

Conduct a needs assessment. page 269

Answered: 1 week ago