Basically is this my test file for some reason is just giving me problems and so I'm currently in the moment trying to correct the problem. I'm also trying to beat a deadline tonight that would give me 20% EC on this assignment.
What I need is for someone to review the code and see by just looking at the code if it's doing what I think it is doing and that is doing what the assignment asks.
The assignment is this: Add a data field motherMaidenName to Person. Write and accessor and a modifier method for this data field. Modify class toString and class equals to include the data field. Assume two Person objects are equal if they have the same ID number and mother's maiden name.
Here's the code:
/** Person is a class that represents a human being.
* @author Koffman and Wolfgang
* */
/** @author Noliving*/
public class Person {
// Data Fields
/** The given name */
private String givenName;
/** The family name */
private String familyName;
/** The ID number */
private String IDNumber;
/** The birth year */
private int birthYear = 1900;
/** Mother's maiden name
@author Noliving*/
private String mothersMaidenName;
// Constants
/** The age at which a person can vote */
private static final int VOTE_AGE = 18;
/** The age at which a person is considered a senior citizen */
private static final int SENIOR_AGE = 65;
// Constructors
/** Construct a person with given values
@param first The given name
@param family The family name
@param ID The ID number
@param birth The birth year
*/
public Person(String first, String family, String ID, int birth) {
givenName = first;
familyName = family;
IDNumber = ID;
birthYear = birth;
mothersMaidenName = "";//This is adding the maiden name value that was requested from the assignment
}
/** Construct a person with only an IDNumber specified.
@param ID The ID number
*/
public Person(String ID) {
IDNumber = ID;
}
// Modifier Methods
/** Sets the givenName field.
@param given The given name
*/
public void setGivenName(String given) {
givenName = given;
}
/** Sets the familyName field.
@param family The family name
*/
public void setFamilyName(String family) {
familyName = family;
}
/** Sets the birthYear field.
@param birthYear The year of birth
*/
public void setBirthYear(int birthYear) {
this.birthYear = birthYear;
}
// Accessor Methods
/** Gets the person's given name.
@return the given name as a String
*/
public String getGivenName() {
return givenName;
}
/** Gets the person's family name.
@return the family name as a String
*/
public String getFamilyName() {
return familyName;
}
/** Gets the person's ID number.
@return the ID number as a String
*/
public String getIDNumber() {
return IDNumber;
}
/** Gets the person's year of birth.
@return the year of birth as an int value
*/
public int getBirthYear() {
return birthYear;
}
// Other Methods
/** Calculates a person's age at this year's birthday.
@param year The current year
@return the year minus the birth year
*/
public int age(int year) {
return year - birthYear;
}
/** Determines whether a person can vote.
@param year The current year
@return true if the person's age is greater than or
equal to the voting age
*/
public boolean canVote(int year) {
int theAge = age(year);
return theAge >= VOTE_AGE;
}
/** Determines whether a person is a senior citizen.
@param year the current year
@return true if person's age is greater than or
equal to the age at which a person is
considered to be a senior citizen
*/
public boolean isSenior(int year) {
return age(year) >= SENIOR_AGE;
}
/** Retrieves the information in a Person object.
@return the object state as a string
*/
public String toString() {
return "Given name: " + givenName + "\n"
+ "Family name: " + familyName + "\n"
+ "ID number: " + IDNumber + "\n"
+ "Year of birth: " + birthYear + "\n"
+ "Mothers name: " + mothersMaidenName + "\n";
}
/** Compares two Person objects for equality.
@param per The second Person object
@return true if the Person objects have same
ID number; false if they don't
@return also if they have the same mother's maiden name
*/
public boolean equals(Person per) {
if (per == null)
return false;
else
return IDNumber.equals(per.IDNumber)&& mothersMaidenName.equals(per.mothersMaidenName);
}
//This method is public string, it is to get the intials of the of the person and leave a period behind the first and last initial.
public String getInitials(){
String firstname = getGivenName();
String lastname = getFamilyName();
String firstnameinitial = firstname.substring(0,1);
String lastnameinitial = lastname.substring(0,1);
String initial = firstnameinitial + "." + lastnameinitial + ".";
return initial;//returns the initial(s) as a string
}
/** This is programming problem #3 from assignment, this is comparing the ID number of objects too see if they have the same ID if they do it
return a zero
@return whether or not they have the Same ID number*/
public int compareTo(Person person){
return IDNumber.compareTo(person.IDNumber);
}
private void SwitchNames(){
String holdoldgivenname = "";
holdoldgivenname = givenName;
givenName = familyName;
familyName = holdoldgivenname;
}
}
Thanks for the help in advance.