Question: Containment: Build a class called Person.java. This class should have the following properties: firstName, lastName, address, and email. The address property should use the Address
Containment: Build a class called Person.java. This class should have the following properties: firstName, lastName, address, and email. The address property should use the Address class you built previously (I have that provided below). Also, add the appropriate set and get methods, display method, toString method, and main method. Main() should be used to test this class. Also add 2 constructors to the Person class. One that takes no arguments and initializes the data to all 0's and ""(empty strings), and one constructor that takes all arguments. Lastly in the main() method instatiate a Person object by calling the constructor that takes all 4 arguments, then call the display method to display the data.
Main Testing Code =
Person p1;
p1 = new Person("James", "Jones", new Address ("123 Main St.","Dallas","TX",56565), "jj@yahoo.com");
p1.display();
============================================================================================
import java.util.*; import java.lang.*; import java.io.*;
class Address { private String street; private String city; private String state; private int zipcode; Address(String street,String city,String state,int zipcode){ this.street=street; this.city=city; this.state=state; this.zipcode=zipcode; }
Address(){ street=""; city=""; state=""; zipcode=0; } void display(){ System.out.println("ADDRESS: "); System.out.println("STREET : "+this.street); System.out.println("CITY : "+this.city); System.out.println("STATE : "+this.state); System.out.println("ZIPCODE :"+this.zipcode); } public static void main (String[] args) throws java.lang.Exception { Address a1; a1=new Address("1313 MockingBirdLn","Atlanta","GA",30001); a1.display(); } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
