Name Price Quantity: Import Public Class Private Private Double Private Int
Name Price Quantity: Import Public Class Private Private Double Private Int
//
//
//
//
***********************************************************
Item.java
Represents an item in a shopping cart.
***********************************************************
import java.text.NumberFormat;
public class Item
{
private String name;
private double price;
private int quantity;
// ------------------------------------------------------// Create a new item with the given attributes.
// ------------------------------------------------------public Item (String itemName, double itemPrice, int numPurchased)
{
name = itemName;
price = itemPrice;
quantity = numPurchased;
}
// ------------------------------------------------------// Return a string with the information about the item.
// ------------------------------------------------------public String toString()
{
NumberFormat fmt = NumberFormat.getCurrencyInstance();
//
//
//
//
//
***********************************************************
ShoppingCart.java
Represents a shopping cart as an array of items.
***********************************************************
//import Item
import java.text.NumberFormat;
public class ShoppingCart
{
private int itemCount;
private double totalPrice;
private int capacity;
return contents;
cart = temp;
// ***********************************************************
// ShoppingDriver.java
//
// Simulate a shopping experience by continuing to shop as long
// as the user wants to. Read in the name, price, and quantity
// of the item the user wants to add to the cart. After the
// item is added to the cart, the cart contents should be printed.
// When the user is finished shopping print a "Please pay ..."
// message with the total price of the items in the cart.
// ***********************************************************
import java.text.NumberFormat;
import java.util.Scanner;
String tmpName;
double tmpPrice, myCartTotal = 0.0;
int tmpQuantity;
while (keepShopping.equalsIgnoreCase("Y"))
{
// obtain information about item purchased
System.out.println("Please enter the name of the item you wish to purchase:
");
tmpName = scan.next();
System.out.println("Please enter the price of the item: ");
tmpPrice = scan.nextDouble();
System.out.println("Please enter the quantity purchased: ");
tmpQuantity = scan.nextInt();