Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I marked all requests with comment. Please help me fix the bugs and the code I missed. Thank you! Address.java public class Address { //There

I marked all requests with comment. Please help me fix the bugs and the code I missed. Thank you!

Address.java

public class Address {

//There should be String instance variables for: streetAddress, city, and state.

//All instance variables should be private.

private String streetAddress;

private String city;

private String state;

//Create getters and setters for all of these.

public String getStreetAddress(){

return streetAddress;

}

public void setStreetAddress(String streetAddress){

this.streetAddress = streetAddress ;

}

public String getCity(){

return city;

}

public void setCity(String city){

this.city = city;

}

public String getState(){

return state;

}

public void setState(String state){

this.state = state;

}

//There should be an int variable for zipCode.

private int zipCode;

//Create getter and setter for zipCode. A zipCode should always have at least 5 digits.

public int getZipCode() {

return zipCode;

}

public void setZipCode(int zipCode){

if (zipCode >= 10000){

this.zipCode = zipCode;

}

}

//Create a constructor which takes in the streetAddress, city, state and zipCode.

public Address(String streetAddress, String city, String state, int zipCode){

/*need some code here */

}

public String toString(){

String output = streetAddress+", "+city+", "+state+ " "+zipCode;

return output;

}

}

Person.java

public class Person {

// To describe a Person we need String variables for name and emailAddress.

private String name;

private String emailAddress;

//A person should also have a mailingAddress which is an Address object.

private Address mailingAddress;

//A person should have an int phoneNumber.

private int phoneNumber;

//Create getters and setters for all instance variables.

public String getName() {

return name;

}

public void setName(String name) {

this.name = name;

}

public String getEmailAddress() {

return emailAddress;

}

public void setEmailAddress(String emailAddress) {

this.emailAddress = emailAddress;

}

public Address getMailingAddress() {

return mailingAddress;

}

public void setMailingAddress(Address mailingAddress) {

this.mailingAddress = mailingAddress;

}

//The phoneNumber setter should only change the phone number

//if it is passed a phone number that is 10-digits long.

public int getPhoneNumber() {

return phoneNumber;

}

public void setPhoneNumber(int phoneNumber) {

if (/*need some codes here*/){

this.phoneNumber = phoneNumber;

}

}

//Create a constructor which takes in parameters for name and email address.

public Person(String name, String emailAddress){

this.name = name;

this.emailAddress = emailAddress;

}

//Create an overloaded constructor which takes in name and phone number.

public /*... */

public String toString(){

String output = "Name: " + name + " ";

output += "Email: " + emailAddress + " ";

output += "Phone Number: " + phoneNumber + " ";

output += "Mailing Address: " + mailingAddress.toString() + " ";

return output;

}

}

class PersonTestDriver {

public static void main(String[] args) {

//Create an array of type Person and name is people.

//You should make space for at least 4 person objects.

Person[] people = new Person[3];

//Construct at least three different Person objects. Their names and addresses should all

//be different.

Person P1 = new Person("Jack","JackAddress");

Person P2 = new Person("Lily","LilyAddress");

Person P3 = new Person("Mark","MarkAddress");

//Put the test Person objects in your people array.

people[0] = P1;

people[1] = P2;

people[2] = P3;

//Use a for loop to print out each person in your array. (Because you've defined toString

//methods you can print a Person object using System.out.println() )

System.out.println(/*need some code here */);

}

}

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

The Database Factory Active Database For Enterprise Computing

Authors: Schur, Stephen

1st Edition

0471558443, 9780471558446

More Books

Students also viewed these Databases questions