Skip to content

Instantly share code, notes, and snippets.

@0ryant
Created August 13, 2019 08:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save 0ryant/91a8dc6fb32e6b36691b88b6dc2e8c39 to your computer and use it in GitHub Desktop.
Save 0ryant/91a8dc6fb32e6b36691b88b6dc2e8c39 to your computer and use it in GitHub Desktop.
Java - Coding Challenge - Classes; Person
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