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;

}

}

  1. Think about a class named Person.
  2. What are the different attributes that a person class can have?
  3. What are the methods that a person class can have?

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!