Full Restaurant Program

Classic programmed-learning exercises, refreshed for modern Java and presented in the current MrStyner.com portfolio style.

Modern Java noteThis archive has been refreshed for Java 25 LTS. Core language concepts remain useful, while outdated setup instructions and browser-era Java are labeled or replaced. Java 26 is the current feature release; Java 25 is used here as the stable teaching baseline.
go to previous page   go to home page   hear noise   go to next page

Answer:

The full program is below:

Full Restaurant Program

Here is the correct program, suitable for copying to a file and running. Hopefully you figured out the proper order for the lines. You should be able to read the program almost like a story in normal English.

import java.io.*;
import java.util.Scanner;

class RestaurantBill
{
  public static void main (String[] args)  

  {
    Scanner scan = new Scanner( System.in );
    double basicCost;

    System.out.print("Enter the basic cost: ");
    basicCost = scan.nextDouble();

    System.out.println("basic cost: " +  basicCost + " total cost: " + 
         (basicCost + basicCost*0.06 + basicCost*0.20) );
  }
}

As you read the story (the program) it should make sense. Actions should follow in a logical order. The logic is the important part, not the fussy details of syntax.

QUESTION 9:

There have been some big programming projects that failed badly, costing billions of dollars. What do you suppose is true:

  • The projects failed because their programmers did not know syntax, or
  • The projects failed because their logic was bad.