ICS 111 Homework Assignment H02: Calculate Change

Purpose

We are going to continue our problem-solving education by writing a program that helps a cashier calculate the correct change. This will help us understand how Java does integer math and explore the division and modulus operators.

We will also get more practice using Eclipse to make our programming life easier.

Tasks

1. Create a package named edu.ics111.h02 in your project

This is where we will put all our classes for homework 02. To create a package right mouse click on the project, choose new, then choose package. new package

2. Create a program to help a cashier calculate the correct change.

Write a program that helps a cashier calculate the correct change. The program should ask how much the item cost. Then ask how much was paid. The program should tell the cashier how many dollars, quarters, dimes, nickels and pennies they should give the customer as change.

Now use the ICS 111 Programming Algorithm to start the problem-solving process.

1. Read and understand the problem.

Do you understand what the program needs to do?

2. Create the Java file for your program and insert the Java boilerplate

I’ve chosen to call my program CorrectChange, so I’m going to create the Java class CorrectChange in the homework 02 package by clicking File -> New -> Class then filling out the dialog box you see next.

CorrectChange

Make sure you click the public static void main(String[] args) option and the ‘Generate comments’ option. Here is what my Eclipse gave me.

CorrectChange Class

As you can see I need to fill out the comments for the program and main subroutine.

Now you should have the boilerplate code now you can start working on solving the problem.

3. Write the steps to solve the problem as comments in main and refine them

“What are the steps needed to solve this problem?” Write them down as comments in the main method. Once you have the steps start refining them till you can write Java code.

An example of the running program might look like:

How much does the item cost?
1.30
How much was paid?
5
The change is 3 dollars, 2 quarters, 2 dimes, 0 nickels, and 0 pennies.

Grading Rubric

CriterionExcellent (100%)Satisfactory (75%)Borderline (50%)Unsatisfactory (25%)Poor (0)
Adherence to standards - 2 points
Does it conform to standards in every detail?
No errors. Minor details of the assignment are violated, or poor choices are made where the assignment is unclear. Significant details of the assignment or the underlying program intent are violated, but the program still fulfills essential functions. Significant details of the assignment or the underlying program intent are violated, but the program still fulfills some essential functions. Misses the point of the assignment.
Breakdown (modular design) - 1 point
Does it demonstrate good modular design?
No errors. 1-3 minor errors. > 3 minor errors OR 1 major error. 2 major errors > 2 major error.
Correctness of code - 5 points
Does it work? Does it pass JUnit?
Passes all tests. Works for typical input, may fail for minor special cases. Fails for typical input, for a minor reason. Fails for typical input, for a major reason. No.
Documentation, and style - 2 points
Is it clear and maintainable? Does it pass CheckStyle?
No errors. 1-3 minor errors. > 3 minor errors OR 1 major error. 2 major errors > 2 major error.

Turning in the Assignment

The assignment is due on Friday, September 10th at 11:55pm. You may turn it in early.