You will also create two classes, one for existing project two called foodTrack and another class called foodDiscount that extends foodTrack.
//initialize program
import java.util.Scanner;
public class Main
{
finalstatic String items[]=new String[]{"FRIES","CHEESESTEAK","BISCUIT","SALADBOWL","DONUTBOX","SALESTAX"};
finalstaticfloat price[]=newfloat[]{2.99F,5.99F,.99F,5.99F,10.99F,.06F};//declare array functions and variables
staticfloat subTotal=0, TAX=0, total=0, tender=0,change=0;
publicstaticvoid getInput(int[] ordered_items)
{
Scanner sc= new Scanner(System.in);
for(int i=0;i<5;i++)
{//get input from the userand showcase price and per item as well as quantity
//ask the user questions
System.out.println("How many "+ items[i] +" would you like to order? (each at: " + price[i] + ")");
ordered_items[i] = sc.nextInt();
}
}
publicstaticvoid billCalculator(int[] ordered_items,float[] item_bill)
{
for(int i=0;i<5;i++)//calculate for the itemsor dered
{
item_bill[i] = ordered_items[i]*price[i];
}
for(int i=0;i<5;i++)//calculate the price for the items ordered
{
subTotal+=item_bill[i];
}//calculate subtotal and total
TAX = subTotal * price[5];
total = subTotal + TAX;
}
publicstaticvoid printBill(int[] ordered_items,float[] item_bill)
//Receipt displayal starts here
{
System.out.println("\t\t\t\t\t\tTop Cuisine");
System.out.println("\t\t\t\t\t\t1267 Loongton st.");
System.out.println("\t\t\t\t\thyattsville, Maryland 28746");
System.out.println("\t\t\t\t\t\t301-273-378");
for(int i=0;i<5;i++)
{
System.out.println(ordered_items[i] + " " + items[i] + " each at: $" + price[i] + "\t\t\t\t\t\t\t\t $" + item_bill[i]);
}
//Display items quantity ordered, and cost per individual item
//start displaying the total , taxes, subtotal and change.
System.out.println(" Subtotal :\t\t\t\t\t\t\t\t\t\t\t\t$"+subTotal );
System.out.println(" Taxes : \t\t\t\t\t\t\t\t\t\t\t\t$" +TAX);
System.out.println(" Total :\t\t\t\t\t\t\t\t\t\t\t\t$"+total);
System.out.println(" Tender :\t\t\t\t\t\t\t\t\t\t\t\t$" +tender);
System.out.println(" Change :\t\t\t\t\t\t\t\t\t\t\t\t$" +change);
System.out.println("\t\t\t\t Thank You For Visiting ! Come Again!");
}
//displya total amount due to user if not met, loop back until price is correctly payed.
publicstaticvoid main(String[] args)
{
int ordered_items[]=newint[5];
float item_bill[]=newfloat[5];
getInput(ordered_items);
billCalculator(ordered_items, item_bill);
System.out.println("How much will you be paying ? (Total is " + total + ")");
Scanner sc= new Scanner(System.in);
while(true)
{
tender = sc.nextFloat();
if(tender<total)
{
System.out.println("You are paying "+(total-tender)+" less than the total bill");
System.out.println("Please re-enter the amount");
}
else
{
break;
}
}
change = tender - total;
printBill(ordered_items, item_bill);
}
}
//program finished.