Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Question1. What data fields would you use in the definition of a class Address to represent a student's address? Question2. Add a data field to

Question1. What data fields would you use in the definition of a class Address to represent a student's address?

Question2. Add a data field to the class Student to represent a student's address. What new methods should you define?

Question3. What existing methods need to be changed in the class Student as a result of the added field that Question2 described?

Question4. What is another implementation for the default constructor that uses this, as described in Segment B.25 of Appendix B? this("", "")

  1. Download the attached files. Name.java, Student.java. Add a data field Address to the class Student and getter/setter methods.
  2. Make changes in the existing methods of the class Student for the new data field Address.
  3. Modify the default Student constructor so it uses this().

Write a main() in Student.java for a student Mr. Reed, 00001, 19351 W Washington St.

  • CopyAndPaste the output in the SubmissionBox.

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 

Attached files. 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

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

Step: 3

blur-text-image

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

Beginning C# 2005 Databases

Authors: Karli Watson

1st Edition

0470044063, 978-0470044063

More Books

Students also viewed these Databases questions

Question

3 > O Actual direct-labour hours Standard direct-labour hours...

Answered: 1 week ago