Write all the contents of a java file named \'WashingMachine.java\' This file co
ID: 3919053 • Letter: W
Question
Write all the contents of a java file named 'WashingMachine.java' This file contacts the class washing Machine that represents a real-life washing machine.
Every WashingMachine is identified by 3 attributes: a brand to identify the made of the WashingMachine(i.e "GM", "LG", Hoover") a capacity that a and integer number indicating the volume of the WashingMachine in cc (cubic centimerters), and a boolean variable ecoFriendly, that indicates if the WashingMachine is ecolgically frienldy (true) or not (false).
Write syntactically correct Java code for all the 3 attributes mentions above (use the names brand, capactiy and ecoFriendly) its 3 accessors methods (get methods). its 3 mutator methods (set.methods), and two appropriate contructor methods that initialize all its instance variables (one default and one with all attributes as a parameters) using the mutator methods. You must also write an equals methods that compares all attributes of WashingMachines for equality using the accessor methods.
Explanation / Answer
public class WashingMachine { private String brand; private int capacity; private boolean ecoFriendly; public String getBrand() { return brand; } public void setBrand(String brand) { this.brand = brand; } public int getCapacity() { return capacity; } public void setCapacity(int capacity) { this.capacity = capacity; } public boolean isEcoFriendly() { return ecoFriendly; } public void setEcoFriendly(boolean ecoFriendly) { this.ecoFriendly = ecoFriendly; } public WashingMachine(String brand, int capacity, boolean ecoFriendly) { setBrand(brand); setCapacity(capacity); setEcoFriendly(ecoFriendly); } public WashingMachine() { this("GM", 0, true); } @Override public boolean equals(Object obj) { WashingMachine machine = (WashingMachine) obj; return brand.equals(machine.brand) && capacity == machine.capacity && ecoFriendly == machine.ecoFriendly; } }
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.