Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

ItemToPurchase.java:- package main; enum ItemTaxCategory { N, X , T ; } public class ItemToPurchase { private String itemName; private int itemPrice; private int itemQuantity;

ItemToPurchase.java:-

package main;

enum ItemTaxCategory {

N,

X,

T;

}

public class ItemToPurchase {

private String itemName;

private int itemPrice;

private int itemQuantity;

private String itemDiscription;

private ItemTaxCategory category;

public ItemToPurchase(){

this.itemName = "none";

this.itemPrice = 0;

this.itemQuantity = 0;

this.itemDiscription="";

this.category = ItemTaxCategory.N;

}

public String getName() {

return itemName;

}

public void setName(String itemName) {

this.itemName = itemName;

}

public int getPrice() {

return itemPrice;

}

public void setPrice(int itemPrice) {

this.itemPrice = itemPrice;

}

public int getQuantity() {

return itemQuantity;

}

public void setQuantity(int itemQuantity) {

this.itemQuantity = itemQuantity;

}

public ItemTaxCategory getTaxCategory() {

return category;

}

public void setTaxCategory(ItemTaxCategory category) {

this.category = category;

}

public double itemTotalPrice() {

return getQuantity() * getPrice();

}

public double totalTax() {

double tax;

if(category == ItemTaxCategory.X) {

tax = 0.08 * getPrice();

}else if(category == ItemTaxCategory.T) {

tax = 0.10 * getPrice();

}else {

tax = 0;

}

return tax;

}

}

ShoppingCart.java:-

package main;

import java.util.ArrayList;

public class ShoppingCart extends ItemToPurchase {

//Private Data Members private String customerName; private String currentDate;

public ShoppingCart () { // The default Constructor customerName = "none"; currentDate = "January 1, 2020"; }

//ArrayList cartItems ArrayList cartItems = new ArrayList();;

/* * parameterized constructor which takes the customer name and date as parameters */ public ShoppingCart (String CustomerName, String CurrentDate, int x, int y) { this.currentDate = CurrentDate; this.customerName = CustomerName; }

//Public member methods public String getCustomerName() { // accessor return customerName; }

public void setCustomerName(String customerName) { this.customerName = customerName; }

public String getDate() { //accessor return currentDate; } public void setCurrentDate(String currentDate) { this.currentDate = currentDate; } /* * This method adds an item to the cartItems array. It also has a parameter ItemToPurchase. It does not return anything. */ public void addItem( ItemToPurchase i) { cartItems.add(i); } /* * This method removes item from the cartItems array. It has a string (an item's name) parameter. It does not return anything. */

public void removeItem(String name) { boolean found = false;; for(ItemToPurchase i: cartItems){ if(i.getName().equalsIgnoreCase(name)) { cartItems.remove(i); found = true; break; } }

if(!found) //If an item name cannot be found System.out.println("Item not found in cart. Nothing removed"); }

/* * This method returns quantity of all items in cart. It has no parameters. */

public int getNumItemsInCart() { int sum = 0; for(ItemToPurchase i: cartItems){ sum = sum + i.getQuantity(); } return sum; }

/* * This method determines and returns the total cost of items in cart. It has no parameters. */

public double getCostOfCart() { int sum = 0; for(ItemToPurchase i: cartItems){ sum = sum + i.getPrice();

} return sum;

}

public void printTotal(){ // This method outputs total of objects in the cart.

if(cartItems != null && cartItems.size() > 0){ System.out.println(customerName + "'s Shopping Cart - " + currentDate); System.out.println("Number of Items: " + cartItems.size()); System.out.println();

}

else{ System.out.println("SHOPPING CART IS EMPTY");

}

}

public void printDescriptions() { // This method outputs each item's description.

System.out.println(customerName+"'s Shopping Cart - "+currentDate); System.out.println("Number of Items: " + cartItems.size()); System.out.println(); System.out.println("Item Descriptions");

}

} ShoppingCartManager.java:-

package main;

import java.util.Scanner;

public class ShoppingCartManager {

public static void main(String[] args){ // Prompts the user for customer's name and today's date 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 currentDate = scan.nextLine(); ShoppingCart y = new ShoppingCart(); ShoppingCart x = new ShoppingCart(customerName, currentDate,0,0); System.out.println(); // Prints the name and date System.out.println("Customer Name: " + x.getCustomerName()); System.out.println("Today's Date: " + currentDate); printMenu(x); }

public static void printMenu(ShoppingCart x){ // This method prints the menu

while(true){ System.out.println("MENU"); System.out.println("a - Add item to cart"); System.out.println("b - Remove item from cart"); System.out.println("c - Change item quantity"); System.out.println("d - Apply Coupon Code "); // So you have to created Else if statement below for applying coupon code System.out.println("i - Output items' descriptions"); System.out.println("o - Output shopping cart"); System.out.println("q - Quit Choose an option: "); Scanner scanner = new Scanner(System.in); // The User chooses an option

char input = scanner.next().charAt(0); scanner.nextLine();

// Adding an item to the cart if(input == 'a'){ System.out.println("ADD ITEM TO CART"); System.out.println("Enter Item Name: "); String itemName = scanner.nextLine(); System.out.println("Enter Item Description: "); String itemDescritpion = scanner.nextLine(); System.out.println("Enter Item Price: "); int itemPrice = scanner.nextInt(); System.out.println("Enter Item Quantity: "); int itemQuantity = scanner.nextInt(); scanner.nextLine(); ItemToPurchase item = new ItemToPurchase(); x.addItem(item);

}

// Printing items' descriptions else if(input == 'i'){ System.out.println("OUTPUT ITEMS' DESCRIPTIONS"); x.printDescriptions(); }

// printing the shopping cart else if(input == 'o'){ System.out.println("OUTPUT SHOPPING CART"); x.printTotal(); x.getCostOfCart(); }

// Quit else if(input == 'q'){ break; }

}

}

}

I want output Of i and o as shown in Screenshot:-

image text in transcribed

new (1) - Protected View - Saved to this PC - Search Mailings Review View Help viruses. Unless you need to edit, it's safer to stay in Protected View. Enable Editing 5. Implement Output shopping cart menu option Output Example: OUTPUT SHOPPING CART John Doe's Shopping Cart - February 1, 2020 Number of Items : 8 Nike Romaleos 2 @ $189 = $378 Chocolate Chips 5 @ $3 = $15 Powerbeats 2 Headphones 1 @ $128 = $128 Discount (300FF): --$30 Total: $491 6. Implement Output item's description menu option. Output Example: OUTPUT ITEMS' DESCRIPTIONS John Doe's Shopping Cart - February 1, 2020 Item Descriptions Nike Romaleos: Volt color, Weightlifting shoes Chocolate Chips: Semi-sweet Powerbeats 2 Headphones: Bluetooth headphones 7. Implement Add item to cart menu option

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems On GPUs In Databases

Authors: Johns Paul ,Shengliang Lu ,Bingsheng He

1st Edition

1680838482, 978-1680838480

More Books

Students also viewed these Databases questions