Computer Science 1260 – Classwork 6
October 21, 2018 / Inheritance and Interfaces / Name: ______

The Problem

Implement the program shown in the following UML diagram. To save you time, the uncommented code for the Name and Addressclasses is attached. Be sure you pay attention to the class relationships described in the UML diagram.

The Driver Program

The driver should fill an address book with 5 or more Contact objects. It should then display the Contact objects in the address book in a neat readable form. Finally, it should sort the contacts into alphabetical order of the last names and display them again. Your sort method should take advantage of the fact that Contact implements the CompareTo<Name> method.

Deliverable

Demo your FULLY COMMENTEDprogram to your instructor or teaching assistant before leaving the lab today. Hand a sheet of paper with your name and section number on it to the person to that person. Please print.

The Name Class

public class Name

{

private Stringfirst;

private Stringmiddle;

private Stringlast;

public Name ( )

{

first = "";

middle = "";

last = "";

}

public Name (String first, String middle, String last)

{

this.first = first;

this.middle = middle;

this.last = last;

}

public String getFirst ( )

{

return first;

}

public void setFirst (String first)

{

this.first = first;

}

public String getMiddle ( )

{

return middle;

}

public void setMiddle (String middle)

{

this.middle = middle;

}

public String getLast ( )

{

return last;

}

public void setLast (String last)

{

this.last = last;

}

@Override

public String toString ( )

{

String name = first + " " + middle;

if (middle != "")

name += " ";

name += last;

return name;

}

}

The Address Class

public class Address

{

private Stringstreet;

private Stringcity;

private Stringstate;

private intzipCode;// Five-digit zip code

public Address ( )

{

street = "";

city = "";

state = "";

zipCode = 0;

}

public Address (String street, String city, String state, int zipCode)

{

this.street = street;

this.city = city;

this.state = state;

this.zipCode = zipCode;

}

public String getStreet ( )

{

return street;

}

public void setStreet (String street)

{

this.street = street;

}

public String getCity ( )

{

return city;

}

public void setCity (String city)

{

this.city = city;

}

public String getState ( )

{

return state;

}

public void setState (String state)

{

this.state = state;

}

public int getZipCode ( )

{

return zipCode;

}

public void setZipCode (int zipCode)

{

this.zipCode = zipCode;

}

@Override

public String toString ( )

{

DecimalFormat fmt = new DecimalFormat ("00000");

return street + "\n" + city + ", " + state + " " + fmt.format (zipCode);

}

}

ClassworkPage 1