Question: JAVA Modify the address class to only accept two characters for the state. Also modify the class so that only five digits can be entered

JAVA Modify the address class to only accept two characters for the state. Also modify the class so that only five digits can be entered for the postalCode (no less than 5, no more than 5).

Modify both of constructors in your address class to throw an IllegalArgumentException if state or postal code is null.

In the AddressTester class, test that the exception works. Change your tester class back to working after you've tested the exception.

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

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!