Question
public class Person { //Data members private String FirstName; private String LastName; private int Age; private String Gender; private String City; //default constructor public Person()
public class Person {
//Data members
private String FirstName;
private String LastName;
private int Age;
private String Gender;
private String City;
//default constructor
public Person()
{
this.FirstName = "Unknown";
this.LastName = "Unknown";
this.Age = 0;
this.Gender = "Unknown";
this.City = "Unknown";
}
//non default constructor
public Person(String FN, String LN, int Age, String GN, String City)
{
this.FirstName = FN;
this.LastName = LN;
this.Gender = GN;
this.City = City;
if (Age < 0)
this.Age = 0;
else
this.Age = Age;
}
//set methods
public void setFirstName(String FN)
{
this.FirstName = FN;
}
public void setLastName(String LN)
{
this.LastName = LN;
}
public void setAge(int Age)
{
if (Age < 0)
this.Age = 0;
else
this.Age = Age;
}
public void setGender(String GN)
{
this.Gender = GN;
}
public void setCity(String City)
{
this.City = City;
}
//get methods
public String getFirstName()
{
return this.FirstName;
}
public String getLastName()
{
return this.LastName;
}
public int getAge()
{
return this.Age;
}
public String getGender()
{
return this.Gender;
}
public String getCity()
{
return this.City;
}
//toString method
public String toString()
{
String Print;
Print = " Fist Name: " + this.getFirstName() + " Last Name: " +
this.getLastName() + " Age: " + this.getAge() + " Gender: " + this.getGender() +
" City: " + this.getCity();
return Print;
}
}
- Think about a class named Person.
- What are the different attributes that a person class can have?
- What are the methods that a person class can have?
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started