ITEC 120
L02b: Bills and coins

Objectives

After successfully completing this lab you will be able to develop programs that use variables and expressions.

Assignment

Develop a program named Money that determines how an amount of money can be represented using bills and coins. To make the problem easier to solve, break it into two parts.

Part 1: Bills only

First, solve the problem of bills only. Prompt the user for a dollar amount, then print out how many twenties, tens, fives, and ones would be needed to make that amount.

Here's an example output of this program:

Enter a dollar amount: 57

57 dollars is:
     2 twenty dollar bills
     1 ten dollar bills
     1 five dollar bills
     2 one dollar bills

Your program prints the text in black, the user inputs the text in red. Hint: it's easier if you read the dollar amount in as an integer.

Part 2: Coins too

Once you have that much working, add code to prompt the user for the number of cents, and print the number of quarters, dimes, nickels, and pennies that would be needed to make that amount. You can do this in a similar fashion to the first part. Once again, it will be easier if you read in the number of cents as an integer. A sample run of the program with both parts working might look like this:

Enter dollars: 57
Enter cents: 49

57 dollars and 49 cents is:
     2 twenty dollar bills
     1 ten dollar bills
     1 five dollar bills
     2 one dollar bills
     1 quarters
     2 dimes
     0 nickels
     4 pennies

A note about grammer

In the English language, we would not say "1 ten dollar bills". It is possible to write a program which would output "1 ten dollar bill" instead, but that would require a conditional statement, which we haven't learned yet. So don't worry about grammer on this lab, but once we cover conditionals, we'll handle this sort of thing.

Extra Credit

For 2 extra lab points, prompt the user only once for dollars and cents, and read the amount as a floating point number, then report bills and coins needed to make that amount. A run of this program might look like this:

Enter an amount of money: 57.49

$57.49 is:
     2 twenty dollar bills
     1 ten dollar bills
     1 five dollar bills
     2 one dollar bills
     1 quarters
     2 dimes
     0 nickels
     4 pennies

Submit Your Assignment

Part 1: bills only, is worth 5 points. Part 2, coins, is worth 5 points. The extra credit part is worth an additional 2 points. Submit your program, Money.java to the L02b dropbox on D2L.