From d56fd05c3dbf21ffb19fec635849cd442f2a803e Mon Sep 17 00:00:00 2001 From: Logen Kain Date: Wed, 11 Nov 2020 10:46:50 -0500 Subject: [PATCH] More prep for next part --- .../part-2/ItemToPurchase.java | 32 +++++--- Week-11-final-start/part-2/ShoppingCart.java | 59 +++++++++++++++ .../part-2/ShoppingCartManager.java | 33 +++++++++ .../part-2/ShoppingCartPrinter.java | 74 ------------------- 4 files changed, 112 insertions(+), 86 deletions(-) create mode 100644 Week-11-final-start/part-2/ShoppingCart.java create mode 100644 Week-11-final-start/part-2/ShoppingCartManager.java delete mode 100644 Week-11-final-start/part-2/ShoppingCartPrinter.java diff --git a/Week-11-final-start/part-2/ItemToPurchase.java b/Week-11-final-start/part-2/ItemToPurchase.java index 671abfe..f903ce1 100644 --- a/Week-11-final-start/part-2/ItemToPurchase.java +++ b/Week-11-final-start/part-2/ItemToPurchase.java @@ -1,25 +1,23 @@ -/* - * Following Specs: - * Init in default constructor: - * - * String itemName -- init to none - * int itemPrice - init to 0 - * int itemQuanity - init to 0 - * - * Public member mothods (mutators & accessors) - * setPrice() & getPrice() - */ - public class ItemToPurchase { private String itemName; private int itemPrice; private int itemQuantity; + private String itemDescription; public ItemToPurchase() { itemName = "none"; itemPrice = 0; itemQuantity = 0; + itemDescription = "none"; } + public ItemToPurchase(String name, String Desc, int Price, + int Quantity){ + this.itemName = name; + this.itemPrice = Price; + this.itemQuantity = Quantity; + this.itemDescription = Desc; + } + public void setName(String name){ this.itemName = name; } @@ -38,6 +36,16 @@ public class ItemToPurchase { public int getPrice(){ return itemPrice; } + public void setDescription(String Desc){ + this.itemDescription = Desc; + } + public void printItemCost(){ + System.out.println(itemName + " " + itemQuantity + " @ $" + itemPrice + + " = $" + (itemQuantity*itemPrice)); + } + public void printItemDescription(){ + System.out.println(itemName + ": " + itemDescription); + } } diff --git a/Week-11-final-start/part-2/ShoppingCart.java b/Week-11-final-start/part-2/ShoppingCart.java new file mode 100644 index 0000000..213616a --- /dev/null +++ b/Week-11-final-start/part-2/ShoppingCart.java @@ -0,0 +1,59 @@ +import java.util.ArrayList; + +public class ShoppingCart { + private String customerName; + private String currentDate; + private ArrayList cartItems; + + ShoppingCart (){ + customerName = "none"; + currentDate = "January 1, 2016"; + } + ShoppingCart (String name, String date){ + customerName = name; + currentDate = date; + } + + public String getCustomerName(){ + return customerName; + } + + public String getDate(){ + return currentDate; + } + + public void addItem(ItemToPurchase item){ + //add item to cartItems + } + public void removeItem(String itemName){ + //if itemname not found print + //"Item not found in cart. Nothing removed." + } + public void modifyItem(ItemToPurchase item){ + //Modify desc, price, and/or quantity + //If item can be found by name in cart + //check if parameter has default values + //for desc, price, and quantity + //if not, modify item in cart + //if item cannot be found by name, + //"Item not found in cart. Nothing modified." + } + public int getNumItemsInCart(){ + //return number of items in cart + return 0; + } + public int getCostOfCart(){ + //return total cost of items in cart + return 0; + } + public void printTotal(){ + //print total objects in cart + //if empty, print: + //"SHOPPING CART IS EMPTY" + } + public void printDescriptions(){ + //Print out each items description + } + + +} diff --git a/Week-11-final-start/part-2/ShoppingCartManager.java b/Week-11-final-start/part-2/ShoppingCartManager.java new file mode 100644 index 0000000..0a841d1 --- /dev/null +++ b/Week-11-final-start/part-2/ShoppingCartManager.java @@ -0,0 +1,33 @@ +import java.util.Scanner; + +public class ShoppingCartManager { + public static void main(String[] args) { + + //Ask for customer name and today's date + //Output the name and date + //Create a shoppingCart + // + //Implement printMenu(ShoppingCart cart) method + // + Scanner scnr = new Scanner(System.in); + } + + public void printMenu(ShoppingCart cart, Scanner scnr){ + + char userInput; + userInput = 0; + + while (userInput != 'q'){ + System.out.println("Menu\n"+ + "a - Add item to cart\n"+ + "d - Remove item from cart\n"+ + "c - Change item quantity\n"+ + "i - Output items' descriptions\n"+ + "o - Output shopping cart\n"+ + "q - Quit"); + userInput = scnr.next().charAt(0); + + } + } + +} diff --git a/Week-11-final-start/part-2/ShoppingCartPrinter.java b/Week-11-final-start/part-2/ShoppingCartPrinter.java deleted file mode 100644 index 7d8f3d2..0000000 --- a/Week-11-final-start/part-2/ShoppingCartPrinter.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - In main, ask the user for two items and create two objects of the - ItemToPurchase class. - - Before asking for the second item, call scnr.nextLine() - to allow the user to put in a new string. - -Example: -Item 1 -Enter the item name: -Chocolate Chips -Enter the item price: -3 -Enter the item quantity: -1 - -Item 2 -Enter the item name: -Bottled Water -Enter the item price: -1 -Enter the item quantity: -10 - Then add the costs of teh two items together and output - the total cost - -Example: -TOTAL COST -Chocolate Chips 1 @ $3 = $3 -Bottled Water 10 @ $1 = $10 - -Total: $13 -*/ - -import java.util.Scanner; - -public class ShoppingCartPrinter { - public static void main(String[] args) { - Scanner scnr = new Scanner(System.in); - ItemToPurchase item1 = new ItemToPurchase(); - ItemToPurchase item2 = new ItemToPurchase(); - - - System.out.println("Item 1"); - System.out.println("Enter the item name:"); - item1.setName(scnr.nextLine()); - System.out.println("Enter the item price:"); - item1.setPrice(scnr.nextInt()); - System.out.println("Enter the item quantity:"); - item1.setQuantity(scnr.nextInt()); - scnr.nextLine(); - - System.out.println("\nItem 2"); - System.out.println("Enter the item name:"); - item2.setName(scnr.nextLine()); - System.out.println("Enter the item price:"); - item2.setPrice(scnr.nextInt()); - System.out.println("Enter the item quantity:"); - item2.setQuantity(scnr.nextInt()); - - System.out.println("\nTOTAL COST"); - System.out.println(item1.getName() + " " + item1.getQuantity() + - " @ $" + item1.getPrice() + " = $" + - (item1.getPrice() * item1.getQuantity())); - - System.out.println(item2.getName() + " " + item2.getQuantity() + - " @ $" + item2.getPrice() + " = $" + - (item2.getPrice() * item2.getQuantity())); - System.out.println("\nTotal: $" + - ((item2.getPrice() * item2.getQuantity()) + - (item1.getPrice() * item1.getQuantity()))); - } -} -