//package zyLabsUnitTest;

import java.util.ArrayList;
import java.util.List;


public class ShoppingCart {

private String customerName;

private String currentDate;

private List<ItemToPurchase> cartItems = new ArrayList<>();
public ShoppingCart(){
customerName = "none";
currentDate = "January 1, 2016";
}


public ShoppingCart(String n, String d){
customerName = n;
currentDate = d;
}


public void printDescriptions(){
System.out.println(customerName+"'s Shopping Cart - "+currentDate);
System.out.println();
System.out.println("Item Descriptions:");
for(int i = 0; i < cartItems.size(); i++){
System.out.println(cartItems.get(i).getName()+": "+(cartItems.get(i).getDescription()));
}
}

public void printTotal(){
System.out.println(customerName+"'s Shopping Cart - "+currentDate);
System.out.println("Number of Items: "+this.getNumItemsInCart());
System.out.println();
int total = 0;
if (cartItems.size() == 0){
System.out.println("SHOPPING CART IS EMPTY");
System.out.println();
System.out.println("Total: $0");

}
else
{
for(int i = 0; i < cartItems.size(); i++){
//System.out.println("banana");
cartItems.get(i).printItemCost();
total += cartItems.get(i).getTotalPrice();

}
System.out.println();
System.out.println("Total: $"+total);

}
}

public int getCostOfCart(){

int total = 0;

for(int i = 0; i < cartItems.size(); i++){
total += cartItems.get(i).getTotalPrice();
}
return total;

}


public int getNumItemsInCart(){
int total = 0;

for(int i = 0; i < cartItems.size(); i++){
total += cartItems.get(i).getQuantity();
}

return total;
}

public void modifyItem(ItemToPurchase z){
boolean done = false;

int item2Change = 0;
for (int i = 0; i < cartItems.size() || done; i++){
if (z.getName().equals(cartItems.get(i).getName())){
done = true;
}
}
if(!done){
System.out.println("Item not found in cart. Nothing modified.)");
}
}


public void removeItem(String n){
boolean done = false;
int itemForRemoval = 0;
for (int i = 0; i < cartItems.size() && !done; i++){
//System.out.println(cartItems.get(i).getName()+"="+n);
if (cartItems.get(i).getName().equals(n)){
//System.out.println("got it!");
done = true;
itemForRemoval = i;
}
}
if (done){
cartItems.remove(itemForRemoval);
}else{
System.out.println("Item not found in cart. Nothing removed.");
}
}
public void addItem(ItemToPurchase z){
cartItems.add(z);
}


public String getDate(){
return currentDate;
}

public String getCustomerName(){
return customerName;
}


}
Enjoy the site? All donations are appreciated

Free Text Host is brought to you by Dagon Design
This site contains no adware, spyware, or popups
Questions? Comments?     Privacy Policy     Report abuse here