continue
This commit is contained in:
parent
d56fd05c3d
commit
7a238a93ef
@ -3,7 +3,7 @@ import java.util.ArrayList;
|
|||||||
public class ShoppingCart {
|
public class ShoppingCart {
|
||||||
private String customerName;
|
private String customerName;
|
||||||
private String currentDate;
|
private String currentDate;
|
||||||
private ArrayList cartItems;
|
private ArrayList<ItemToPurchase> cartItems;
|
||||||
|
|
||||||
ShoppingCart (){
|
ShoppingCart (){
|
||||||
customerName = "none";
|
customerName = "none";
|
||||||
@ -22,12 +22,21 @@ public class ShoppingCart {
|
|||||||
return currentDate;
|
return currentDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void printNameDate (){
|
||||||
|
System.out.println(customerName + " Shopping Cart - "+ currentDate);
|
||||||
|
}
|
||||||
|
|
||||||
public void addItem(ItemToPurchase item){
|
public void addItem(ItemToPurchase item){
|
||||||
//add item to cartItems
|
cartItems.add(item);
|
||||||
}
|
}
|
||||||
public void removeItem(String itemName){
|
public void removeItem(String itemName){
|
||||||
//if itemname not found print
|
for (int i=0; i<cartItems.size(); i++){
|
||||||
//"Item not found in cart. Nothing removed."
|
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){
|
public void modifyItem(ItemToPurchase item){
|
||||||
//Modify desc, price, and/or quantity
|
//Modify desc, price, and/or quantity
|
||||||
@ -39,21 +48,40 @@ public class ShoppingCart {
|
|||||||
//"Item not found in cart. Nothing modified."
|
//"Item not found in cart. Nothing modified."
|
||||||
}
|
}
|
||||||
public int getNumItemsInCart(){
|
public int getNumItemsInCart(){
|
||||||
//return number of items in cart
|
return cartItems.size();
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
public int getCostOfCart(){
|
public int getCostOfCart(){
|
||||||
//return total cost of items in cart
|
int runningTotal = 0;
|
||||||
return 0;
|
for (int i=0; i<cartItems.size(); i++){
|
||||||
|
runningTotal += cartItems.get(i).getPrice();
|
||||||
|
}
|
||||||
|
return runningTotal;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void printTotal(){
|
public void printTotal(){
|
||||||
//print total objects in cart
|
if (cartItems.size() == 0){
|
||||||
//if empty, print:
|
System.out.println("SHOPPING CART IS EMPTY");
|
||||||
//"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(){
|
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
|
//Implement printMenu(ShoppingCart cart) method
|
||||||
//
|
//
|
||||||
Scanner scnr = new Scanner(System.in);
|
Scanner scnr = new Scanner(System.in);
|
||||||
|
ShoppingCart cart = new ShoppingCart();
|
||||||
|
printMenu(cart, scnr);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void printMenu(ShoppingCart cart, Scanner scnr){
|
public void printMenu(ShoppingCart cart, Scanner scnr){
|
||||||
@ -18,7 +21,7 @@ public class ShoppingCartManager {
|
|||||||
userInput = 0;
|
userInput = 0;
|
||||||
|
|
||||||
while (userInput != 'q'){
|
while (userInput != 'q'){
|
||||||
System.out.println("Menu\n"+
|
System.out.println("MENU\n"+
|
||||||
"a - Add item to cart\n"+
|
"a - Add item to cart\n"+
|
||||||
"d - Remove item from cart\n"+
|
"d - Remove item from cart\n"+
|
||||||
"c - Change item quantity\n"+
|
"c - Change item quantity\n"+
|
||||||
@ -27,7 +30,24 @@ public class ShoppingCartManager {
|
|||||||
"q - Quit");
|
"q - Quit");
|
||||||
userInput = scnr.next().charAt(0);
|
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