CS 110: Program 2
Student Learning Objectives
- Demonstrate test-driven development and the ability to hand-calculate test cases
- Design and write a Java program that acts like a cash register
- The operator should enter the amount paid by the customer
- The operator should enter the amount owed
- The program will calculate the change returned to the customer. Make it user friendly.
- Display the total change and then display as dollars, quarters, dimes, nickles, and pennies
- Use integer division and modulus to perform calculations
- Use of jGRASP to type in, compile, and execute a simple Java program
- Use formatting and comments to produce readable programs.
- Include a file header comment to identify the author, account, and honor code
- Browse through the Java Programming Style Guide for other standards and conventions to use in CS 110.
Introduction
Write the Java program ChangeMaker.java that calculates the change to be returned to a customer based on the amount paid by the customer and the total amount of sale.
Test Driven Development
- Hand-calculate the change for the three test cases contained on the CS 110 Program 2 Grading Sheet (PDF), given the amount paid and the amount owed.
- This hand-calculations are part of your programming score, so do not skip this step
| Amount Paid | Amount Owed | Change Returned |
| Total Change | Dollars | Quarters | Dimes | Nickels | Pennies |
| 500 | 272 | | | | | | |
| 1000 | 156 | | | | | | |
| 200 | 199 | | | | | | |
Sample Session
Prompt for and read in the amount paid and amount owed as int values entered by the user.
Enter the amount the customer paid: 500
Enter the amount the customer owed: 272
Their change is 228
2 dollars, 1 quarters, 0 dimes, 0 nickels, and 3 pennies
Duplicate the sample session exactly; do not make up your own words or formatting.
Note: to simplify the assignment, do not worry about the 's' after the coin unit. For example, do not worry that "1 quarters" is grammatically incorrect and try to fix it to display as "1 quarter".
Java File, Header Comment, and Formatting
- Name your Java class
ChangeMaker and save the file in folder U:\programs\program2
- Note: if you prefer to complete the program at home, you must copy your
ChangeMaker.java file to your account's U:\programs\program2 folder to receive a score on the assignment
- Include a file header comment at the top of your program file that includes your name, cs110 account number, completion time, and honor code
- Program assignments are individual assignments, to be done solo.
- If you receive help in understanding or debugging the assignment, you must acknowledge the person who helped (including help from TAs outside of lab time) in the file header comment
//**********************************************************
// Assignment: Program 2
// Account: (Enter your cs110 account number here)
//
// Author: (Enter your full name here)
//
// Completion time: (Enter the total number of hours you
// spent on the assignment)
//
// Honor Code: I pledge that this program represents my own
// program code. I received help from (enter the names of
// others that helped you with the assignment or write no one if
// you received no help) in understanding and debugging my program.
//*********************************************************
- Include inline comments for every three to five lines of code
- Skip one blank line before every inline comment
- Use jGrasp Generate CSD to indent and align your program
Read through the CS 110 Java Programming Style Guide and follow all guidelines that apply at this point
What to turn in at the start of the next lab
- The CS 110 Program 2 Grading Sheet (PDF) with the table of three test cases filled in
- Write your full name and account number on the test cases page
- Be sure your project is saved in your
U:\programs\program2\ folder in your CS 110 account.
- Note: if you complete the assignment on your personal computer, you must copy the file(s) to your your CS network account
- An easy way to copy the files is to use a USB portable drive, email, or a digital drop box
- Instructions for accessing your U-Drive remotely is provided if you are unable to physically come into the Hebeler lab to copy the files
- Your program will be checked online. You do not need to print out a copy of your program to turn in.
- The assignment is due at the start of Lab 4.
- If you are unable to finish in time, you may turn in what you have done to receive partial credit for the assignment.
- You are allowed to drop one program assignment score for the quarter
Grading Criteria
20 points --
CS 110 Program 2 Grading Sheet (PDF)
- 12 points - Output Correctness
- The program calculates and displays the correct change with different user input (-1 per error, 10 points possible)
- The prompts and output produced by the program are correctly worded and formatted
- Duplicate the sample session exactly; do not make up your own words or formatting (-1 per problem, 2 points possible).
- 4 points - Comments and Alignment
- Include a complete file header comment with all required information filled in (1 point possible)
- Include single-line Java comments beginning with
// to explain what your program is doing (-1 point per missing comment, 2 points possible)
- Skip one blank line before every single-line comment (1 point possible)
- Use jGRASP's Generate CSD to properly indent and align your code
- 2 points - Identifier Names
- Use meaningful variable names for all Java variables used (-1 point per problem, 2 points possible)
- Variable identifier names should use lower camel casing (begin with a lower case letter, and each subsequent word should start with an upper-case letter)
- Avoid the use of abbreviations in choosing variable names
- 2 points - Creation of Assignment Folder, File, and Printouts
- File
ChangeMaker.java saved in folder U:\programs\program2\ correctly (1 point possible)
- Test case table and hand-calculated values submitted correctly (1 point possible)