Question: Write a Bottle class. The Bottle will have one private int that reprrsents the countable value in the Bottle. Please use one of these names:

Write a Bottle class. The Bottle will have one private int that reprrsents the countable value in the Bottle. Please use one of these names: cookies, marbles, M&M, pennies, nickels, dimes or pebbles. The class has these 14 methods : read(), set(int), set(Bottle), get(), add(Bottle), substract(Bottle), multiply(Bottle), divide(Bottle), add(int), substract(int), multiply(int), divide(int), equals(Bottle), and toString() (toString() method will be given in class). All add, substract, multiply and divide methods return a Bottle. This means the demo code b2 = b3.add(b1) brings into the add method a Bottle b1 which is added to b3. Bottle b3 is the this Bottle.The returned bottle is a new bottle containing the sum of b1 and b3. The value of b3 (the this bottle)is not changed. Your Bottle class must guarantee bottles always have positive value and never exceed a maximum number chosen by you. These numbers are declared as constants of the class. Use the names min and max. Each method with a parameter must be examined to determine if the upper or lower bound could be violated, In the case of the add method with a Bottle parameter your code must test for violating the maximum value. It is impossible for this add mathod to violate the minimum value of zero. The method substract with a Bottle parameter must test for a violation of te minimum zero value but should not test for exceeding the maximum value. Consider each method carefully and test only the conditions that could be violated.

I have Bottle Demo as an attachment code that already given.

import java.util.Scanner; // test driver for the Bottle class public class BottleDemo3 { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int x; Bottle bottle1 = new Bottle(); Bottle bottle2 = new Bottle(); Bottle bottle3 = new Bottle(); Bottle bottle4 = new Bottle(); Bottle bottle5 = new Bottle(); System.out.println("please enter a number for bottle1:"); bottle1.read(); System.out.println("Bottle1 is this value " + bottle1 + "."); System.out.println("Please enter a number for bottle2:"); bottle2.read(); bottle3 = bottle2.add(bottle1); System.out.println("The sum of bottle2 and bottle1 is: " + bottle3 + "."); bottle4 = bottle3.divide(2); System.out.println("The 2 bottle average is: " + bottle4 + "."); System.out.print("Subtracting bottle1 from bottle2 is: " ); bottle3 = bottle2.subtract(bottle1); System.out.println( bottle3); bottle3 = bottle2.divide(bottle1); System.out.println("Dividing bottle2 with bottle1 is: " + bottle3 + "."); if (bottle1.equals(bottle2)) { System.out.println("Bottle1 and bottle2 are equal."); } else { System.out.println("Bottle1 and bottle2 are not equal."); } System.out.println("Bottle4 is now given the value of 10 with the set() method."); bottle4.set(10); System.out.println("The value of bottle4 is " + bottle4 + "."); System.out.println("Bottle4 is now multipled with bottle1. The value is placed in " + "bottle5."); bottle5 = bottle1.multiply(bottle4); System.out.println("The value of bottle5 is " + bottle5 + "."); System.out.println("Enter an integer to add to the value bottle1 has."); System.out.println("The sum will be put in bottle3."); x = scan.nextInt(); bottle3 = bottle1.add(x); System.out.println("Adding your number " + x + " to bottle1 gives a new Bottle with " + bottle3 + " in it."); System.out.print("Adding the number " + bottle2 + " which is the number" + " in bottle2 to the number in "); bottle2 = bottle1.add(bottle2); System.out.println("bottle1 which is " + bottle1 +" gives " + bottle2 + "."); bottle2.set(bottle2.get()); } } 

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!