Build a class called ferson.java. This class should have the following propertie
ID: 3848523 • Letter: B
Question
Build a class called ferson.java. This class should have the following properties: firstName, lastName, address and email. The address property should use the Address class that you built in Lab #1. 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 instantiate a Person object by calling the constructor that takes all 4 arguments, then call the display method to display the data. Main Testing Code Rightarrow Person p1; p1 = new Person("James", "Jones", new Address("123 Main St.", "Dallas", "TX", 56565), "jj@yahoo.com"); p1.display();Explanation / Answer
You didn't provide the Address class so i created my own for purpose . If this address class is not what youre address class is then specify me in comment and i will provide you.
PROGRAM:-
import java.util.*;
import java.lang.*;
import java.io.*;
class Address{
String street;
String city;
String state;
int postalcode;
Address(String street,String city,String state, int postalcode ){
this.street = street;
this.city = city;
this.state = state;
this.postalcode = postalcode;
}
String giveAddress(){
String add = this.street+' '+this.city+' '+this.state+' '+this.postalcode;
return add;
}
}
class Person
{
String firstName, lastName, address, email;
public String getFirstname(){
return this.firstName;
}
public void setFirstname(String name){
this.firstName = name;
}
public String getLastname(){
return this.lastName;
}
public void setLastname(String name){
this.lastName = name;
}
public String getEmail(){
return this.email;
}
public void setEmail(String email){
this.email = email;
}
Person(String fname, String lname, Address a , String email){
this.firstName = fname;
this.lastName = lname;
this.address = a.giveAddress();
this.email = email;
}
Person(){
this.firstName = " ";
this.lastName = " ";
this.address = " ";
this.email = " ";
}
void Display(){
System.out.println("Your name is : "+this.firstName+" "+this.lastName);
System.out.println("Your Address is : "+this.address);
System.out.println("Your email address is : "+this.email);
}
public static void main (String[] args) throws java.lang.Exception
{
Person p1;
p1 = new Person("James",
"Jones",
new Address("123 Main St","Dallas","TX",585858),
"jj@tahin.com");
p1.Display();
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.