### Recitation R8 - Java: Restaurant Receipts Spring 2015

CS160: Foundations in Programming

### 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:
• Java variables and expressions
• The String object and its methods
• The Scanner object and its method
• The printing methods: println(), print(), and printf()

#### 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;

// 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
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:
• The restaurant is printed exactly how the user typed it.
• The server name is only the first name converted to all uppercase.
• There are spaces after every colon.
• There are dollar signs before every money amount.
• All money amounts are formatted to exactly two decimal places.
Some tips:
• Displaying a percent sign using printf() requires typing % twice:
```	CODE: System.out.printf("My battery is only at 3%%.");

OUTPUT: My battery is only at 3%.
```
• You can compute the suggested tips in advance and store them in variables, or you can compute them inside a print statement when printing the receipt.
• You may want to handle the printing of the server name last, since that's the harder part of this program.