Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Project Four The Cafe Problem Write a program for a cafe to display the bill for

ID: 3603132 • Letter: P

Question

Project Four The Cafe Problem Write a program for a cafe to display the bill for the cashier. The cafe serves a chef's menu with two options Category Adults Children Price Adjustment $31.50 The total adult bill is reduced by $4.00 if there are 8 or more adults. $15.00 The program first requests the identification number for the cafe and the starting order number. The program then accepts the number of adults and children, performs the necessary calculations, computes the 6% tax, and displays the bill similar to the example below. Enter cafe identifier: 252 Enter first order number: 1ee White Marsh Cafe Order Number 1ee Price Total Adults Children 31.58 248.00 15.00 30.80 278.80 16.68 Subtotal (6%) Total bil1 Tax 294.68 27

Explanation / Answer

import java.util.Scanner;

public class Menu {
public double subTotal;
public static double runningTotal;
private static double itemPrice;
static boolean ordering = true;
static Scanner input = new Scanner(System.in);

public static void menu() {
System.out.println("Welcome 1. Burger ($2.00) 2. Fries ($1.50) 3. Soda ($1.00) 4. Done");
}

public static double itemPrice(int foodItem) {
if (foodItem == 1) {
  
System.out.println("You've ordered a burger");
itemPrice = 2.00;
}
if (foodItem == 2) {

System.out.println("You've ordered fries");
itemPrice = 1.50;
}
if (foodItem == 3) {
  
System.out.println("You've ordered a soda");
itemPrice = 1.00;
}
quantity();
return itemPrice;
}

public static double quantity() {
System.out.println("Enter quantity");
double quantity = input.nextDouble();
subTotal(quantity, itemPrice);
return quantity;
}

public static double subTotal(double quantity, double itemPrice) {
double subTotal = quantity * itemPrice;
System.out.println("Subtotal: " + subTotal);
return subTotal;
}

public static void done(double runningTotal) {
ordering = false;
System.out.println(runningTotal);
System.out.println("Enjoy your meal");
}

public static void main(String[] args) {
int menuOption;
int foodItem = 0;
input = new Scanner(System.in);
do {
double runningTotal = 0;
menu();
menuOption = input.nextInt();
switch (menuOption) {
case 1:
foodItem = 1;
itemPrice(foodItem);
break;
case 2:
foodItem = 2;
itemPrice(foodItem);
break;
case 3:
foodItem = 3;
itemPrice(foodItem);
break;
case 4:
done(runningTotal);
break;
default:
System.out.println("Invalid option.");
}
} while (ordering);
{
subTotal(quantity(), itemPrice(foodItem));
runningTotal = runningTotal + subTotal(quantity(), itemPrice(foodItem));
}
}
}

public static void main(String[] args) {
int menuOption;
int foodItem = 0;
input = new Scanner(System.in);
double runningTotal=0;
do{
menu();
menuOption = input.nextInt();
switch(menuOption){
case 1:
foodItem = 1;
runningTotal += itemPrice(foodItem);
break;
case 2:
foodItem = 2;
runningTotal += itemPrice(foodItem);
break;
case 3:
foodItem = 3;
runningTotal += itemPrice(foodItem);
break;
case 4:
done(runningTotal);
break;
default:
System.out.println("Invalid option.");
}
} while(ordering);
System.out.println("Total amount: " + runningTotal);
}

import java.util.Scanner;
public class menu {
public double subTotal;
public static double runningTotal;
private static double itemPrice;
static boolean ordering = true;
static Scanner input = new Scanner(System.in);
public static void menu(){
System.out.println("Welcome 1. Burger ($2.00) 2. Fries ($1.50) 3. Soda ($1.00) 4. Done");
}
public static double itemPrice(int foodItem) {
if (foodItem == 1) {
  
System.out.println("You've ordered a burger");
itemPrice = 2.00;
}
if (foodItem == 2) {
  
System.out.println("You've ordered fries");
itemPrice = 1.50;
}
if (foodItem == 3) {

System.out.println("You've ordered a soda");
itemPrice = 1.00;
}
quantity();
return itemPrice;
}
public static double quantity() {
System.out.println("Enter quantity");
double quantity = input.nextDouble();
subTotal(quantity, itemPrice);
return quantity;
}
public static double subTotal(double quantity, double itemPrice) {
double subTotal = quantity*itemPrice;
System.out.println("Subtotal: "+ subTotal);
runningTotal += subTotal;
return subTotal;
}
public static void done(){
ordering = false;
System.out.println(runningTotal);
System.out.println("Enjoy your meal");
}
public static void main(String[] args) {
int menuOption;
int foodItem = 0;
input = new Scanner(System.in);
do{
double runningTotal=0;
menu();
menuOption = input.nextInt();   
switch(menuOption){
case 1:
foodItem = 1;
itemPrice(foodItem);
break;
case 2:
foodItem = 2;
itemPrice(foodItem);
break;
case 3:
foodItem = 3;
itemPrice(foodItem);
break;
case 4:
done();
break;   
default:
System.out.println("Invalid option.");
}

} while(ordering); {
}
}
}

IDENTIFICATION DIVISION.
PROGRAM-ID. Table1.

ENVIRONMENT DIVISION.

CONFIGURATION SECTION.
SOURCE-COMPUTER. IBM-PC.
OBJECT-COMPUTER. IBM-PC.

INPUT-OUTPUT SECTION.
FILE-CONTROL.

SELECT TABLE-FILE ASSIGN TO DISK
ORGANIZATION IS LINE SEQUENTIAL.

SELECT CUST-FILE ASSIGN TO DISK
ORGANIZATION IS LINE SEQUENTIAL.

SELECT BILL-FILE ASSIGN TO DISK
ORGANIZATION IS LINE SEQUENTIAL.

DATA DIVISION.

FILE SECTION.

FD TABLE-FILE
VALUE OF FILE-ID IS "TABLE.IND".
01 TABLE-REC.
05 ZIPCODE PIC 9(6).
05 FILLER PIC XX.
05 TAX-RATE PIC 99.

FD CUST-FILE
VALUE OF FILE-ID IS "CUST.DAT".
01 SAL-REC.
05 C-ID PIC 9(4).
05 FILLER PIC XX.
05 C-ZIPCODE PIC 9(6).
05 FILLER PIC XX.
05 C-SALE PIC 9(6).

FD BILL-FILE
VALUE OF FILE-ID IS "BILL.RPT".
01 BILL-REC PIC X(80).

WORKING-STORAGE SECTION.
01 TAB.
05 TABLE-ENTRIES OCCURS 5 TIMES.
07 TEMP-ZIPCODE PIC 9(6).
07 FILLER PIC XX.
07 TEMP-TAX-RATE PIC 99.

01 OUT-REC.
05 OUT-C-ID PIC 9(4).
05 PIC XX VALUE SPACES.
05 OUT-C-ZIPCODE PIC 9(6).
05 PIC XX VALUE SPACES.
05 OUT-C-SALE PIC 9(6).
05 PIC XX VALUE SPACES.
05 OUT-C-TAX-RATE PIC 9(2).
05 PIC XX VALUE SPACES.
05 OUT-C-TAX PIC 9(6).

77 EOF PIC X VALUE 'N'.
77 IND PIC 9 VALUE 1.

PROCEDURE DIVISION.

BEGIN.
OPEN INPUT TABLE-FILE
CUST-FILE
OUTPUT BILL-FILE.

PERFORM GET-TABLE-ENTRIES.
PERFORM GET-SAL-ENTRIES.

CLOSE TABLE-FILE
CUST-FILE
BILL-FILE.

STOP RUN.

GET-TABLE-ENTRIES.
MOVE 1 TO IND
PERFORM VARYING IND FROM 1 BY 1
UNTIL IND > 5
READ TABLE-FILE
AT END CONTINUE
NOT AT END PERFORM MOVE-TABLE-ENTRIES
END-READ
END-PERFORM.

MOVE-TABLE-ENTRIES.
MOVE ZIPCODE TO TEMP-ZIPCODE (IND)
MOVE TAX-RATE TO TEMP-TAX-RATE (IND).

GET-SAL-ENTRIES.
PERFORM UNTIL EOF = 'Y'
READ CUST-FILE
AT END MOVE 'Y' TO EOF
NOT AT END PERFORM MOVE-CUST-ENTRIES
END-READ
END-PERFORM.

MOVE-CUST-ENTRIES.
MOVE C-ID TO OUT-C-ID
MOVE C-ZIPCODE TO OUT-C-ZIPCODE
MOVE C-SALE TO OUT-C-SALE

MOVE 1 TO IND
PERFORM VARYING IND FROM 1 BY 1
UNTIL IND > 6 OR C-ZIPCODE = TEMP-ZIPCODE (IND)
END-PERFORM

IF IND < 6
MOVE TEMP-TAX-RATE (IND) TO OUT-C-TAX-RATE
COMPUTE OUT-C-TAX = (OUT-C-SALE * OUT-C-TAX-RATE) /100
ELSE
MOVE 0 TO OUT-C-TAX-RATE OUT-C-TAX
END-IF