Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Shopping Cart Program

$
0
0
Hi guys, I'm new with java and working on my first project and I got stuck with this ShoppingCart Class.
Here is my ShoppingCart class and my question is when I add an ItemOrder which contains name of items, prices(hard coded) and quantity (input from user) to an ItemOrderList(quantity, name, price), how do I deal with replacing any old order for the item.
For example: A user at one time might request 3 of some item and later change the request to 5 of that item. The order for 5 replaces the order for 3.

Any help would be appreciated.
import java.util.ArrayList;
public class ShoppingCart {
	int total=0;
	ItemOrder itemOrder;
	
	ArrayList<ItemOrder>ItemOrderList;
	
	ShoppingCart()
	{
		ItemOrderList = new ArrayList<ItemOrder>(); 
	}
	
	public void add(ItemOrder itemOrder)
	{
		ItemOrderList.add(itemOrder);//the ItemOrderList's size keep increasing 
		
		//how to deal with replacing any old order for the item. The order for 5 replaces the order for 3
		
		
	}
	
	public void setDiscount(boolean discount)
	{
		if(discount == true)
			System.out.println("Qualify for discount");
		else
			System.out.println("No discount");
	}
	public int getTotal()
	{
		for(int i=0; i<ItemOrderList.size(); i++)
		{
		total+=ItemOrderList.get(i).getPrice();
		}
		return total;
		
	}

} 



Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>