Project7_making_change - Project 7 Making Change This...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Project 7 – Making Change This problem is based on an everyday situation, but it makes a good, simple example for programming. The task is to make change for an arbitrary purchase amount less than $50, using an optimal combination of pennies, nickels, dimes, quarters, one's, five's, ten's and twenties. Here's an example: I buy something for $15.37 and pay with a twenty dollar bill. I should get $4.63 in change. There are lots of possible ways to pay me my $4.63, but you know I'm going to be upset if you give me, say 463 pennies. By an “optimal” combination I mean the combination that results in my getting the fewest total coins and bills. So I don't want 3 ones, 4 quarters, 6 dimes and 3 pennies (unless I'm going to the laundromat). I want 4 ones, 2 quarters, 1 dime and 3 pennies. That's the fewest bills and coins you can give me that add up to $4.63. This problem is rendered a little more interesting than it might seem initially when you try to state, exactly and in the detailed language of a Javaprogram, exactly how to carry out something you can, as a human, do almost without thinking. The twists and turns may surprise you. Learning Objectives L2 - Primitive data types, arithmetic and relational operators. L4 – Collections (e.g. List, Queue) and Arrays L5 - Object-oriented principles using Java. L7 – Exception Handling Methods (if you do the extra credit portion) Please see the notes about using an array or other collection class to hold the bill and coin denominations, below. How to get started In our example, I need to give back $4.63 (a real number, by the way). Suppose I divide this amount by 20 (the largest bill I give in change). What will the result be? Zero.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 03/01/2012 for the course COP 2800 taught by Professor Geraldreed during the Spring '08 term at Valencia.

Page1 / 3

Project7_making_change - Project 7 Making Change This...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online