COMP 110-001 - Introduction to Programming (Spring 2009)

Program 1: Tip Calculator

50 points

Assigned: January 21st

Due: February 4th by midnight

Description

In this assignment, you will write a Java program to aid restaurant-goers in calculating the total cost of their meal including a generous tip for good service. For the sake of this assignment, the tip should be calculated as follows: given the cost of the meal, subtract the tax (we'll use 5% as the tax rate) and calculate the tip as 20% of the reduced amount. For example, given a meal cost of $20, we calculate the cost of the meal before 5% tax to be $19.05. We then calculate the tip as 20% of $19.05, resulting in a tip of $3.81. The total cost of the meal is then $23.81.

Your program should first prompt the user for the cost of the meal before tip. The user must be allowed to enter decimal input such as 6.7. Your program should then output the amount of the tip AND the total cost of the meal including tip. Additionally, make your tip calculator convenient for those who wish to pay without coin. Do this by outputting the total cost of the meal including tip rounded up to the next whole dollar in addition to the other output. You will find it convenient to use Math.ceil(), which is provided by the Java language, for this purpose. For example, Math.ceil(12.7) will return 13, and Math.ceil(myVariable) will round the value stored in "myVariable" up to the next whole number.

Example run (User Input in Italics):

Hello restaurant-goer! I will help you with your check.
Please enter the cost of your meal before tip (do not include a $):

20.00

Your tip amount is $3.81. Your check with tip is $23.81. Rounded up to the next dollar, the total cost of your meal is $24.00.

Output Format

The amounts output by your program should use the dollar symbol '$' and be formatted with 2 decimal places for cents, e.g $12.67. You may use the following example code to ensure your output is properly formatted. The example code uses variables named "tipAmount", "checkWithTip", and "roundedCheck" for the three different amounts that must be output. You should replace these variable names with the names used in your program.

String output = String.format("Your tip amount is $%2.2f. Your check with tip is $%2.2f. Rounded up to the next dollar, the total cost of your meal is $%2.2f.", tipAmount, checkWithTip, roundedCheck);
System.out.println(output);

Submission

For this assignment you will need to create a Jar file that contains the source code for your program. Follow these instructions for creating a Jar file.
The Jar file you submit must be named yourlastname_pro1.jar, where yourlastname is your last name.

Submit yourlastname_pro1.jar via the UNC Blackboard System before the deadline.

Requirements & Grading