New, Improved 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 new improved program follows.

New, Improved Restaurant Program

Your program should look much like the following:

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

class RestaurantBill
{
  public static void main (String[] args)  
  {
    Scanner scan = new Scanner( System.in );
    double basicCost;
    double tipPercent;

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

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

The println statement was changed to use the variable tipPercent. Without this change, the program would run, and would appear to work correctly, but would not calculate the correct result.

QUESTION 11:

If the println statement were not changed, would the Public Health Inspector give your program a passing grade?