Site Navigation

Site Search

CS 110: Program 2

Student Learning Objectives


Write the Java program 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

  1. 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 PaidAmount OwedChange Returned
Total ChangeDollarsQuartersDimesNickelsPennies

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

  1. 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 file to your account's U:\programs\program2 folder to receive a score on the assignment
  2. 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.
  1. Include inline comments for every three to five lines of code
    • Skip one blank line before every inline comment
  2. 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

Grading Criteria

20 points -- CS 110 Program 2 Grading Sheet (PDF)