Question: I have a question, Implement a class Address. An address has a house number, a street, an optional apartment number, a city, a state, and

I have a question,

Implement a class Address. An address has a house number, a street, an optional apartment number, a city, a state, and a postal code. Supply two constructors: one with an apartment number and one without. Supply a print method that prints the address with the street on one line and the city, state, and postal code on the next line. Supply a method public boolean comesBefore (Address other) that tests whether this address comes before another when the addresses are compared by postal code.

I have written the program but am stuck on this part. Supply a method public boolean comesBefore (Address other) that tests whether this address comes before another when the addresses are compared by postal code.

public class CreamCracker { int houseNumber; String street; int apartmentNumber; String city; String state; int PostalCode; public CreamCracker(int houseNumber, String street, String city, String state, int PostalCode) { this.houseNumber = houseNumber; this.street = street; this.city = city; this.state = state; this.PostalCode = PostalCode; } public CreamCracker(int houseNumber, String street, int apartmentNumber, String city, String state, int PostalCode) { this(houseNumber, street, city, state, PostalCode); this.apartmentNumber = apartmentNumber; } public void printAddress() { System.out.printf("Street: House number: ", this.street, this.houseNumber); System.out.printf("City: State: Postal Code: ", this.city, this.state, this.PostalCode); } public boolean comesBefore(CreamCracker other) { if (this.PostalCode < other.PostalCode) { return true; } else { return false; } } } 

this is my code. But it is not running. Can you help me?

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 Programming Questions!