Program 4
Making Change
- Assigned: Fri 2/1
- Due: Fri 2/8 – submit both paper copy and via Sakai
- Possible points: 4
Description
Do the programming project from chapter 2 that asks you to determine the change to be dispensed from a vending machine. This is on page 131 problem 10 (in all 3: Pearson Custom Publishing, 6th edition, and 5th edition). Use only branches (NOT integer division and modulus). There is one extra requirement: if the price is less than $0.25 or greater than $1.00, print “!!! Invalid price” and give no change. Sample output.
Enter price of item (from 25 cents to a dollar, in 5-cent increments): 35 price = 35 change = 65 2 quarters 1 dimes 1 nickelsSome tips:
- You must use branches only. You may not use integer division (/) nor the modulus operator (%). This means you can not start with the sample solution in Listing 2-12. If you know what a loop is, don't use them. Branches only.
- As with all programs, first download the skeleton.
- These are the requirements for the Implementation and Test plans you should include at the beginning of your code:
- Implementation plan: break your program into 4-8 very small steps. Describe each step in one brief statement. For example, one step might be “Calculate amount of change to be returned” or “Count number of quarters”. Note that when you run Source/Format in Eclipse, it may reformat your comment putting the line breaks where it wants. You won't be able to write your implementation plan as a nice, aligned and bulleted list as shown in the skeleton.
- Test plan: You should think out test cases to run that produce all legal numbers of quarters (e.g. 3, 2, 1, and 0), dimes, and nickels. The first test in the skeleton
price change q d n 25 75 3 0 0
covers 3 possibilities (q=3, d=0, n=0) all in one test.
- Do not write a branch for every possible combination of change. Doing this is considered the “brute force” method and will not get much credit. There are much cleaner and shorter ways to complete this assignment.
Requirements
Turn in the following:- Print out your code and submit it in class following the general guidelines. All sections (including Implementation Plan and Test Plan) are required for this assignment
- Submit your code to Sakai
- The skeleton has a new block of comments at the start of the class definition. You will need to fill this in with your name, etc.
Grading
- 50% Correctness
- 25% Implementation plan. Logical, well organized and broken into very small steps. 6-8 steps is appropriate.
- 25% Thorough testing of the correctness of your program.
- Up to 25% may be deducted if the program is not written in good programming style – indentation, clarity, descriptive names, simplicity, etc.
Objectives
- Proper use of branches. Think out thorough testing.