Question

In: Computer Science

Implement a class Address. An address has a house number, a street, an optional apartment number,...

Implement a class Address. An address has a house number, a street, an optional apartment number, a city, a state, and a postal code (all of these are strings). Create the getters and setters.

Supply two constructors that accept all the address components except one includes an apartment number and one without (refer to the tester class below to see the proper order).

Supply a print method that returns void and prints to the console the address with the street on one line and the city, state, and zip code on the next line.

Use my addressTester file attached here to verify it works correctly. You shouldn't make any changes to the addressTester file. Make changes to your class so that it works with my addressTester.java file. If your class file doesn't work with my tester class, you will receive no points.

Clarification: All components of the Address should print - however, an apartment number should only print if one is provided. Your method should not print null if no apartment number is provided.

Given Tester


public class AddressTester {
   //provided by instructor

   public static void main(String[] args) {
       Address a1 = new Address("123","Main Street","Los Angeles", "CA","90001");
       System.out.print(Address);
      
       System.out.println("----------------");
      
       Address condo = new Address("5643", "Hideaway Mountain", "3C","Nashville", "TN", "37115");
       condo.print();
      
   }

}

Solutions

Expert Solution

code:

[11:44 am, 30/03/2020] Chinna: public class Address {

private String houseNumber;
private String street;
private String apartmentNumber;
private String city;
private String state;
private String postalCode;

public Address(String houseNumber, String street, String city, String state, String postalCode) {
this.houseNumber = houseNumber;
this.street = street;
this.city = city;
this.state = state;
this.postalCode = postalCode;
}

public Address(String houseNumber, String street, String apartmentNumber, String city, String state, String postalCode) {
this.houseNumber = houseNumber;
this.street = street;
this.apartmentNumber = apartmentNumber;
this.city = city;
this.state = state;
this.postalCode = postalCode;
}

public String getHouseNumber() {
return houseNumber;
}

public void setHouseNumber(String houseNumber) {
this.houseNumber = houseNumber;
}

public String getStreet() {
return street;
}

public void setStreet(String street) {
this.street = street;
}

public String getApartmentNumber() {
return apartmentNumber;
}

public void setApartmentNumber(String apartmentNumber) {
this.apartmentNumber = apartmentNumber;
}

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;
}

public String getPostalCode() {
return postalCode;
}

public void setPostalCode(String postalCode) {
this.postalCode = postalCode;
}

public void print() {
System.out.println("Street: " + street);
System.out.println("City: " + city + ", State: " + state + ", ZIP: " + postalCode);
}
}

output:

note:

ask any doubts

give me up vote:)


Related Solutions

Create an ApartmentException class whose constructor receives a string that holds a street address, an apartment...
Create an ApartmentException class whose constructor receives a string that holds a street address, an apartment number, a number of bedrooms, and a rent value for an apartment. Upon construction, throw an ApartmentException if any of the following occur: • The apartment number does not consist of 3 digits • The number of bedrooms is less than 1 or more than 4 • The rent is less than $500.00 or over $2500 Write a driver class that demonstrates creating valid...
Create a class named Lease with fields that hold an apartment tenant’s name, apartment number, monthly...
Create a class named Lease with fields that hold an apartment tenant’s name, apartment number, monthly rent amount, and term of the lease in months. Include a constructor that initializes the name to “XXX”, the apartment number to 0, the rent to 1000, and the term to 12. Also include methods to get and set each of the fields. Include a nonstatic method named addPetFee() that adds $10 to the monthly rent value and calls a static method named explainPetPolicy()...
Create and test a python regular expression that matches a street address consisting of a number...
Create and test a python regular expression that matches a street address consisting of a number with one or more digits followed by two words of one or more characters each. The tokens should be separated by one space each, as in 123 Main Street.
University of Southern Ontario has been assigned a Class B address with a network number of...
University of Southern Ontario has been assigned a Class B address with a network number of 132.27.0.0. You are asked to come up with a subnetting scheme that allows to create 650 subnets on that network. Show your work. 1)         How many bits must be borrowed for the subnet ID? 2)         What is the subnet mask required? 3)         How many hosts there can be on each subnet? 4)         How many subnets can there be? 5)         Explain in 4 lines MAX,...
TestLibrary.java Design and implement a class named Book. A book has a serial number, a title,...
TestLibrary.java Design and implement a class named Book. A book has a serial number, a title, an author, and a publisher. Create appropriate constructor(s) and accessor and mutator methods for the Book class. Add a static variable to the Book class and set its initial value to 100000000. When a new book is created, this static variable is automatically incremented by 1 and the new value is assigned as the serial number of the new book. Design and implement a...
Suppose that you know that Y, the number of cars passing in front of your house/apartment/dorm...
Suppose that you know that Y, the number of cars passing in front of your house/apartment/dorm room every weekday is a Poisson Random Variable. If the average number of cars per week day is 25, use Chebychev's Inequality to *bound* the probability that Y is at most 32 and more than 18. Simplify your answer
C++ programming question class Address { public: Address(const std::string& street, const std::string& city, const std::string& state,...
C++ programming question class Address { public: Address(const std::string& street, const std::string& city, const std::string& state, const std::string& zip) : StreetNumber(street), CityName(city), StateName(state), ZipCode(zip) {} std::string GetStreetNumber() const { return StreetNumber; } void SetStreetNumber(const std::string& street) { StreetNumber = street; } std::string GetCity() const { return CityName; } void SetCity(const std::string& city) { CityName = city; } std::string GetState() const { return StateName; } void SetState(const std::string& state) { StateName = state; } std::string GetZipCode() const { return ZipCode; }...
Jess has agreed to purchase a house on 11th Street by July 2020 but only if...
Jess has agreed to purchase a house on 11th Street by July 2020 but only if she is able to sell her house on 15th Street by June 2020. This term is called a: express condition concurrent condition condition subsequent anticipatory condition --------------------------------------------------------------------------------------------------- In the United States, sources of law include: Executive orders laws passed by a state legislature international common law the U.S. Constitution --------------------------------------------------------------------------------------------------- The main purpose of contract remedies is to put the party who is not...
Cluster analysis has a number of optional metrics. Identify the Euclidean, Manhattan, and Farthest First distances...
Cluster analysis has a number of optional metrics. Identify the Euclidean, Manhattan, and Farthest First distances for each of the following cases to the two clusters given the following data (which has been transformed to a 0-1 scale). Variable CASE CLUSTER 1 CLUSTER 2 Ecology 0.8 0.2 0.9 Economy 0.3 1.0 0.2 Social impact 0.9 0.5 0.4
A sample of 250 apartment house shows that 154 house subscribes to cable TV. Construct a...
A sample of 250 apartment house shows that 154 house subscribes to cable TV. Construct a 90% confidence interval for the proportion of all apartment houses that subscribes to cable TV. Also, find the margin of error. Round your answers to 3 decimal places.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT