/*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 zip 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.*/

public class P8_04 {
int houseNumber;
String street;
int apartmentNumber;
String city;
String state;
int postalCode;

public P8_04(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 P8_04(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: %s House number: %s \n", this.street, this.houseNumber);
System.out.printf("City: %s State: %s Postal Code: %d\n", this.city, this.state, this.postalCode);
}

public boolean comesBefore(P8_04 other) {
if (this.postalCode < other.postalCode) {
return true;
} else {
return false;
}
}
}

Respuesta :

Answer:

Java.

Explanation:

public class Address {

   int houseNumber;

   String street;

   int apartmentNumber;

   String city;

   String state;

   int postalCode;

   public Address(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 Address(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: %s%n", this.street);

       System.out.printf("City: %s, State: %s, Postal Code: %d.%n", this.city, this.state, this.postalCode);

   }

   public boolean comesBefore(Address other) {

       if (this.postalCode < other.postalCode) {

           return true;

       }

       else {

           return false;

       }    

   }

}

The few changes I made are in bold.

In this exercise we want to use computer and Java knowledge to write the code correctly, so it is necessary to add the following to the informed code:

The code given in the image is the final answer to this question

To facilitate the code and a possible copy will be rewritten below as:

public class Address {

  int houseNumber;

  String street;

  int apartmentNumber;

  String city;

  String state;

  int postalCode;

}

  public Address(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 Address(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: %s%n", this.street);

      System.out.printf("City: %s, State: %s, Postal Code: %d.%n", this.city, this.state, this.postalCode);

  }

  public boolean comesBefore(Address other) {

      if (this.postalCode < other.postalCode) {

          return true;

      }

      else {

          return false;

      }    

  }

}

See more about computer at brainly.com/question/950632

Ver imagen lhmarianateixeira
ACCESS MORE
ACCESS MORE
ACCESS MORE
ACCESS MORE