/*********************************ItemToPurchase.java*****************************/
package cart;
public class ItemToPurchase {
protected String itemName;
protected int itemPrice;
protected int itemQuantity;
protected String itemDescription;
public ItemToPurchase() {
this.itemName = "none";
this.itemPrice = 0;
this.itemQuantity = 0;
this.itemDescription =
"none";
}
public ItemToPurchase(String itemName, String
itemDescription, int itemPrice, int itemQuantity) {
this.itemName = itemName;
this.itemPrice = itemPrice;
this.itemQuantity =
itemQuantity;
this.itemDescription =
itemDescription;
}
public void setName(String itemName) {
this.itemName = itemName;
}
public void setPrice(int itemPrice) {
this.itemPrice = itemPrice;
}
public void setQuantity(int itemQuantity) {
this.itemQuantity =
itemQuantity;
}
public void setDescription(String itemDescription)
{
this.itemDescription =
itemDescription;
}
public String getName() {
return itemName;
}
public int getPrice() {
return itemPrice;
}
public int getQuantity() {
return itemQuantity;
}
public String getDescription() {
return itemDescription;
}
public String printItemCost() {
String cost = ("\n" + itemName + "
" + itemQuantity + " @ $" + itemPrice + " = $" + (itemQuantity *
itemPrice));
return cost;
}
public String printItemDescription() {
String description = (itemName + ":
" + itemDescription);
return description;
}
}
/*************************************ShoppingCart.java***************************/
package cart;
import java.util.ArrayList;
import java.util.Iterator;
public class ShoppingCart {
private String customerName;
private String currentDate;
private ArrayList<ItemToPurchase> cartItems;
public ShoppingCart() {
this.customerName = "";
this.currentDate = "January 1,
2016";
this.cartItems = new
ArrayList<>();
}
public ShoppingCart(String customerName, String
currentDate) {
super();
this.customerName =
customerName;
this.currentDate =
currentDate;
this.cartItems = new
ArrayList<>();
}
public String getCustomerName() {
return customerName;
}
public void setCustomerName(String customerName)
{
this.customerName =
customerName;
}
public String getCurrentDate() {
return currentDate;
}
public void setCurrentDate(String currentDate)
{
this.currentDate =
currentDate;
}
public ArrayList<ItemToPurchase>
getCartItems() {
return cartItems;
}
public void
setCartItems(ArrayList<ItemToPurchase> cartItems) {
this.cartItems = cartItems;
}
public void addItem(ItemToPurchase item) {
cartItems.add(item);
}
public void removeItem(String itemName) {
int flag = 0;
Iterator<ItemToPurchase> itr
= cartItems.iterator();
while (itr.hasNext()) {
ItemToPurchase
item = itr.next();
if (item.getName().equalsIgnoreCase(itemName)) {
itr.remove();
flag = 1;
}
}
if (flag == 0) {
System.out.println("Item not found in the cart. Nothing
found");
}
}
public void modifyItem(String itemName, int quantity) {
int flag = 0;
ItemToPurchase item = null;
for (ItemToPurchase itemToPurchase
: cartItems) {
if (itemToPurchase.getName().equalsIgnoreCase(itemName)) {
flag = 1;
item = itemToPurchase;
}
}
if (flag == 1) {
item.setQuantity(quantity);
} else {
System.out.println("Item not found in cart. Nothing
modified.");
}
}
public int getNumItemsInCart() {
return cartItems.size();
}
public int getCostOfCart() {
int totalCost = 0;
for (ItemToPurchase itemToPurchase
: cartItems) {
totalCost +=
itemToPurchase.getPrice();
}
return totalCost;
}
public void printTotal() {
for (ItemToPurchase itemToPurchase
: cartItems) {
System.out.println(itemToPurchase.printItemDescription());
}
}
public void printDescription() {
System.out.println(customerName
+ "'s Shopping cart - " + currentDate);
System.out.println("Number of
items: " + getNumItemsInCart());
for (ItemToPurchase itemToPurchase : cartItems) {
System.out.println(itemToPurchase.printItemCost());
}
}
}
/**************************************ShoppingCartManager.java*********************/
package cart;
import java.util.Scanner;
public class ShoppingCartManager {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println("Enter
Customer's Name: ");
String customerName =
scan.nextLine();
System.out.println("Enter
today's Date: ");
String date = scan.nextLine();
ShoppingCart cart = new
ShoppingCart(customerName, date);
char option = ' ';
do {
printMenu();
option =
scan.nextLine().toLowerCase().charAt(0);
switch
(option) {
case 'a':
System.out.println("Add ITEM TO CART");
System.out.println("Enter the item name:
");
String itemName = scan.nextLine();
System.out.println("Enter the item description:
");
String itemDesc = scan.nextLine();
System.out.println("Enter the item price:
");
int itemPrice = scan.nextInt();
scan.nextLine();
System.out.println("Enter the item quantity:
");
int quantity = scan.nextInt();
scan.nextLine();
cart.addItem(new ItemToPurchase(itemName,
itemDesc, itemPrice, quantity));
break;
case 'd':
System.out.println("REMOVE ITEM FROM
CART");
System.out.println("Enter name of item to
remove: ");
String name = scan.nextLine();
cart.removeItem(name);
break;
case 'c':
System.out.println("CHANGE ITEM
QUANTITY");
System.out.println("Enter the item name:
");
name = scan.nextLine();
System.out.println("Enter the new quantity:
");
quantity = scan.nextInt();
scan.nextLine();
cart.modifyItem(name, quantity);
break;
case 'i':
cart.printTotal();
break;
case 'o':
cart.printDescription();
break;
case 'q':
System.out.println("Thank you, Bye!");
break;
default:
System.out.println("Invalid Choice! try
againg..");
break;
}
} while (option != 'q');
}
public static void printMenu() {
System.out.println("Menu\n" + "a
- Add item to cart\n" + "d - Remove item from cart\n"
+ "c - Change item Quantity\n" + "i - Output
item's descriptions\n" + "o - Output shopping cart\n"
+ "q - Quit\n" + "\n" + "Choose an option:
");
}
}
/************************output********************/
Enter Customer's Name:
John Doe
Enter today's Date:
February 1, 2016
Menu
a - Add item to cart
d - Remove item from cart
c - Change item Quantity
i - Output item's descriptions
o - Output shopping cart
q - Quit
Choose an option:
a
Add ITEM TO CART
Enter the item name:
Nike Romaleos
Enter the item description:
Volt Color, Weightlifting Shoes
Enter the item price:
189
Enter the item quantity:
2
Menu
a - Add item to cart
d - Remove item from cart
c - Change item Quantity
i - Output item's descriptions
o - Output shopping cart
q - Quit
Choose an option:
i
Nike Romaleos: Volt Color, Weightlifting Shoes
Menu
a - Add item to cart
d - Remove item from cart
c - Change item Quantity
i - Output item's descriptions
o - Output shopping cart
q - Quit
Choose an option:
o
John Doe's Shopping cart - February 1, 2016
Number of items: 1
Nike Romaleos 2 @ $189 = $378
Menu
a - Add item to cart
d - Remove item from cart
c - Change item Quantity
i - Output item's descriptions
o - Output shopping cart
q - Quit
Choose an option:
c
CHANGE ITEM QUANTITY
Enter the item name:
Nike Romaleos
Enter the new quantity:
4
Menu
a - Add item to cart
d - Remove item from cart
c - Change item Quantity
i - Output item's descriptions
o - Output shopping cart
q - Quit
Choose an option:
o
John Doe's Shopping cart - February 1, 2016
Number of items: 1
Nike Romaleos 4 @ $189 = $756
Menu
a - Add item to cart
d - Remove item from cart
c - Change item Quantity
i - Output item's descriptions
o - Output shopping cart
q - Quit
Choose an option:
q
Thank you, Bye!
Please let me know if you have any doubt or modify the answer, Thanks :)
Need three seperate files. ShoppingCartManager.java ShoppingCart.java ItemsToPurchase.java These are from part 1 what do you mean...
Ch 7 Program: Online shopping cart (continued) (Java)This program extends the earlier "Online shopping cart" program. (Consider first saving your earlier program).(1) Extend the ItemToPurchase class per the following specifications:Private fieldsstring itemDescription - Initialized in default constructor to "none"Parameterized constructor to assign item name, item description, item price, and item quantity (default values of 0). (1 pt)Public member methodssetDescription() mutator & getDescription() accessor (2 pts)printItemCost() - Outputs the item name followed by the quantity, price, and subtotalprintItemDescription() - Outputs the...
4.18 Ch 7 Program: Online shopping cart (continued) (C++) This program extends the earlier "Online shopping cart" program. (solution from previous lab assignment is provided in Canvas). (1) Extend the ItemToPurchase class per the following specifications: Parameterized constructor to assign item name, item description, item price, and item quantity (default values of 0). (1 pt) Public member functions SetDescription() mutator & GetDescription() accessor (2 pts) PrintItemCost() - Outputs the item name followed by the quantity, price, and subtotal PrintItemDescription() -...
I need help with this assignment, can someone HELP ? This is the assignment: Online shopping cart (continued) (C++) This program extends the earlier "Online shopping cart" program. (Consider first saving your earlier program). (1) Extend the ItemToPurchase class per the following specifications: Parameterized constructor to assign item name, item description, item price, and item quantity (default values of 0). (1 pt) Public member functions SetDescription() mutator & GetDescription() accessor (2 pts) PrintItemCost() - Outputs the item name followed by...
CODES: main.cpp #include <iostream> #include <string> #include "ShoppingCart.h" using namespace std; char PrintMenu() { char answer; cout << "MENU" << endl; cout << "a - Add item to cart" << endl; cout << "d - Remove item from cart" << endl; cout << "c - Change item quantity" << endl; cout << "i - Output items' descriptions" << endl; cout << "o - Output shopping cart" << endl; cout << "q - Quit" << endl << endl; while (true) {...
Online shopping cart (continued) (Java) Hello, I need help with Java to figure this out. In my Shopping Cart Manager Class (Bottom Code), I get "Resource leak: 'sc' is never closed." I have tried multiple things and cannot figure it out. Thank you. Online shopping cart (continued) (Java) Hello, I need help with Java to figure this out. In my Shopping Cart Manager Class (Bottom Code), I get "Resource leak: 'sc' is never closed." I have tried multiple things and...
8.6 LAB*: Warm up: Online shopping cart (Part 1)(1) Create two files to submit:ItemToPurchase.java - Class definitionShoppingCartPrinter.java - Contains main() methodBuild the ItemToPurchase class with the following specifications:Private fieldsString itemName - Initialized in default constructor to "none"int itemPrice - Initialized in default constructor to 0int itemQuantity - Initialized in default constructor to 0Default constructorPublic member methods (mutators & accessors)setName() & getName() (2 pts)setPrice() & getPrice() (2 pts)setQuantity() & getQuantity() (2 pts)(2) In main(), prompt the user for two items and create...
8.7 LAB*: Program: Online shopping cart (Part 2)Note: Creating multiple Scanner objects for the same input stream yields unexpected behavior. Thus, good practice is to use a single Scanner object for reading input from System.in. That Scanner object can be passed as an argument to any methods that read input.This program extends the earlier "Online shopping cart" program. (Consider first saving your earlier program).(1) Extend the ItemToPurchase class per the following specifications:Private fieldsstring itemDescription - Initialized in default constructor to "none"Parameterized...
Can someone please help me with this Python code? Thank you in advance, Zybooks keeps giving me errors. Thanks in advance!! This program extends the earlier "Online shopping cart" program. (Consider first saving your earlier program). (1) Extend the ItemToPurchase class to contain a new attribute. (2 pts) item_description (string) - Set to "none" in default constructor Implement the following method for the ItemToPurchase class. print_item_description() - Prints item_description attribute for an ItemToPurchase object. Has an ItemToPurchase parameter. Ex. of...
Zybooks 11.12 LAB*: Program: Online shopping cart (continued) Python 3 is the code needed and this is in Zybooks Existing Code # Type code for classes here class ItemToPurchase: def __init__(self, item_name="none", item_price=0, item_quantity=0): self.item_name = item_name self.item_price = item_price self.item_quantity = item_quantity # def __mul__(self): # print_item_cost = (self.item_quantity * self.item_price) # return '{} {} @ ${} = ${}' .format(self_item_name, self.item_quantity, self.item_price, print_item_cost) def print_item_cost(self): self.print_cost = (self.item_quantity * self.item_price) print(('{} {} @ ${} = ${}') .format(self.item_name, self.item_quantity, self.item_price,...
11.12 LAB*: Program: Online shopping cart (continued)This program extends the earlier "Online shopping cart" program. (Consider first saving your earlier program).(1) Extend the ItemToPurchase class to contain a new attribute. (2 pts)item_description (string) - Set to "none" in default constructorImplement the following method for the ItemToPurchase class.print_item_description() - Prints item_description attribute for an ItemToPurchase object. Has an ItemToPurchase parameter.Ex. of print_item_description() output:Bottled Water: Deer Park, 12 oz.(2) Build the ShoppingCart class with the following data attributes and related methods. Note: Some can be method stubs...