Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

5. [40 points] Use the following UML diagram and the partially completed code fo

ID: 3728654 • Letter: 5

Question

5. [40 points] Use the following UML diagram and the partially completed code for the class Bottle. Complete the code.
   a. [10 points] Add the properties.
   b. [10 points] Implement the getter for the property filled.
c. [10 points] Finish the constructor Bottle(double, String). Make it verify that the unit is “oz” or “cc”, and sets it to “oz” if not.
d. [10 points] Finish the method fill(double amount).The parameter amount represents the amount of liquid to be added to the bottle. The property filled represents the amount of liquid already in the bottle. Make the method verify that the bottle will not overflow. The bottle can be filled to capacity but no more.

public class Bottle{
   //Properties go here.

                                  

public Bottle (double size, String unit){
//Finish this constructor.

}

public Bottle(double size){
this(size,"oz");
}
public Bottle(){
this(16.0,"oz");
}
public double getSize() {return size;}
public String getUnit() {return unit;}
//Implement a getter for filled here.


public void fill(double amount){
//Finish this method here.

}
}

Explanation / Answer

public class Bottle{

   //Properties go here.

   private double size;

   private String unit;

   private double filled;

   public Bottle (double size, String unit){

       //Finish this constructor.

       this.size = size;

       this.unit= unit;

       filled = 0;

   }

   public Bottle(double size){

       this(size,"oz");

   }

   public Bottle(){

       this(16.0,"oz");

   }

   public double getSize() {return size;}

   public String getUnit() {return unit;}

   //Implement a getter for filled here.

   public double getFilled() {return filled;}

   public void fill(double amount){

       //Finish this method here.

       if((size - filled) >= amount)

           filled = filled + amount;

       else

           filled = size;

   }

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote