java code 1 of 2

java code 1 of 2

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

View Answers

December 21, 2010 at 5:58 PM

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 acceptDetergent () {
        System.out.println("Adding Detergent.. ");
    }
    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









Related Tutorials/Questions & Answers:
java code 1 of 2
java code 1 of 2  Create a washing machine class with methods as switchOn, acceptClothes, acceptDetergent, switchOff. acceptClothes accepts the noofClothes as argument & returns the noofClothes   Hi Friend, Visit
java code 1 of 2
java code 1 of 2  Create a washing machine class with methods as switchOn, acceptClothes, acceptDetergent, switchOff. acceptClothes accepts... the following code: import java.util.*; class WashingMachine { Scanner input
Advertisements
java code 8 of 1
java code 8 of 1  Develop a program that computes the distance a boat travels across a river, given the width of the river, the boat's speed perpendicular to the river, and the river's speed. Speed is distance/time
WAP in java to print the series 1*2*3
WAP in java to print the series 1*2*3  WAP in java to print the series 123
Cohabitation struts 1 and 2 - Struts
Cohabitation struts 1 and 2  Hi, I have a problem with the cohabitation of struts 1 and 2. I work on a web application which used struts 1. But i must add some functionality in struts 2. When i modify my web.xml file
Struts 2 Integration with Struts 1
Struts 2 Integration with Struts 1  I want to integrate struts 2 with struts 1 existing application. Can you please help on how to go about this. I am not finding any good source to integrate struts 2 with struts 1 framework
What does "1"+2+4 evaluate to?
What does "1"+2+4 evaluate to?  What does "1"+2+4 evaluate
java code to validate column content of 2 different tables in 2 different databases.
java code to validate column content of 2 different tables in 2 different... that the migrated data is correct by creatng a script to run written in java. how to compare 2 columns(different col_name) in 2 different databases placed
JSP Architecture, JSP Model 1 architecture, JSP Model 2 architecture
. In the JSP page programmers embeds Java code for generating dynamic content. JSP...: Model 1 Architecture Model 2 Architecture JSP Model 1... of the architecture is used. These architectures are known as Model 1
Java Struts 2 Programmer
Java Struts 2 Programmer       Position Vacant: Java Struts 2 Programmer  Job...; Writing code for the rest of the application  Struts 
task 1 - Java Beginners
task 1  Please write a Java client that send a small letters string to a Java server which convert it to uppercase letters and send it back..., Try the following code: import java.util.*; class ChangeCase{ public
array 1 - Java Beginners
array 1  WAP to input values in 2 arrays and merge them to array M.  Hi Friend, Try the following code: import java.util.*; class MergeArray{ public static int[] merge(int [] ... arr) { int arrSize = 0
problem 1 - Java Beginners
problem 1   Hi, please help me!!!! How can i code in java using Two-dimensional Arrays? This question is related to the one i posted before. this is my input data file: 88 90 94 102 111 122 134 75 77 80 86 94 103 113 80
java code7 of 1
java code7 of 1  Develop the program calculateHeight, which computes the height that a rocket reaches in a given amount of time. If the rocket accelerates at a constant rate g, it reaches a speed of g Ã?· t in t time units
java program 1
java program 1  (4) WAP to take input of a String and check wheather it is valid number or not? Sample Output1: Enter a String : 10 10 is a number Sample Output2: Enter a String : 10b1 10b1 is not a number (5) WAP to take
que 1 - Java Beginners
que 1  WAP to enter a sentence & count the no. of times a particular word occurs in it.Display the frequency of the searched word. eg- input...:frequency of word-2 times   Hi Friend, Try the following code: import
function 1 - Java Beginners
function 1  WAP to calculate the value of x,where x=tan(A)+tan(B)/1+tan(A)*tab(B)  Give more details like how to calculate and what is tan(A) and tan(B),etc
loop code to print the Pyramid: 1 1234 12 123 123 12 1234 1
loop code to print the Pyramid: 1 1234 12 123 123 12 1234 1  Hi, I want to know how the code to print the pyramid below works. It uses nested for loops. Pyramid: 1 1234 12 123 123 12 1234 1
Java programming 1 - Java Beginners
Java programming 1  write one program, which consists of a main... be at position 1, etc ?A sentence is constructed with a series of words? Index 0 1 2 3 4...? There are nine words in total Java has a standard to index elements starting
Java programming 1 - Java Beginners
Java programming 1  Thx sir for reply me ^^ err how bout if using scanner class or further method to solve that code? instead of using array?  ...://www.roseindia.net/java/java-tips/examples-introductory/console/console-input
Java programming 1 - Java Beginners
Java programming 1  write one program, which consists of a main... 1 2 3 4 5 6 7 8 We need to provide a method...? There are nine words in total Java has a standard to index elements starting
Java programming 1 - Java Beginners
Java programming 1  thx sir for reply me..but sir can u pls simplify...; Hi friend, 1. Ask the user for their height. Convert it to a double. 2. Ask the user for their weight. Convert it to a double. 3. Use
Java programming 1 - Java Beginners
Java programming 1  Hi sir, i facing problem in this program....   Hi friend, Please send me full code. Because your.../java/example/java/swing/ Thanks
Java programming 1 - Java Beginners
Java programming 1  hi there, Sir! Can u help me check where my program gone wrong? here are my coding =D, hope to get reply from u guys soon... = JOptionPane.showInputDialog(null,"Enter mark 1", "Homework 8",JOptionPane.QUESTION_MESSAGE
GUI 2 - Java Beginners
GUI 2  How can I modify this code? Please give me a GUI...); }}//newly added code//KeyEvent function public void numberTextField_KeyTyped...();}}This will help you out..  Brilliant! The keyEvent works, but the modified code
Struts: validations code to support 2 date foramats - Struts
Struts: validations code to support 2 date foramats  What is the code in validation.xml to support 2 date formats (DD-MM-YYYY & DD/MM/YYYY ) in form. (I'm using struts 1.3
Moire Pattern 2 Java
Moire Pattern 2 Java   textWhat you are seeing in the screenshot... and height are the same. Make the program from this older code: import...; g2.setColor(Color.black);g2.fillOval(centerX, centerY - ovalWidth / 2, 300, ovalWidth
task 2 - Java Beginners
task 2  Write a time server that follows the time protocol outlined in RFC 868. When a client connects, the server sends a 4-byte, big-endian..., January 1, 1970 GMT (the epoch
EXCEPTIONS-----1 - Java Interview Questions
EXCEPTIONS-----1  How To Handle The Exceptions With Out Using Try,Catch And Throws?I Want Region Plz Post Answer
que 2 - Java Beginners
que 2  WAP to input a string & print out the text withthe uppercase & lowercase letters reversed,but all other characters should remain the same..., Try the following code: import java.util.*; class CaseConverter{ public
Java 2 micro editionJ
Java 2 micro editionJ  Hello, i am using JCreator, for writing my J2ME program, after building the program, it keeps on given me the following errors: package javax.microedition.midlet does not exist package
INTTERFACE 1 - Java Interview Questions
INTTERFACE 1  What is a Interface?  Hi Friend, Interface is the collection of methods with empty implementations and constants variables ( variables with static and final declarations ). All the methods
this code gives addition of 2 numbers in j2me..but the code is not executing ..can u pls find out the error...??
this code gives addition of 2 numbers in j2me..but the code is not executing...",Command.OK,1); ok=new Command("Ok",Command.OK,1); t1=new TextField...",Command.BACK,1); f2.addCommand(c3); f2.setCommandListener
Java Loop 2 - Java Beginners
Java Loop 2  WAP to print d following patter wid d help of ne loop possible
Java 2 Micro Edition - MobileApplications
Java 2 Micro Edition  I meet difficulties to do my final project using J2me.It's about train ticket booking in mobile.Pls help on how to do this source code using j2me.Thank You
Java 2 Micro Edition - MobileApplications
Java 2 Micro Edition  I meet difficulties to do my final project using J2me.It's about train ticket booking in mobile.Pls help on how to do this source code using j2me.Thank You
OOP with Java 2 - Java Beginners
OOP with Java 2  Define a class called BogEntry that could be used to store an entry for a Web log. The class should have member variables to store the poster's username, text of entry, and the date of the entry using the Date
Java 2 SDK, Standard Edition,
Java 2 SDK, Standard Edition,  Once I have the Java 2 SDK, Standard Edition, from Sun, what else do I need to connect to a database
java bits 1 - Java Interview Questions
java bits 1   Given: 11. public interface Status { 12. /* insert code here */ int MY_VALUE = 10; 13. } Which three are valid on line 12? (Choose three.) A. final B. static C. native D. public E. private F. abstract G
arrays part 2 - Java Beginners
arrays part 2  Question 2: Useful Array Algorithms and Operations (5 marks) Upgrade the program in Question 1 so that the program includes... index if the integer appears in the array o Returns -1 otherwise. ? A static
java 2 d array program
java 2 d array program  write a program 2-d matrix addition through user's input?  Hi Friend, Try the following code: import...[][] A = new int[2][2]; int[][] B = new int[2][2]; int[][] C = new int[2][2
More than 1 preparedStatement object - Java Beginners
Statement object in the java class.Try the following code: import java.sql.... =?"); pst1.setString(1, "Delhi"); pst1.setString(2... =?"); pst2.setString(1, "Agra"); pst2.setString(2, "AAAAA
readline Error 2 - Java Beginners
readline Error 2  Hi sir, can you look again please. The error is hard to notice, but if you execute the code, 1. enter a string the first input request (eg hello world), 2. ENTER 3a. ENTER n for the next input request
JAVA leftshift operator add 1 instead of 0
JAVA leftshift operator add 1 instead of 0  Hi Guys, I have a task... this in java. Please help me asap. Thanks. Code Eater... to clipboardprint? byte a = 5, b; int i; i = a << 2; So, it will work like
Prime numbers in Java between 1 and 100
Prime numbers in Java between 1 and 100  Hi, How to display prime numbers in java between 1 and 100? Thanks   Hi, Prime numbers are the number which is divisible by itself and 1. I have provide you Java program
executing java program with 2 classes
executing java program with 2 classes  how to run a program of java containing more than one class....ex of program is given below.... class C...); } }   Executing java program with 2 classes save the file with D.java
object 2 string - Java Beginners
object 2 string  hi sir,how to convert object to string and how 2 compare object with null value to string with null value plz provide a program 4 this sir,plzzzzzzzzz
returning doubles with 2 decimals JAVA
returning doubles with 2 decimals JAVA  Hi all. I'm writing a program where users input the cost of an item (in the constructor), so for example, Item (string name, double cost, int qty) { ... } I have a method public double
code in java
: T(n) = n(n+1)/2 These numbers are called Mathew numbers. And scientist John... with 1, then it is called John number. Example of John numbers is: 13 = 1^2 + 3^2 = 1+9 = 10 (Step : 1). 10 = 1^2 + 0^2 = 1+0 = 1 (Step : 2), iteration ends
JAVA code For
JAVA code For   JAVA code For "Traffic signals Identification for vehicles

Ads