Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In the previous chapter, Self-Test Question 16 described a class Person to repre

ID: 3644149 • Letter: I

Question

In the previous chapter, Self-Test Question 16 described a class Person to represent a person. The class has instance variables for a person's name, which is a a string, and an integer age. These variables are name and age, respectively
a string, and an integer age. These variables are name and age, respectively.
a. Write a default constructor for Person that sets name to the string
"No name yet" and age to zero.
b. Write a second constructor for Person that sets name to a given string
and age to a given age.
c. Write a static method createAdult for Person that returns a special instance
of this class. The instance represents a generic adult and has the
name "An adult" and the age 21.

Explanation / Answer

Please rate...

public class Person
{
    private String personName;
    private int age;
    Person()
    {
        personName="No name yet";
        age=0;
    }
    Person(String s,int a)
    {
        personName=s;
        age=a;
    }
    public Person createAdult()
    {
        this.personName="An Adult";
        this.age=21;
        return this;
    }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote