Colorado State University

Recitation R8 - Java: Restaurant Receipts
Spring 2015

CS160: Foundations in Programming


Must be completed during recitation on Feb. 23-25.

Objectives

The goal of this lab is to create a simple program that prints a restaurant receipt to the screen. This recitation is intended as a pair programming exercise. Each team with work on one computer and you will trade typing in the middle. To submit, each person in the team will submit the same file and this can be done on the same system. The TA will assist with any submission questions. In this recitation you will be using:

Instructions

IMPORTANT: This code is what will be graded. If you have any doubts or questions, ask the TA:
  1. Read all the steps carefully before beginning. Understand the larger picture.
  2. Create a new Java Project named R8, and make a class named R8.
  3. Copy the following code and paste it inside the the curly braces of the main method:
    // Declare variables
    String restaurantName;
    String serverName;
    double subtotal;
    double tax;
    double total;
    double taxRate = 0.05;
    double tipRate1 = 0.10;
    double tipRate2 = 0.15;
    double tipRate3 = 0.20;
    		
    // Ask and receive input from the user
    
    		
    // Perform calculations
    
    		
    // Print receipt		
    
  4. Create a Scanner object.
  5. Prompt the user for the name of the restaurant and read in their input. The restaurant can be be more than one word, like "Park Sushi." Store the value in the variable restaurantName.
  6. Prompt the user for the name of the server. Store the value in the variable serverName. Assume the server name will always be a first and last name, separated by one space character.
  7. Prompt the user for the cost of the bill. Store the value in the variable subtotal. Assume the cost will be a double value representing dollars, for example 56.23.
  8. Calculate the amount of tax on the bill based on the taxRate and store the result in the variable tax.
  9. Calculate the total bill by adding the subtotal and tax together. Store the total bill in the variable total.
  10. Using the calculated values you stored in variables, print a receipt to the console. We recommend you print the receipt one line at a time. You can use println() and printf() to do this. Make sure you copy exactly the format of the receipt as seen here:
    =====================================
    Park Sushi
    Your server was: JULIE
    Subtotal: $56.23
    Tax: $2.81
    =====================================
    Total: $59.04
    
    Suggested tips:
    10%: $5.90
    15%: $8.86
    20%: $11.81
    
    Thank you!
    =====================================
    
Note the following details: Some tips:

© 2015 CS160 Colorado State University. All Rights Reserved.