 |
CS 139
Algorithm Development
PA2: Fine Dining Refactored
Part
A Due in Canvas by Friday,October 3 at 11:59PM
Part B Due in WebCAT by
Wednesday, October 8 at 11:59 PM
- -10% on Thursday, October 9
- -20% on Friday, October 10
- -35% on Sunday, October 12
- -50% on Monday, October 13
- Not accepted afterwards
Part C due in Canvas by
Thursday,October 9 or one day after you have successfully submitted to
WebCAT.
Part D due in class on
Thursday, October 10 or one day after you have successfully submitted
to
WebCAT.
|
 |
Objectives - At the conclusion of this assignment students will
have demonstrated that they can:
- Input data from a keyboard.
- Use Java math operations.
- Properly format output to specification.
- Do everything necessary to create, debug, and run a java
program.
- Use comments to delineate each section of the program.
- Divide a program into smaller more manageable components
- Adhere to a Java Style Guide.
- READ AND FOLLOW DIRECTIONS!!!!!
Background
When dining in a restaurant, patrons are presented with a check for
their meal. In this application you will calculate the tax and
suggested gratuities for a meal. This application will require you to
produce a "check" like you might get in a restaurant.
Requirements
PART A - Graded as a homework assignment. There
will be a separate Canvas Assignment for this.
You will stub out a program called BillMakerTools.java. This program
will contain the methods outlined below. The stubs must be compilable
working stubs such as you built in Lab 05B. They should be fully
documented. See specifications below for the required methods in
BillMakerTools.java. BillMakerTools will not have a main method except
if you build one for testing.
PART B - Submitted to webcat.
You will write a Java program consisting of BillMaker.java and
BillMakerTools.java, that must:
- Prompt for and receive the meal amount using the prompt "How
much was the total bill? " and the cursor must remain on the line
beside
the space following the question mark.
- Prompt for and receive name of the server. The prompt must be of
the form, "Who was the server? " and the cursor must remain
on the line beside the space following the colon.
- Calculate the tax based on the tax rate of 11.8%.
- Calculate the total bill.
- Calculate three tip amounts, one based on 15% of the meal amount,
one based on 18%, and the final one at 20% of the meal amount.
- Output a report in the following format:
<blank>
Total bill: $ 88.00
Tax: $ 10.38
You owe: $ 98.38
<blank>
Your server was kelly.
Tip 15%: $ 13.20
Tip 18%: $ 15.84
Tip 20%: $ 17.60
<blank>
Thank you for dining with us.
Output MUST conform exactly to that shown. Failure to match it
exactly will result in WebCAT errors. Each line above must end
with the new line character directly following the output value and the
blank lines <blank> in the output are significant. These lines
should not include a blank space character, but should include a single
new line character.
A complete dialog (with input values highlighted in red would look
like)
How much was the total bill? 100
Who was the server? kelly
<blank>
Total bill: $100.00
Tax: $ 11.80
You owe: $111.80
<blank>
Your server was kelly.
Tip 15%: $ 15.00
Tip 18%: $ 18.00
Tip 20%: $ 20.00
<blank>
Thank you for dining with us.
NOTES:
- Each of the output lines must terminate with a single newline
"\n" character with the exception of the input prompts.
- All of the colons should line up vertically. The T for the total
bill will be in the first position and all colons will line up with the
one after "bill:".
- Each line identified by <blank> should have a single
newline character and no spaces.
- All currency amounts must be formatted with a $ followed by up to
three digits followed by a decimal point and exactly 2 digits following
the decimal place. Valid formatting would look like $ 0.50, $ 12.95, $
1.50, etc.
- Your tax rate should be a named constant in the file.
Your program should use appropriate data types for the values being
input and calculated, and appropriate and meaningful names for all
variables and constants. The program source must follow all StyleGuide
conventions used in this class.
Part B Structure
BillMaker will contain a single method, main which will call all of
the other methods in BillMakerTools to perform the calculations and
output the results. Nothing should be directly output in BillMaker.
BillMakerTools will have the following methods:
-
inputDouble has two parameters, a Scanner
object (built in main) and a String prompt. The method should use the
prompt to print a message to the user and then read in a double value.
Any data remaining on the line should be "consumed" to avoid any
conflict with future reads. The double is returned by the method.
- inputString has two
parameters, a Scanner object (built in main) and a String prompt. The
method should use the prompt to print a message to the suer and then
read in a String value. The String is then returned by the method.
- formatBillAmount has one
parameter, the amount to format as a double. It returns a String which
is the amount formatted as shown in the examples, with a $ followed by
0, 1, or 2 spaces depending on the dollar amount, a decimal point and
two digits rounded. NOTE: String has a method, format, which will
behave like printf, except that it will not print the value, but
instead will return a String.
- formatLabels has two
parameters, a String which is the label (in this case like Total bill:
or Tax:) and an integer width and will return a new String padded on
the left with enough spaces to fill the width. For example, if the
String were "Total bill:" and the width was 11, then the return would
be the same as the value passed in. If the String were "Tax:" and the
width 11, 7 blanks would be put in front of the bill. Note, this can be
done without ifs or loops. HINT: Consider a long constant String of
blanks. If you need 7 blanks, you can substring the spring to give you
only 7 blank spaces which can be concatenated onto the front of the
passed String. Work out this calculation on paper before trying to code
it.
- calcTax will calculate
the tax. This method will take in an amount to be taxed and returns the
tax on that amount. The tax rate should be a constant within this
method.
- calcTip will calculate
the tip. This method will take in an amount of the meal and the tip
percentage and will return the amount that the tip should be.
- print will take in a
single parameter, the line to print and will output the line.
Part B Deliverables
- Zip your BillMaker.java and BillMakerTools.java into a zip file.
Submit the zip file via
Web-CAT (http://webcat.cs.jmu.edu).
- Your program will be judged on correctness (80%) and conformance
to the StyleGuide
(20%). The checkoff chart is found here.
Deductions for failing to follow the structure will be taken from the
80% correctness score.
Part C, D - Reflection and Pair Programming Log - graded as
regular homework assignments. There will be separate Canvas Assignments
for this.
You will write a reflection document for this assignment which will
let you consider the process of building this program. It will also
contain a place to critique this assignment for this class.
In addition, you should keep a log showing how much time you and
your partner worked together and how much time you worked alone.
Honor Code
This is a pair programming assignment. You may work with your
partner, but may not work with any other team. This assignment should
be viewed as a take home exam. Your work on the assignment and your
submission must conform to the JMU Honor Code.
Authorized help is limited to the classroom handouts, lab material, the
TAs for any CS139 or CS 149 section, and either professor. Copying work
from another student not in your partnership or the Internet is an
honor code violation, which will result in a zero on the assignment and
possibly further sanctions. Your work on this assignment is subject to
review by MOSS
which is a plagiarism detection tool for programs. Submission to WebCAT
constitutes your submission of work for academic credit and your
agreement that your work may be submitted to MOSS.