Question: JAVA What is the solution to the problem public class Item { private String name; private double price; private int bulkQuantity; private double bulkprice; Itemorder

JAVA

What is the solution to the problem

public class Item {

private String name; private double price; private int bulkQuantity; private double bulkprice; Itemorder Itemorder;

public Item(String name, double price, int bulkQuantity, double bulkprice) { this.name = name; this.price = price; this.bulkQuantity = bulkQuantity; this.bulkprice = bulkprice; }

public String getName() { return name; }

public void setName(String name) { this.name = name; }

public double getPrice() { return price; }

public void setPrice(double price) { this.price = price; }

public int getBulkQuantity() { return bulkQuantity; }

public void setBulkQuantity(int bulkQuantity) { if (bulkQuantity <= this.bulkQuantity) { this.bulkQuantity = bulkQuantity; } }

public double getBulkprice() { return bulkprice; }

public void setBulkprice(double bulkprice) { this.bulkprice = bulkprice; }

@Override public String toString() { return this.getName() + "\t Price: " + this.getPrice() + "\tgetBulkprice: " + this.getBulkprice() + "\tBulkQuantity: " + this.getBulkQuantity(); }

public Itemorder getItemorder() { return Itemorder; }

///////////////////////////////////////////////////////////

public class Itemorder { public Itemorder() { } public Itemorder(int quantity) { this.quantity = quantity; }

public Itemorder(Item item, int quantity) { this.item = item; this.quantity = quantity; } private Item item; private int quantity;

public int getQuantity() { return quantity; }

public void setQuantity(int quantity) { if (this.quantity >= 0) { this.quantity = quantity; } else { System.out.println("Quality of the quantity"); } }

public double getprice() { return this.getItem().getPrice() * quantity; }

public Item getItem() { return item; } }

/////////////////////////////////////////////////////////

import java.util.ArrayList; import java.util.List; import java.util.Scanner;

public class ShoppingCart2 {

List itemorderList;

public ShoppingCart2() { this.itemorderList = new ArrayList<>(); }

public void add(Itemorder itemorder) { itemorderList.add(itemorder); }

public void remove(int itemorder) { itemorderList.remove(itemorder); }

public double Total() { double total = 0; for (Itemorder itemorder : itemorderList) { total += itemorder.getprice(); } return total; }

public static void main(String[] args) { int p = 1; ShoppingCart shoppingCart = new ShoppingCart(); Scanner in = new Scanner(System.in); int num = 1; Itemorder Bread = new Itemorder(new Item(num + ".Name: " + "Bread", 1, 100, 80), 9); num++; Itemorder Milk = new Itemorder(new Item(num + ".Name: " + "Milk", 0.60, 50, 0.50), 15); num++; Itemorder Bananas = new Itemorder(new Item(num + ".Name: " + "Bananas", 0.40, 20, 0.20), 20); Itemorder[] itemorder = {Bread, Milk, Bananas}; Itemorder quan = new Itemorder(); System.out.println("Welcome to the market" + " ................................" + " what do you want to do? " + " 1.Buying Products In The Store" + " 2.Display Cart" + " 3.Finish"); System.out.print("Your choice: "); int chose = in.nextInt();

boolean loop = true;

while (loop) { switch (chose) { case 1: System.out.println(" "); for (Itemorder i : itemorder) { System.out.println(i.getItem().toString() + "\tQuqntity: " + i.getQuantity()); loop = false; } boolean loop2 = true;

while (loop2) {

System.out.println(" 1.Add to cary" + " 2.Remove From cart" + " 3.Back to back"); System.out.print("Your choice: "); loop2 = false; int shoce = in.nextInt(); switch (shoce) { case 1: System.out.print("Chose the product you whant to buy:"); int toBuyProduct = in.nextInt(); if (toBuyProduct == 1 || toBuyProduct == 2 || toBuyProduct == 3) { Itemorder tem = itemorder[toBuyProduct - 1]; int i = 1; switch (toBuyProduct) { case 1: System.out.print("Enter a quantity:"); int q = in.nextInt(); shoppingCart.add(new Itemorder(new Item(i + ".Name: " + "Bread", 1, 100, 80), q)); i++; loop2 = true; break;

case 2: System.out.print("Enter a quantity:"); q = in.nextInt(); shoppingCart.add(new Itemorder(new Item(i + ".Name: " + "Milk", 0.60, 50, 0.50), q)); i++; loop2 = true; break; case 3: System.out.print("Enter a quantity:"); q = in.nextInt(); shoppingCart.add(new Itemorder(new Item(i + ".Name: " + "Bananas", 0.40, 20, 0.20), q)); i++; loop2 = true; break; }

} else { System.out.println("----------------------------Error in input----------------------------"); } System.out.println(" "); for (Itemorder i : itemorder) { System.out.println(i.getItem().toString() + "\tQuqntity: " + i.getQuantity()); loop = false; } break; case 2: boolean loop3 = true; while (loop3) { System.out.println(" 1.Delete all cart" + " 2.Delete part of the cart" + " 3.Back to back"); System.out.print("Your choice: "); int sh = in.nextInt(); switch (sh) { case 1: shoppingCart.remove(0);//Delete from arraylist shoppingCart.remove(1);//Delete from arraylist shoppingCart.remove(2);//Delete from arraylist System.out.println("All items have been deleted"); break; case 2: System.out.println("Any product you want a delete"); System.out.print("Your choice: "); int pro = in.nextInt(); if (pro == 1 || pro == 2 || pro == 3) { pro -= 1; switch (pro) { case 1: shoppingCart.remove(0);//Delete from arraylist break; case 2: shoppingCart.remove(1);//Delete from arraylist break; case 3: shoppingCart.remove(2);//Delete from arraylist break; // default: // break; } } else { System.out.println("----------------------------Error in input----------------------------"); } break; case 3: loop = true; loop2 = false; loop3 = false; break; default: loop = false; loop2 = false; loop3 = true; System.out.println(" "); for (Itemorder i : itemorder) { System.out.println(i.getItem().toString() + "\tQuqntity: " + i.getQuantity()); loop = false; }

break; } }

break; case 3: loop = false; loop2 = true; break; default: if (p == 3) { System.out.println("-----------------------BYE!----------------------- "); System.exit(0); } else { p++; System.out.println(" Invalid c1`hoica"); System.out.println("Try again :( " + (p - 1) + " )"); loop = true; loop2 = false; break; } } } break;

case 2: System.out.println(" -----------------------Your purchases-----------------------"); System.out.println("You have to pay: "); for (Itemorder itemorder : shoppingCart.itemorderList) { System.out.println(itemorder.getItem() + "\tQuqntity: " + itemorder.getQuantity()); } System.out.println("Total purchases: " + shoppingCart.Total()); loop = false; break; case 3: System.out.println(" -----------------------BYE!----------------------- "); System.exit(0); break; default: System.out.println(" -----------------------ERROR in INPUT!----------------------- "); System.exit(0); break; } } } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!