Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Essentials of Database Management

Authors: Jeffrey A. Hoffer, Heikki Topi, Ramesh Venkataraman

1st edition

133405680, 9780133547702 , 978-0133405682

More Books

Students also viewed these Databases questions

Question

How do Excel Pivot Tables handle data from non OLAP databases?

Answered: 1 week ago