package example; import java.util.Scanner; /** * Demonstrates keeping track of Refrigerator items based on food prepared. An * example to tinker with Java Fundamentals * * @author maellis1 * @version May 2020 * */ public class FridgeInventory { private int numberOfItems; private double tempSetting; public static int capacity; /** * Returns the average cost of 3 items * * @param cost1 cost of item 1 in dollars * @param cost2 cost of item 2 in dollars * @param cost3 cost of item 3 in dollars * @return */ public static double avgExpense(double cost1, double cost2, double cost3) { double avg; avg = (cost1 + cost2 + cost3) / 3; return avg; // return (cost1 + cost2 + cost3)/3; } /** * Returns the total cost of 3 items Good idea for money to use BigDecimal from * java. math * * @param cost1 cost of item 1 in dollars * @param cost2 cost of item 2 in dollars * @param cost3 cost of item 3 in dollars * @return */ public static double totalExpense(double cost1, double cost2, double cost3) { double total; total = cost1 + cost2 + cost3; return total; // return (cost1 + cost2 + cost3) } /** * Demonstrates keeping track of Refrigerator items based on food prepared. An * example to tinker with Java Fundamentals */ public static void main(String[] args) { double gallonsOfMilk = 2; // can also separately declare the variable and then assign it int numberOfGreenPeppers = 2; double packagesOfMushrooms = 1; Integer numberOfEggs = 20; // Integer is reference to an Integer object instead of the primitive type Double sticksOfButter = 3.25; // Integer and Double use auto-boxing to convert primitive types so // instantiation not needed boolean cerealForBreakfast = false; boolean omeletForBreakfast = false; Scanner myObj = new Scanner(System.in); //create Scanner object String response; while (gallonsOfMilk > 0 && numberOfEggs >= 8) { System.out.println("Good morning! Choose your breakfast by entering 'cereal' or 'omelet'"); response = myObj.nextLine(); // Read user input if (response.equals("cereal")) { cerealForBreakfast = true; } else if (response.equals("omelet")) { omeletForBreakfast = true; } if (cerealForBreakfast) { gallonsOfMilk = gallonsOfMilk - 1; cerealForBreakfast = false; } else if (omeletForBreakfast) { if (sticksOfButter > .25) { numberOfEggs -= 8; } else { System.out.println("Find some PAM and try again!"); } omeletForBreakfast = false; } System.out.println("Gallons of milk remaining: " + gallonsOfMilk); System.out.println("Number of eggs remaining: " + numberOfEggs); } } }