{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Project7_making_change

Project7_making_change - Project 7 Making Change This...

Info icon This 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.
Image of page 1

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

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

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern