Question

Q17 Suppose the following classes (some details were omitted) 10 Points class Hair { public boolean isClean() { } // Returns

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Whether you face any problem or need any modification then share with me in the comment section, I'll happy to help you.

Program

class Hair{
   public boolean isClean(){ return false;}
   public void lather(){}
}

class Shampoo{
   public void openBottle(){}
   public void closeBottle(){}
   public void apply(Hair hair){}
}

class Basin{
   public void fill(){}
   public void flush(){}
   public void rinse(Hair hair){}
}


public class Main {

public static void main(String[] args) {

   Hair hair = new Hair();
   Shampoo shampoo = new Shampoo();
   Basin basin = new Basin();
  
   do
   {
           shampoo.openBottle();
           shampoo.closeBottle();
          
           basin.fill();
           shampoo.apply(hair);
           hair.lather();
           basin.rinse(hair);
           basin.flush();
          
   }while(!hair.isClean());
}
}
      
  

Add a comment
Know the answer?
Add Answer to:
Q17 Suppose the following classes (some details were omitted) 10 Points class Hair { public boolean...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Consider the following classes (For Java): class A { public void process() { // Details omitted...

    Consider the following classes (For Java): class A { public void process() { // Details omitted } } class B extends A { public void compute() { // Details omitted } } class C extends B { public void calculate() { // Details omitted } } Which of the following client code fragments are legal? Select one or more: C c = new C(); c.compute(); A c = new C(); c.process(); C c = new A(); c.process(); A a =...

  • Consider the following Java classes: class A{ public int foo () { return 1; } public...

    Consider the following Java classes: class A{ public int foo () { return 1; } public void message () { System.out.println( "A" + foo()); } } class B extends A { public int foo() {return 2; } } class C extends B { public void message () { System.out.println( "C" + foo()); } } (i) What are the outputs of the following code? (ii) What would be the outputs if Java used static dispatching rather than dynamic dispatching? B b...

  • Q19 Consider the following main function: 10 Points public class Main { public static void main(String[]...

    Q19 Consider the following main function: 10 Points public class Main { public static void main(String[] args) { Office office = new Office("5421 Sennott Square"); office.setOccupant("Luis"); office.width 5.0; office.setDepth(4.0); office.closeDoor(); System.out.println( office.toString() ); هه فه Program output (ignore the colors, gradescope's fault): Office information: Location: 5421 Sennott Square Occupant: Luis Area: 20.0 Door: Closed Q19.1 Implement the class Office that makes the program above work and produce the correct output 10 Points public class Office { Enter your answer here

  • Classes A Customer Points class maintains information about a customer. This information is the customer name...

    Classes A Customer Points class maintains information about a customer. This information is the customer name (entire name as a String) and the amount of points (as an int) the customer has accrued. Methods: Constructor: Receives a name and sets the name field to the received name and sets the points field to 0 (zero). getName: Returns the customer's name getPoints: Returns the customer's current points toString: Returns a String representation of the current state in the form-name points, i.e....

  • Please answer all the questions thank you 1) (Classes – 20 Points) Consider the following class...

    Please answer all the questions thank you 1) (Classes – 20 Points) Consider the following class declaration for Time to complete the questions below: DO NOT WRITE MORE THAN ASKED FOR. class Time private: int hours; int minutes; public: Time(); Time (int , int m = 0); void addMin(int m); void addHr(int h); void reset(int h = 0, int m = 0); Time operator+(const Time & t) const; Time operator-(const Time & t) const; Time operator*(double n) const; friend Time...

  • Q21 Read the following code: 8 Points public class Main { public static int[][] doStuff() {...

    Q21 Read the following code: 8 Points public class Main { public static int[][] doStuff() { int[][] array2D = new int[3][2]; for (int i = 0; i < array2D.length; i++) { for (int j = 0; j < array2D[0].length; j++) { array2D[i][j] = (i+j)%2; } } return array2D; فه public static void main(String[] args) { int[][] a = doStuff(); مہ سره Q21.1 What are the contents of array a? 6 Points Write your answer as if printing the elements row-by-row....

  • 1-Assume that the Plant class looks like the following: public abstract class Plant { private int...

    1-Assume that the Plant class looks like the following: public abstract class Plant { private int age=0; private int height=0; public int getAge() { return age; } public void addYearToAge() { age++; } public int getHeight() { return height; } public void setHeight(int height) { this.height = height; } abstract public void doSpring(); abstract public void doSummer(); abstract public void doFall(); abstract public void doWinter(); } 2- Assume that the MapleTree class looks like the following: public class MapleTree extends...

  • Question: Write the Main class code for the following application. The first three classes are given...

    Question: Write the Main class code for the following application. The first three classes are given below. Lottery This lottery app allows users to sign up for an account, choose a random number or two, and then win a certain amount of money if their chosen number matches the number that the game draws. The house keeps the cash proceeds if nobody wins. The app must repeatedly do the following: Allow the user to (1) Add Player Account (2) Play...

  • Activity: Writing Classes Page 1 of 10 Terminology attribute / state behavior class method header class...

    Activity: Writing Classes Page 1 of 10 Terminology attribute / state behavior class method header class header instance variable UML class diagram encapsulation client visibility (or access) modifier accessor method mutator method calling method method declaration method invocation return statement parameters constructor Goals By the end of this activity you should be able to do the following: > Create a class with methods that accept parameters and return a value Understand the constructor and the toString method of a class...

  • Given the following classes: StringTools.java: public class StringTools { public static String reverse(String s){ char[] original=s.toCharArray();...

    Given the following classes: StringTools.java: public class StringTools { public static String reverse(String s){ char[] original=s.toCharArray(); char[] reverse = new char[original.length]; for(int i =0; i<s.length(); i++){ reverse[i] = original[original.length-1-i]; } return new String(reverse); } /**  * Takes in a string containing a first, middle and last name in that order.  * For example Amith Mamidi Reddy to A. M. Reddy.  * If there are not three words in the string then the method will return null  * @param name in...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT