Write a method that lets a caller add water taken from a 64-ounce jug into an empty 12-ounce bottle. Assume there are already fields for jugOunces and bottleOunces. The number of ounces to be poured into the bottle is determined when the method is called(using a parameter). If too much water is added it will spill and be lost so the method should prevent the caller from adding too much. We also need to keep track of how much water is still in the jug so we don't add whats no longer there.
public class Jug { private static int jugOunces = 64; private static int bottleOunces; public static int waterJug; public Jug() { jugOunces = 64; bottleOunces = 12; } public static void main(int waterAdd){ //ERROR HERE if (waterAdd > 13) { System.out.println("Bottle can only hold 12 ounces!"); waterJug = 64; } else if(waterAdd <= 12) waterJug = jugOunces - waterAdd; printInfo(); } public static void printInfo() { System.out.println("There is " + waterJug + "ounces left in the jug."); } }
It must never end and allow user to keep pouring water until jug of 64 ounces is empty