Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Modern Dental Assisting

Authors: Doni Bird, Debbie Robinson

13th Edition

978-0323624855, 0323624855

Students also viewed these Programming questions