Created
August 13, 2019 08:29
-
-
Save 0ryant/91a8dc6fb32e6b36691b88b6dc2e8c39 to your computer and use it in GitHub Desktop.
Java - Coding Challenge - Classes; Person
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Person { | |
private String firstName; | |
private String lastName; | |
private int age; | |
public String getFirstName(){ | |
return firstName; | |
} | |
public String getLastName(){ | |
return lastName; | |
} | |
public int getAge(){ | |
return age; | |
} | |
public void setFirstName(String firstName){ | |
this.firstName = firstName; | |
} | |
public void setLastName(String lastName){ | |
this.lastName=lastName; | |
} | |
public void setAge(int age){ | |
if ((age<0)||(age>100)){ | |
this.age=0; | |
} else { | |
this.age=age; | |
} | |
} | |
public boolean isTeen(){ | |
if ((age<13)||(age>19)){ | |
return false; | |
} | |
return true; | |
} | |
public String getFullName(){ | |
if (firstName.isEmpty()){ | |
return lastName; | |
} else if (lastName.isEmpty()){ | |
return firstName; | |
} | |
return firstName+" "+lastName; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment