1 Create two files ItemToPurchasejava Class definition Shop
(1) Create two files:
ItemToPurchase.java - Class definition
ShoppingCartPrinter.java - Contains main() method
*NOTE* this is in Java. Please do not use floats or \"printf\".
Build the ItemToPurchase class with the following specifications:
Private fields
String itemName - Initialized in default constructor to \"none\"
int itemPrice - Initialized in default constructor to 0
int itemQuantity - Initialized in default constructor to 0
Default constructor
Public member methods (mutators & accessors)
setName() & getName()
setPrice() & getPrice()
setQuantity() & getQuantity()
(2) In main(), prompt the user for two items and create two objects of the ItemToPurchase class. Before prompting for the second item, call scnr.nextLine(); to allow the user to input a new string.
Ex:
(3) Add the costs of the two items together and output the total cost.
Ex:
PART 2:
This program extends the earlier \"Online shopping cart\" program. (Consider first saving your earlier program).
(1) Extend the ItemToPurchase class per the following specifications:
Ex. of printItemCost() output:
Ex. of printItemDescription() output:
(2) Create two new files:
Build the ShoppingCart class with the following specifications. Note: Some can be method stubs (empty methods) initially, to be completed in later steps.
Parameterized constructor which takes the customer name and date as parameters
Public member methods
Ex. of printTotal() output:
Ex. of printDescriptions() output:
(3) In main(), prompt the user for a customer\'s name and today\'s date. Output the name and date. Create an object of type ShoppingCart.
Ex.
(4) Implement the printMenu() method. printMenu() has a ShoppingCart parameter, and outputs a menu of options to manipulate the shopping cart. Each option is represented by a single character. Build and output the menu within the method.
If the an invalid character is entered, continue to prompt for a valid choice. Hint: Implement Quit before implementing other options. Call printMenu() in the main() method. Continue to execute the menu until the user enters q to Quit.
Ex:
(5) Implement Output shopping cart menu option.
Ex:
(6) Implement Output item\'s description menu option.
Ex.
(7) Implement Add item to cart menu option.
Ex:
(8) Implement Remove item menu option.
Ex:
(9) Implement Change item quantity menu option. Hint: Make new ItemToPurchase object and use ItemToPurchase modifiers before using modifyItem() method.
Ex:
Solution
(1) Create two files:
Answer :-
ItemToPurchase:-
ShoppingCartPrinter: -
import java.util.Scanner;
public class ShoppingCartPrinter {
public static void main(String[] args) {
ItemToPurchase item1 = new ItemToPurchase();
ItemToPurchase item2 = new ItemToPurchase();
Scanner scnr = new Scanner(System.in);
scnr.nextLine();
System.out.println(\"Item 1\");
System.out.println(\"Enter the item name: \");
item1.getName();
System.out.println(\"Enter the item price: \");
item1.getPrice();
System.out.println(\"Enter the item quantity: \");
item1.getQuantity();
System.out.println();
scnr.nextLine();
System.out.println(\"Item 2\");
System.out.println(\"Enter the item name: \");
item2.getName();
System.out.println(\"Enter the item price: \");
item2.getPrice();
System.out.println(\"Enter the item quantity: \");
item2.getQuantity();
System.out.println();
System.out.println(\"TOTAL COST\");
System.out.println(item1.getName());
System.out.print(item1.getQuantity() + \" @ $\");
System.out.println(item1.getPrice());
System.out.println(item2.getName());
System.out.print(item2.getQuantity() + \" @ $\");
System.out.println(item2.getPrice());
}
}


