Question
ItemToPurchase.java:- package main; enum ItemTaxCategory { N,// no tax for item X,// 8% T;//10% } public class ItemToPurchase { private String itemName; private int itemPrice;
ItemToPurchase.java:-
package main; enum ItemTaxCategory { N,// no tax for item X,// 8% T;//10% } 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; }
/** * @return the itemName */ public String getName() { return itemName; }
/** * @param itemName the itemName to set */ public void setName(String itemName) { this.itemName = itemName; }
/** * @return the itemPrice */ public int getPrice() { return itemPrice; }
/** * @param itemPrice the itemPrice to set */ public void setPrice(int itemPrice) { this.itemPrice = itemPrice; }
/** * @return the itemQuantity */ public int getQuantity() { return itemQuantity; }
/** * @param itemQuantity the itemQuantity to set */ public void setQuantity(int itemQuantity) { this.itemQuantity = itemQuantity; }
/** * @return the category */ public ItemTaxCategory getTaxCategory() { return category; }
/** * @param category the category to set */ 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; } }
ShopingCartPrinter.java :-
package main;
import java.util.Scanner;
//Define the class ShoppingCartPrinter.
class ShopingCartPrinter
{
//Start the main() method.
public static void main(String[] args)
{
//Declare required variables.
String it_name;
int it_price, it_quantity, item1Cost, item2Cost;
//Create two objects of the class ItemToPurchase.
ItemToPurchase item1 = new ItemToPurchase();
ItemToPurchase item2 = new ItemToPurchase();
//Create an object of scanner class.
Scanner scnr = new Scanner(System.in);
//Prompt the user to enter the details of item 1
//and set the information of item 1 using setter
//methods.
System.out.println("Item 1");
System.out.println("Enter the item name:");
it_name = scnr.nextLine();
item1.setName(it_name);
System.out.println("Enter the item price:");
it_price = scnr.nextInt();
item1.setPrice(it_price);
System.out.println("Enter the item quantity:");
it_quantity = scnr.nextInt();
item1.setQuantity(it_quantity);
//Call the function nextLine() to allow the user to
//input a new string.
scnr.nextLine();
//Prompt the user to enter the details of item 2
//and set the information of item 2 using setter
//methods.
System.out.println(" Item 2");
System.out.println("Enter the item name:");
it_name = scnr.nextLine();
item2.setName(it_name);
System.out.println("Enter the item price:");
it_price = scnr.nextInt();
item2.setPrice(it_price);
System.out.println("Enter the item quantity:");
it_quantity = scnr.nextInt();
item2.setQuantity(it_quantity);
//Display the total cost of both items.
System.out.println(" TOTAL COST");
//Get the cost of both items by multiplying their
//price with their quantities respectively.
item1Cost = item1.getPrice() * item1.getQuantity();
item2Cost = item2.getPrice() * item2.getQuantity();
//Add both item cost to get the total cost.
int totalCost = item1Cost + item2Cost;
//Display the information of both items.
System.out.println(item1.getName() + " "
+ item1.getQuantity() + " @ $" + item1.getPrice()
+ " = $" + item1Cost);
System.out.println(item2.getName() + " "
+ item2.getQuantity() + " @ $" + item2.getPrice()
+ " = $" + item2Cost);
//Display the total cost of both items.
System.out.println(" Total: $" + totalCost);
//Close the scanner class object.
scnr.close();
}
}
I want output as shown in the screenshot below:-
When you run ShopingCartPrinter.java I want the result as shown in screenshot:-
and this screenshot is for your help;-
less you need to edit, it's safer to stay in Protected View. Enable Editing create two objects of the ItemToPurchase class. Your output should look like this: Item 1 Enter the item name: Chocolate Chips Enter the item price: 3 Enter the item quantity: 1 Enter the tax category: X Item 2 Enter the item name: Bottled Water Enter the item price: 1 Enter the item quantity: 10 Enter the tax category T 3. Add the costs of the two items together, apply tax according to the conditions described output the total cost Output Example TOTAL COST Chocolate Chips 1 @ $3 - $3 Bottled Water 10 @ $1 + $10 Tax - $1.24 Total: $14.24 Part 2 workspace - Java - CSC20ASS1/src/main/Shopping Ca File Edit Source Refactor Navigate Search Proje HR- O-a. O Package Explorer X CSC20ASS1 Shopp Ente src main > 2 ItemToPurchase.java > Shopping Cart.java > Shopping CartManager.java > Shopping CartPrinter.java JRE System Library (JavaSE-1.8] CSC2OLAB1 CSC2OLAB2 CSC2OLAB3 CSC2OLAB4 CSC2OLAB5 Homework #10 Homework #3 Homework #4 Homework #6 Homework #7 Homework #8 Homework #9 Homework#5 lab 1
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started