Please read the instructions crefelly this is a java code programming please solve it. don plagarise or copy from other sources please. Please do what in the question says .There are previous lab codes needed. So, I am providing the codes- Apartment classes from Lab 17 code - public class Apartment extends Building { private int totalUnits; public Apartment (String name, CanadianAddress address, int squareFootage, int totalUnits) { super (name, address, squareFootage); this.totalUnits = totalUnits; } public int getTotalUnits () { return totalUnits; } public void setTotalUnits (int totalUnits) { this.totalUnits = totalUnits; } } CanadianAddress class from Lab 18 code - public class TestCanadianAddresslab18 { public static void main(String[] args) { CanadianAddress testAddress = new CanadianAddress(); CanadianAddress SMUAddress = new CanadianAddress("923 Robie St.", "Halifax", "Nova Scotia", "B3H 3C3"); System.out.println("The testAddress is created as:"); System.out.println(testAddress); System.out.println(); System.out.println("The SMUAddress is created as:"); System.out.println(SMUAddress); System.out.println(); System.out.println("The testAddress is equal to SMUAddress? : " + testAddress.equals(SMUAddress)); System.out.println(); testAddress.setStreetAddress("923 Robie St."); testAddress.setCity("Halifax"); testAddress.setProvince("Nova Scotia"); testAddress.setPostalCode("B3H 3C3"); System.out.println("The testAddress is updated as: "); System.out.println(testAddress); System.out.println(); System.out.println("The testAddress is equal to SMUAddress? : " + testAddress.equals(SMUAddress)); } } class CanadianAddress { private String streetAddress; private String city; private String province; private String postalCode; public CanadianAddress() {} public CanadianAddress(String streetAddress, String city, String province, String postalCode) { this.streetAddress = streetAddress; this.city = city; this.province = province; this.postalCode = postalCode; } public String getStreetAddress() { return streetAddress; } public void setStreetAddress(String streetAddress) { this.streetAddress = streetAddress; } public String getCity() { return city; } public void setCity(String city) { this.city = city; } public String getProvince() { return province; } public void setProvince(String province) { this.province = province; } public String getPostalCode() { return postalCode; } public void setPostalCode(String postalCode) { this.postalCode = postalCode; } @Override public String toString() { return (streetAddress != null ? streetAddress : "null") + ", " + (city != null ? city : "null") + "\n" + (province != null ? province : "null") + " " + (postalCode != null ? postalCode : "null") + ", Canada"; } @Override public boolean equals(Object address) { if (this == address) return true; if (address == null || getClass() != address.getClass()) return false; CanadianAddress that = (CanadianAddress) address; return (this.streetAddress == null ? that.streetAddress == null : this.streetAddress.equals(that.streetAddress)) && (this.city == null ? that.city == null : this.city.equals(that.city)) && (this.province == null ? that.province == null : this.province.equals(that.province)) && (this.postalCode == null ? that.postalCode == null : this.postalCode.equals(that.postalCode)); } }
Please read the instructions crefelly this is a java code programming please solve it. don plagarise or copy from other sources please. Please do what in the question says .There are previous lab codes needed. So, I am providing the codes-
Apartment classes from Lab 17 code -
CanadianAddress class from Lab 18 code -
public class TestCanadianAddresslab18 {
public static void main(String[] args) {
CanadianAddress testAddress = new CanadianAddress();
CanadianAddress SMUAddress = new CanadianAddress("923 Robie St.", "Halifax", "Nova Scotia", "B3H 3C3");
System.out.println("The testAddress is created as:");
System.out.println(testAddress);
System.out.println();
System.out.println("The SMUAddress is created as:");
System.out.println(SMUAddress);
System.out.println();
System.out.println("The testAddress is equal to SMUAddress? : " + testAddress.equals(SMUAddress));
System.out.println();
testAddress.setStreetAddress("923 Robie St.");
testAddress.setCity("Halifax");
testAddress.setProvince("Nova Scotia");
testAddress.setPostalCode("B3H 3C3");
System.out.println("The testAddress is updated as: ");
System.out.println(testAddress);
System.out.println();
System.out.println("The testAddress is equal to SMUAddress? : " + testAddress.equals(SMUAddress));
}
}
class CanadianAddress {
private String streetAddress;
private String city;
private String province;
private String postalCode;
public CanadianAddress() {}
public CanadianAddress(String streetAddress, String city, String province, String postalCode) {
this.streetAddress = streetAddress;
this.city = city;
this.province = province;
this.postalCode = postalCode;
}
public String getStreetAddress() {
return streetAddress;
}
public void setStreetAddress(String streetAddress) {
this.streetAddress = streetAddress;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public String getProvince() {
return province;
}
public void setProvince(String province) {
this.province = province;
}
public String getPostalCode() {
return postalCode;
}
public void setPostalCode(String postalCode) {
this.postalCode = postalCode;
}
@Override
public String toString() {
return (streetAddress != null ? streetAddress : "null") + ", " +
(city != null ? city : "null") + "\n" +
(province != null ? province : "null") + " " +
(postalCode != null ? postalCode : "null") + ", Canada";
}
@Override
public boolean equals(Object address) {
if (this == address) return true;
if (address == null || getClass() != address.getClass()) return false;
CanadianAddress that = (CanadianAddress) address;
return (this.streetAddress == null ? that.streetAddress == null : this.streetAddress.equals(that.streetAddress))
&& (this.city == null ? that.city == null : this.city.equals(that.city))
&& (this.province == null ? that.province == null : this.province.equals(that.province))
&& (this.postalCode == null ? that.postalCode == null : this.postalCode.equals(that.postalCode));
}
}
Step by step
Solved in 4 steps with 6 images