pkg utilities Name - yshehab/SchoolRoomBooking GitHub Wiki
Name Class
Overview
Models the name of a person.
Name is mutable, in that title, first name and surname can be reset. Name is not unique. Name implements the Comparable interface.
Package
Constructor
public Name(Title title, String firstName, String surname)
Post-condition: returns an instance of name from the supplied arguments
Static Members
None
Static Methods
public Name createNewName(Title title, String firstName, String surname)
Post-condition: returns an instance of name from the supplied arguments
Attributes
private Title title the person_s title
private String firstName the person_s given name
private String surname the person_s surname
Links
None
Protocol
public void setTitle(Title title)
Post-condition: Sets the receiver_s title attribute to title
public void setFirstName(String firstName)
Post-condition: Sets the receiver_s firstName attribute to firstName
public void setSurname(String surname)
Post-condition: Sets the receiver_s surname attribute to surname
public String toString(String firstName)
Post-condition: Returns a string representation of the receiver
public int CompareTo(Name name)
Post-condition: Returns -1, 0, 1 depending on whether the supplied name is lexically before, equal to or after the receiver. Surnames are compared first, if these are equal then firstNames are compared. Titles are ignored.
Inner Classes
Public Title
An enum of likely titles for a person
Values
MR, MISS, MS, MRS, SIR, DOCTOR, LORD, LADY, REV, FR, NONE
Methods
private String Name.Title.value
Post-condition: Returns a string representation of a value with trailing whitespace included.
Examples
Name blogs # new Name(Name.Title.MR, "Joe", "Blogs");
blogs.toString(); //Mr. Joe Blogs
Name frogs # new Name(Name.Title.NONE, "Alan", "Blogs");
frog.toString(); // Alan Blogs
int i # blogs.compareTo(frogs); // -1
int j # frog.compareTo(blogs); // 1
Discussion
- Does Name.Title.value need to be public?
- As Name is not unique, why have a static method?