package pr01; public class GroceryListTester { public static void main(String[] args) { System.out.println("GroceryListTester written by S. Robbins"); GroceryProduct groceryProduct1 = new GroceryProduct("apples", 1.25, .15, 5.25); System.out.println(groceryProduct1); System.out.println("getName returned " + groceryProduct1.getName()); System.out.println("getPricePerPound returned " + groceryProduct1.getPricePerPound()); System.out.println("getDiscountRate returned " + groceryProduct1.getDiscountRate()); System.out.println("getStartingDiscountWeight returned " + groceryProduct1.getStartingDiscountWeight()); GroceryProduct groceryProduct2 = new GroceryProduct("oranges", 2.05, .10, 7.00); System.out.println(groceryProduct2); GroceryProduct groceryProduct3 = new GroceryProduct("pears", 3.00, .25, 2.00); System.out.println(groceryProduct3); GroceryProduct groceryProduct4 = new GroceryProduct("asparagus", 6.00, .05, 4.00); System.out.println(groceryProduct4); double weight; GroceryProduct product; weight = 2; product = groceryProduct1; System.out.println("The price of " + weight + " pounds of " + product.getName() + " is $" + product.getSellingPrice(weight)); weight = 5.25; product = groceryProduct1; System.out.println("The price of " + weight + " pounds of " + product.getName() + " is $" + product.getSellingPrice(weight)); weight = 5.5; product = groceryProduct1; System.out.println("The price of " + weight + " pounds of " + product.getName() + " is $" + product.getSellingPrice(weight)); weight = 12; product = groceryProduct1; System.out.println("The price of " + weight + " pounds of " + product.getName() + " is $" + product.getSellingPrice(weight)); weight = 25; product = groceryProduct1; System.out.println("The price of " + weight + " pounds of " + product.getName() + " is $" + product.getSellingPrice(weight)); weight = 50; product = groceryProduct1; System.out.println("The price of " + weight + " pounds of " + product.getName() + " is $" + product.getSellingPrice(weight)); System.out.println("All tests for part 2 have been completed"); System.out.println("-----------------------------------------------------\n"); GroceryProductList list = new GroceryProductList(); System.out.println("Empty list is: " + list); boolean returnValue; returnValue = list.addGroceryProduct(groceryProduct1); System.out.println("Add product 1 returned " + returnValue); System.out.println("List is now:\n" + list); returnValue = list.addGroceryProduct(groceryProduct2); System.out.println("Add product 2 returned " + returnValue); System.out.println("List is now:\n" + list); returnValue = list.addGroceryProduct(groceryProduct3); System.out.println("Add product 3 returned " + returnValue); System.out.println("List is now:\n" + list); returnValue = list.addGroceryProduct(groceryProduct3); System.out.println("Add product 4 returned " + returnValue); System.out.println("List is now:\n" + list); System.out.println("All tests for part 3 have been completed"); System.out.println("-----------------------------------------------------\n"); weight = 2; String name = "apples"; System.out.println("The price of " + weight + " pounds of " + name + " is $" + list.getSellingPrice(name, weight)); weight = 5.25; System.out.println("The price of " + weight + " pounds of " + name + " is $" + list.getSellingPrice(name, weight)); weight = 20; System.out.println("The price of " + weight + " pounds of " + name + " is $" + list.getSellingPrice(name, weight)); weight = 50; System.out.println("The price of " + weight + " pounds of " + name + " is $" + list.getSellingPrice(name, weight)); weight = 2; name = "pears"; System.out.println("The price of " + weight + " pounds of " + name + " is $" + list.getSellingPrice(name, weight)); weight = 5.25; name = "oranges"; System.out.println("The price of " + weight + " pounds of " + name + " is $" + list.getSellingPrice(name, weight)); name = "grapes"; System.out.println("The price of " + weight + " pounds of " + name + " is $" + list.getSellingPrice(name, weight)); System.out.println("All tests for part 4 have been completed"); System.out.println("-----------------------------------------------------\n"); weight = 2; product = groceryProduct1; System.out.println("The new price of " + weight + " pounds of " + product.getName() + " is $" + product.getNewSellingPrice(weight)); System.out.println("This is a discount of " + getDiscount(product, weight)); weight = 5.25; System.out.println("The new price of " + weight + " pounds of " + product.getName() + " is $" + product.getNewSellingPrice(weight)); System.out.println("This is a discount of " + getDiscount(product, weight)); weight = 5.5; System.out.println("The new price of " + weight + " pounds of " + product.getName() + " is $" + product.getNewSellingPrice(weight)); System.out.println("This is a discount of " + getDiscount(product, weight)); weight = 12; System.out.println("The new price of " + weight + " pounds of " + product.getName() + " is $" + product.getNewSellingPrice(weight)); System.out.println("This is a discount of " + getDiscount(product, weight)); weight = 25; System.out.println("The new price of " + weight + " pounds of " + product.getName() + " is $" + product.getNewSellingPrice(weight)); System.out.println("This is a discount of " + getDiscount(product, weight)); weight = 50; System.out.println("The new price of " + weight + " pounds of " + product.getName() + " is $" + product.getNewSellingPrice(weight)); System.out.println("This is a discount of " + getDiscount(product, weight)); weight = 1000; System.out.println("The new price of " + weight + " pounds of " + product.getName() + " is $" + product.getNewSellingPrice(weight)); System.out.println("This is a discount of " + getDiscount(product, weight)); System.out.println("All tests for part 5 have been completed"); System.out.println("-----------------------------------------------------\n"); System.out.println("All parts are working successfully"); } private static double getDiscount(GroceryProduct product, double weight) { double discount; double pricePerPound = product.getPricePerPound(); double fullPrice = weight * pricePerPound; discount = (fullPrice - product.getNewSellingPrice(weight)) / fullPrice; return discount; } }