Write the complete equals method (including the method header) for the Appliance class. Two appliance objects are logically equivalent if they have the same description (ignoring capitalization), id (ignoring capitalization), and price. As an example, the two appliances with this data would be considered equal: "dishwasher", "ABC123", 999 "DISHWASHER", "abc123", 999 Here is the appliance class: public class Appliance { private String description; private String id; private int price; // using an int for simplicity public Appliance(String description, String id, int price) { this.description = description; this.id = id; this.price = price; } public String getDescription() { return description; } public void setDescription(String description) { this.description = description; } public String getId() { return id; } public void setId(String id) { this.id = id; } public int getPrice() { return price; } public void setPrice(int price) { if(price > 0) { this.price = price; } } @Override public String toString() { return description + "\n\tID: " + id + "\tPrice: $" + price; } }
Write the complete equals method (including the method header) for the Appliance class. Two appliance objects are logically equivalent if they have the same description (ignoring capitalization), id (ignoring capitalization), and price.
As an example, the two appliances with this data would be considered equal:
"dishwasher", "ABC123", 999
"DISHWASHER", "abc123", 999
Here is the appliance class:
public class Appliance {
private String description;
private String id;
private int price; // using an int for simplicity
public Appliance(String description, String id, int price) {
this.description = description;
this.id = id;
this.price = price;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public int getPrice() {
return price;
}
public void setPrice(int price) {
if(price > 0) {
this.price = price;
}
}
@Override
public String toString() {
return description +
"\n\tID: " + id + "\tPrice: $" + price;
}
}
Step by step
Solved in 2 steps with 1 images