
Create a washing machine class with methods as switchOn, acceptClothes, acceptDetergent, switchOff. acceptClothes accepts the noofClothes as argument & returns the noofClothes

Hi Friend,
Try the following code:
import java.util.*;
class WashingMachine
{
Scanner input=new Scanner(System.in);
public void switchOn () {
System.out.println ("The lid is open.");
}
public void start () {
System.out.println ("Start washing ...");
}
public void acceptDetergent () {
System.out.println("Adding Detergent.. ");
start();
}
public int acceptClothes(){
System.out.println("Enter no of clothes: ");
int no=input.nextInt();
return no;
}
public void switchOff () {
System.out.println ("The lid is closed.");
}
public static void main(String[] args)
{
WashingMachine wm=new WashingMachine();
wm.switchOn();
int numOFClothes=wm.acceptClothes();
wm.acceptDetergent();
wm.switchOff();
System.out.println(numOFClothes+" clothes get washed");
}
}
Thanks
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.