96 lines
2.6 KiB
Java
96 lines
2.6 KiB
Java
import java.util.Scanner;
|
|
|
|
public class ShoppingCartManager {
|
|
public static void main(String[] args) {
|
|
Scanner scnr = new Scanner(System.in);
|
|
String custName;
|
|
String curDate;
|
|
|
|
System.out.println("Enter Customer's Name:");
|
|
custName = scnr.nextLine();
|
|
System.out.println("Enter Today's Date:");
|
|
curDate=scnr.nextLine();
|
|
ShoppingCart cart = new ShoppingCart(custName, curDate);
|
|
System.out.println();
|
|
System.out.println("Customer Name: "+custName);
|
|
System.out.println("Today's Date: "+curDate);
|
|
|
|
printMenu(cart, scnr);
|
|
}
|
|
|
|
public static void printMenu(ShoppingCart cart, Scanner scnr){
|
|
|
|
char userInput;
|
|
userInput = 0;
|
|
|
|
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");
|
|
while (userInput != 'q'){
|
|
userInput = scnr.next().charAt(0);
|
|
scnr.nextLine();
|
|
switch (userInput) {
|
|
case 'a': addItem(cart, scnr);
|
|
break;
|
|
case 'd': removeItem(cart, scnr);
|
|
break;
|
|
case 'c': changeItemQuantity(cart, scnr);
|
|
break;
|
|
case 'i': printDesc(cart);
|
|
break;
|
|
case 'o': outputCart(cart);
|
|
break;
|
|
default:
|
|
System.out.println("Choose an option:");
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
public static void addItem(ShoppingCart cart, Scanner scnr){
|
|
ItemToPurchase item = new ItemToPurchase();
|
|
System.out.println("ADD ITEM TO CART");
|
|
System.out.println("Enter the item name:");
|
|
item.setName(scnr.nextLine());
|
|
System.out.println("Enter the item description:");
|
|
item.setDescription(scnr.nextLine());
|
|
System.out.println("Enter the item price:");
|
|
item.setPrice(scnr.nextInt());
|
|
System.out.println("Enter the item quantity");
|
|
item.setQuantity(scnr.nextInt());
|
|
cart.addItem(item);
|
|
}
|
|
|
|
public static void removeItem(ShoppingCart cart, Scanner scnr){
|
|
System.out.println("REMOVE ITEM FROM CART");
|
|
System.out.println("Enter name of item to remove:");
|
|
String user = scnr.nextLine();
|
|
cart.removeItem(user);
|
|
}
|
|
public static void changeItemQuantity(ShoppingCart cart, Scanner scnr){
|
|
ItemToPurchase item = new ItemToPurchase();
|
|
|
|
System.out.println("CHANGE ITEM QUANTITY");
|
|
System.out.println("Enter the item name:");
|
|
item.setName(scnr.nextLine());
|
|
System.out.println("Enter the new quantity:");
|
|
item.setQuantity(scnr.nextInt());
|
|
scnr.nextLine();
|
|
cart.modifyItem(item);
|
|
}
|
|
public static void printDesc(ShoppingCart cart){
|
|
System.out.println("OUTPUT ITEMS' DESCRIPTIONS");
|
|
cart.printDescriptions();
|
|
}
|
|
public static void outputCart(ShoppingCart cart){
|
|
System.out.println("OUTPUT SHOPPING CART");
|
|
cart.printTotal();
|
|
|
|
}
|
|
|
|
}
|