Question
JAVA What is the solution to the problem public class Item { private String name; private double price; private int bulkQuantity; private double bulkPrice; public
JAVA
What is the solution to the problem
public class Item {
private String name; private double price; private int bulkQuantity; private double bulkPrice;
public Item(String name, double price, int bulkQuantity) { this.name = name; this.price = price; this.bulkQuantity = bulkQuantity; }
public String toString() { return this.name + ".." + this.bulkQuantity + ".." + this.price + "$"; }
public String getName() { return this.name; }
public double getPrice() { return this.price; }
public int getBulkQuantity() { return this.bulkQuantity; }
public void decreaseBulkQuantity(int quantity) { this.bulkQuantity -= quantity; }
public void increaseBulkQuantity(int quantity) { this.bulkQuantity += quantity; } }
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
public class ItemOrder {
private Item item; private int Quantity;
public ItemOrder(Item item, int quantity) { this.item = item; this.Quantity += quantity; }
public double getPrice() { return item.getPrice() * this.Quantity; }
public Item getItem() { return this.item; }
public int getQuantity() { return Quantity; }
public String showOut() { return this.item.getName() + ".." + this.Quantity + ".." + getPrice(); } }
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
import java.util.ArrayList; import java.util.Scanner;
public class k {
public static void main(String[] args) { Scanner in = new Scanner(System.in);
Item milk = new Item("milk", 9, 20); Item bread = new Item("bread", 7, 15); Item banana = new Item("banana", 2, 30); Item[] listItem = {milk, bread, banana}; int[] listQuantity = {0, 0, 0};
ItemOrder order1 = new ItemOrder(listItem[0], listQuantity[0]); ItemOrder order2 = new ItemOrder(listItem[1], listQuantity[1]); ItemOrder order3 = new ItemOrder(listItem[2], listQuantity[2]); ItemOrder[] listOrder = {order1, order2, order3};
ArrayList
double total = 0;
System.out.println("HellOoOo ()/ .......... 1.Buy Item 2.view Purchases & Total price 3.Exit"); int choice1 = in.nextInt(); boolean loop1 = true; while (loop1) { switch (choice1) { case 1: for (int i = 0; i < listItem.length; i++) { System.out.println("\t" + (i + 1) + "." + listItem[i].toString()); } boolean loop2 = true; while (loop2) { System.out.println("\t\t1.add \t\t2.remove\t\t 3.back to hello page"); int choice2 = in.nextInt(); switch (choice2) { case 1: System.out.println("\t\t\tenter the number of item"); int numItem1 = in.nextInt(); System.out.println("\t\t\tenter the quantity "); int quaItem = in.nextInt(); if (quaItem > listItem[numItem1 - 1].getBulkQuantity()) { System.out.println("the quantity Not available"); break; } else { listQuantity[numItem1 - 1] += quaItem; listItem[numItem1 - 1].decreaseBulkQuantity(listQuantity[numItem1 - 1]); sell.add(listOrder[numItem1 - 1]); total += listOrder[numItem1 - 1].getPrice(); } break; case 2: System.out.println("\t\t\t1.all the quantity \t\t\t2.part of the quantity"); int choice3 = in.nextInt(); switch (choice3) { case 1: System.out.println("\t\t\t\t\tenter the number of item"); int numItem2 = in.nextInt(); for (int i = 0; i < sell.size(); i++) { if (sell[i].getItem().getName() == listItem[numItem2 - 1].getName()) { listItem[numItem2 - 1].increaseBulkQuantity(listQuantity[numItem1 - 1]); listQuantity[numItem2 - 1] = 0; sell.remove(sell[i]); } else { System.out.println("\t\t\t\t\tthe item not found"); } } break; case 2: System.out.println("\t\t\t\t\tenter the number of item"); int numItem3 = in.nextInt(); System.out.println("\t\t\t\t\tenter the quantity"); int qua = in.nextInt(); for (int i = 0; i < sell.size(); i++) { if (sell[i].getItem().getName() == listItem[numItem2 - 1].getName()) { listItem[numItem2 - 1].increaseBulkQuantity(qua); listQuantity[numItem2 - 1] -= qua; } else { System.out.println("\t\t\t\t\tthe item not found"); } } break; default: System.out.println("\t\t\t\t\tinvalid code"); break; } break; case 3: loop2 = false; break; default: System.out.println("\t\t\tinvalid code"); break; } } break; case 2: System.out.println("your total price is: " + total); break; case 3: loop1 = false; break; default: System.out.println("invalid code..Re try"); } } } }
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