continue
This commit is contained in:
parent
d56fd05c3d
commit
7a238a93ef
@ -3,7 +3,7 @@ import java.util.ArrayList;
|
||||
public class ShoppingCart {
|
||||
private String customerName;
|
||||
private String currentDate;
|
||||
private ArrayList cartItems;
|
||||
private ArrayList<ItemToPurchase> cartItems;
|
||||
|
||||
ShoppingCart (){
|
||||
customerName = "none";
|
||||
@ -22,12 +22,21 @@ public class ShoppingCart {
|
||||
return currentDate;
|
||||
}
|
||||
|
||||
private void printNameDate (){
|
||||
System.out.println(customerName + " Shopping Cart - "+ currentDate);
|
||||
}
|
||||
|
||||
public void addItem(ItemToPurchase item){
|
||||
//add item to cartItems
|
||||
cartItems.add(item);
|
||||
}
|
||||
public void removeItem(String itemName){
|
||||
//if itemname not found print
|
||||
//"Item not found in cart. Nothing removed."
|
||||
for (int i=0; i<cartItems.size(); i++){
|
||||
if (cartItems.get(i).getName() == itemName){
|
||||
cartItems.remove(i);
|
||||
return;
|
||||
}
|
||||
}
|
||||
System.out.println("Item not found in cart. Nothing removed.");
|
||||
}
|
||||
public void modifyItem(ItemToPurchase item){
|
||||
//Modify desc, price, and/or quantity
|
||||
@ -39,21 +48,40 @@ public class ShoppingCart {
|
||||
//"Item not found in cart. Nothing modified."
|
||||
}
|
||||
public int getNumItemsInCart(){
|
||||
//return number of items in cart
|
||||
return 0;
|
||||
return cartItems.size();
|
||||
}
|
||||
public int getCostOfCart(){
|
||||
//return total cost of items in cart
|
||||
return 0;
|
||||
int runningTotal = 0;
|
||||
for (int i=0; i<cartItems.size(); i++){
|
||||
runningTotal += cartItems.get(i).getPrice();
|
||||
}
|
||||
return runningTotal;
|
||||
}
|
||||
|
||||
public void printTotal(){
|
||||
//print total objects in cart
|
||||
//if empty, print:
|
||||
//"SHOPPING CART IS EMPTY"
|
||||
if (cartItems.size() == 0){
|
||||
System.out.println("SHOPPING CART IS EMPTY");
|
||||
return;
|
||||
}
|
||||
printNameDate();
|
||||
System.out.println("Number of Items: " + cartItems.size());
|
||||
System.out.println();
|
||||
|
||||
for (int i=0; i<cartItems.size(); i++){
|
||||
System.out.println(cartItems.get(i).getName() + " " +
|
||||
cartItems.get(i).getQuantity() + " @ $"+
|
||||
cartItems.get(i).getPrice() + " = $" +
|
||||
(cartItems.get(i).getPrice() *
|
||||
cartItems.get(i).getQuantity()));
|
||||
}
|
||||
System.out.println("\nTotal: " + getCostOfCart());
|
||||
}
|
||||
public void printDescriptions(){
|
||||
//Print out each items description
|
||||
printNameDate();
|
||||
System.out.println("\n Item Descriptions");
|
||||
|
||||
for (int i=0; i<cartItems.size(); i++){
|
||||
cartItems.get(i).printItemDescription();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -10,6 +10,9 @@ public class ShoppingCartManager {
|
||||
//Implement printMenu(ShoppingCart cart) method
|
||||
//
|
||||
Scanner scnr = new Scanner(System.in);
|
||||
ShoppingCart cart = new ShoppingCart();
|
||||
printMenu(cart, scnr);
|
||||
|
||||
}
|
||||
|
||||
public void printMenu(ShoppingCart cart, Scanner scnr){
|
||||
@ -18,7 +21,7 @@ public class ShoppingCartManager {
|
||||
userInput = 0;
|
||||
|
||||
while (userInput != 'q'){
|
||||
System.out.println("Menu\n"+
|
||||
System.out.println("MENU\n"+
|
||||
"a - Add item to cart\n"+
|
||||
"d - Remove item from cart\n"+
|
||||
"c - Change item quantity\n"+
|
||||
@ -27,7 +30,24 @@ public class ShoppingCartManager {
|
||||
"q - Quit");
|
||||
userInput = scnr.next().charAt(0);
|
||||
|
||||
switch (userInput) {
|
||||
case 'a': break;
|
||||
case 'd': break;
|
||||
case 'c': break;
|
||||
case 'i': cart.printDescriptions();
|
||||
break;
|
||||
case 'o': break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void addItem(){
|
||||
}
|
||||
public void removeItem(){
|
||||
}
|
||||
public void changeItemQuantity(){
|
||||
}
|
||||
public void outputCart(){
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user