Answer:
Step-by-step explanation:
package sample;
import java.util.Scanner;
public class Main extends newOrder{
public static void main(String[] args) {
newOrder order = new newOrder();
order.newOrder("apple", 0.5);
order.newOrder("pear", 0.75);
order.newOrder("pineapple", 0.75);
double newTotal = order.getTotal();
order.printItems();
order.printTotal();
while (newTotal != 0) {
Scanner in = new Scanner(System.in);
System.out.println("Please enter payment type.\\" + "Cash \\Debit card \\Credit card \\Check");
String paymentType = in.nextLine();
System.out.println("Enter the amount to pay with this type: ");
double amount = in.nextDouble();
newTotal -= amount;
System.out.println("Total after payment: " + newTotal);
}
System.out.println("Receipt Printed:");
order.printItems();
order.printSubtotal();
System.out.println("Tax: 7%");
order.printTotal();
}
}
------------------------------------------------------------------------------------------------------------
package sample;
public enum PaymentType {
CASH, DEBIT_CARD, CREDIT_CARD, CHECK
}
-----------------------------------------------------------------------------------------------------------
package sample;
import java.util.HashMap;
class newOrder {
private String name;
private double cost;
private double total;
private double subtotal;
HashMap<String, Double> itemList = new HashMap<>();
public void newOrder(String name, double cost) {
this.name = name;
this.cost = cost;
this.total += cost;
}
public void printItems() {
for (String i: itemList.keySet()) {
System.out.println( i + ": \t" + itemList.get(i));
}
}
public double getTotal() {
return (total * 1.07);
}
public void printSubtotal() {
for (double i : itemList.values()) {
subtotal += i;
}
System.out.println("Subtotal: " + subtotal);
}
public void printTotal() {
double total = subtotal * 1.07;
System.out.println("Total: " + total);
}
}