All pastes #959516 Raw Edit

Stuff

public text v1 · immutable
#959516 ·published 2008-03-27 14:38 UTC
rendered paste body
import java.text.NumberFormat;

public class ShoppingCart
{
	private int itemCount;
	private double totalPrice;
	private int capacity;
	
	public ShoppingCart()
	{
		capacity = 5;
		itemCount =0;
		totalPrice =0.0;
	}
	
	public void addToCart(String itemName, double price, int quantity)
	{
		
	}
	
	public String toString()
	{
		NumberFormat fmt = NumberFormat.getCurrencyInstance();
		
		String contents = "\nShopping Cart\n";
		contents += "\nItem\t\tUnit Price\tQuantity\tTotal\n";
		
		for (int i=0; i < itemCount; i++)
		contents += cart[i].toString()+"\n";
		
		contents += "\nTotal Price: " + fmt.format(totalPrice);
		contents += "\n";
		
		return contents;
	}
	
	private void increaseSize()
	{
		
	}
	
}


import java.text.NumberFormat;

public class Item
{
	private String name;
	private double price;
	private int quantity;
	
	public Item (String itemName, Double itemPrice, int numPurchased)
	{
		name=itemName;
		price=itemPrice;
		quantity=numPurchased;
	}
	
	public String toString()
	{
		NumberFormat fmt = NumberFormat.getCurrencyInstance();
		return ( name + "\t" + fmt.format(price) + "\t" + quantity + "\t" + fmt.format(price*quantity));
	}
	
	public double getPrice()
	{ 
	     return price;
	}
	
	public String getName()
	{
		return name;
	}
	
	public int getQuantity()
	{
		return quantity;
	}
}