Question: In Java. I cannot get the total to output. This program extends the earlier Online shopping cart program. ( Consider first saving your earlier program
In Java. I cannot get the total to output.
This program extends the earlier "Online shopping cart" program. Consider first saving your earlier program
Extend the ItemToPurchase class per the following specifications:
Private fields
string itemDescription Initialized in default constructor to "none"
Parameterized constructor to assign item name, item description, item price, and item quantity default values of pt
Public member methods
setDescription mutator & getDescription accessor pts
printItemCost Outputs the item name followed by the quantity, price, and subtotal
printItemDescription Outputs the item name and description
Ex of printItemCost output:
Bottled Water @ $ $
Ex of printItemDescription output:
Bottled Water: Deer Park, oz
Create two new files pts:
ShoppingCart.java Class definition
ShoppingCartManager.java Contains main method
Build the ShoppingCart class with the following specifications. Note: Some can be method stubs empty methods initially, to be completed in later steps.
Private fields pts
String customerName Initialized in default constructor to "none"
String currentDate Initialized in default constructor to "January
ArrayList cartItems
Default constructor
Parameterized constructor which takes the customer name and date as parameters pts
Public member methods
getCustomerName accessor pt
getDate accessor pt
addItem
Adds an item to cartItems array. Has parameter ItemToPurchase. Does not return anything.
removeItem
Removes item from cartItems array. Has a string an item's name parameter. Does not return anything.
If item name cannot be found, output this message: Item not found in cart. Nothing removed.
modifyItem pts
Modifies an item's description, price, andor quantity. Has parameter ItemToPurchase. Does not return anything.
If item can be found by name in cart, check if parameter has default values for description, price, and quantity. If not, modify item in cart.
If item cannot be found by name in cart, output this message: Item not found in cart. Nothing modified.
getNumItemsInCart pts
Returns quantity of all items in cart. Has no parameters.
getCostOfCart pts
Determines and returns the total cost of items in cart. Has no parameters.
printTotal
Outputs total of objects in cart.
If cart is empty, output this message: SHOPPING CART IS EMPTY
printDescriptions
Outputs each item's description.
Ex of printTotal output: John Doe's Shopping Cart February
Number of Items:
Nike Romaleos @ $ $
Chocolate Chips @ $ $
Powerbeats Headphones @ $ $
Total: $
MY CODE SO FAR:
package onlineShoppingCart;
import java.util.Scanner;
public class ItemToPurchase
Private fields
private String itemName;
private String itemDescription;
private int itemPrice;
private int itemQuantity;
Default constructor
public ItemToPurchase
this.itemName "none";
this.itemDescription "none";
this.itemQuantity ;
this.itemPrice ;
Parameterized constructor to assign name, description, price, and quantity
public ItemToPurchaseString itemName, String itemDescription, int itemPrice, int itemQuantity
this.itemName itemName;
this.itemDescription itemDescription;
this.itemPrice itemPrice;
this.itemQuantity itemQuantity;
Public member methods
public String getItemDescription
return itemDescription;
public void setItemDescriptionString itemDescription
this.itemDescription itemDescription;
public void printItemCost
System.out.printlnitemName itemQuantity @ $ itemPrice $itemQuantity itemPrice;
public void printItemDescription
System.out.printlnitemName : itemDescription;
public String getName
return itemName;
public void setNameString itemName
this.itemName itemName;
public int getPrice
return itemPrice;
public void setPriceint itemPrice
this.itemPrice itemPrice;
public int getQuantity
return itemQuantity;
public void setQuantityint itemQuantity
this.itemQuantity itemQuantity;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
