Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

package modelobject; public class WashingMachine { private double maxLoad; private boolean hasDryer; public WashingMachine(double maxLoad, boolean hasDryer) { this.maxLoad = maxLoad; this.hasDryer = hasDryer; }

package modelobject;

public class WashingMachine { private double maxLoad; private boolean hasDryer;

public WashingMachine(double maxLoad, boolean hasDryer) { this.maxLoad = maxLoad; this.hasDryer = hasDryer; } //getters and setters public double getMaxLoad() { return maxLoad; }

public void setMaxLoad(double maxLoad) { this.maxLoad = maxLoad; }

public boolean isHasDryer() { return hasDryer; }

public void setHasDryer(boolean hasDryer) { this.hasDryer = hasDryer; } //load method loads clothes in the washing machine public void loadClothes(double load){ if(load>maxLoad){ //if the load is greater than the maxLoad System.out.println("That is too many clothes! Max Load: "+maxLoad+" pounds"); }else{ //else the clothes are loaded System.out.println("Clothes are loaded!"); } } //wash method washes the clothes public void wash(){ System.out.println("The clothes have been washed!"); } //dry clothes method public void dryClothes(){ //if the hasDryer method is true if(hasDryer) System.out.println("The clothes have been dried!"); else System.out.println("This washing machine has no drying feature.");} } public class Week1 {

public static void main(String[] args) { //instantiating a WashingMachine object WashingMachine washingMachine = new WashingMachine(16.9,true); washingMachine.loadClothes(45.0); washingMachine.loadClothes(10.0); washingMachine.wash(); washingMachine.dryClothes(); }

}

Correct based on the feedback's which are

Its better practice to use descriptive variable/object/parameter names to improve readability and maintenance

Brand would be a good attribute to use and would give you a better way to use descriptive variable names

and add encapsulation to it to include making all attributes private, adding constructor, and adding get and set methods. The main method should create an instance of the class and demonstrate the correct functionality of all the methods.

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

Introduction To Data Mining

Authors: Pang Ning Tan, Michael Steinbach, Vipin Kumar

1st Edition

321321367, 978-0321321367

More Books

Students also viewed these Databases questions

Question

Describe the steps in an effective performance management system.

Answered: 1 week ago