0

Create a class named Person that includes fields for last name, first name, and zip code. Include a default constructor that initialize last name, first name and zip code to ‘X’ if no arguments are supplied. Also include a display method, displayPerson() to display Person details. Create a test class (main class) called TestPerson where your main() is located. In main(), instantiate and display two Person objects: one that uses default values, and one for which you supply your own values.

5
Contributors
5
Replies
23
Views
2 Years
Discussion Span
Last Post by Slavi
Featured Replies
  • 1

    if you don't know that, it means your reading comprehension is zero. Nothing we can do is going to change that. Read More

0
public class Person
{
    private String FirstName;
    private String LastName;
    private int ZipCode;

    public Person(){
    }

    public Person(String FirstName, String LastName, int ZipCode)
    {
        this.FirstName = FirstName;
        this.LastName = LastName;
        this.ZipCode = ZipCode;
    }

    public void displayPerson()
    {

    }
}

This is what i've got , still dont know where to put the "X" and how to include a default constructor that initialize last name, first name and zip code to ‘X’ if no arguments are supplied.

1

if you don't know that, it means your reading comprehension is zero.
Nothing we can do is going to change that.

0

As James said, you can set them in the default contructor on line 7, and just set your variable to some strings of your choice, so whenever you create a person he will be automatically assigned to those strings, which could represent names etc

This article has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.