Skip to content

Instantly share code, notes, and snippets.

@GrunclePug
Created May 26, 2019 08:22
Show Gist options
  • Save GrunclePug/35c93601925a49682f16d3bd44ff84dc to your computer and use it in GitHub Desktop.
Save GrunclePug/35c93601925a49682f16d3bd44ff84dc to your computer and use it in GitHub Desktop.
COMP 1409 | Lab02
/**
* Class that models a Person.
*
* @author Chad
* @version 1.1
*/
public class Person
{
private int age;
private double height; // cm
private String details;
private String firstName;
private String lastName;
/**
* Constructor for the Person.
*
* @param _firstName The first name of the Person.
* @param _lastName The last name of the Person.
* @param _age The age of the Person, must be between 1 and 100 inclusively.
* @param _height The height of the Person (in cm), must be between 1 and 200 inclusively.
*
*/
public Person(String _firstName, String _lastName, int _age, double _height)
{
firstName = _firstName;
lastName = _lastName;
if(_age > 0 && _age <= 100)
{
age = _age;
}
else
{
age = 1;
}
if(_height > 0 && _height <= 200)
{
height = _height;
}
else
{
height = 150;
}
}
/**
* Mutator to change the Person's first name.
*
* @param _firstName The new first name of the Person.
*/
public void setFirstName(String _firstName)
{
firstName = _firstName;
}
/**
* Mutator to change the Person's last name.
*
* @paraam _lastName The new last name of the Person.
*/
public void setLastName(String _lastName)
{
lastName = _lastName;
}
/**
* Mutator to change the Person's age.
*
* @param _age The new age of the Person, must be between 1 and 100 inclusively.
*/
public void setAge(int _age)
{
if(_age > 0 && _age <= 100)
{
age = _age;
}
}
/**
* Mutator to change the Person's height.
*
* @param _height The new height of the Person, must be between 1 and 200 inclusively.
*/
public void setHeight(double _height)
{
if(_height > 0 && _height <= 200)
{
height = _height;
}
}
/**
* Accessor to view the Person's first name.
*
* @return Returns the Person's first name.
*/
public String getFirstName()
{
return firstName;
}
/**
* Accessor to view the Person's last name.
*
* @return Returns the Person's last name.
*/
public String getLastName()
{
return lastName;
}
/**
* Accessor to view the Person's age.
*
* @return Returns the Person's age.
*/
public int getAge()
{
return age;
}
/**
* Accessor to view the Person's height.
*
* @return Returns the Person's height.
*/
public double getHeight()
{
return height;
}
/**
* Accessor to view the Person's details.
*
* @return Returns the Person's details.
*/
public String getDetails()
{
details = "Hello my name is " + firstName + " " + lastName + " and my age is " + age;
return details;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment