ITEC 120
HW3: Billls and Coins, improved

Academic Integrity

Be reminded that this homework assignment must be your own work.

Objectives

After successfully completing this assignment you will be able to incorporate if statements into your programs.

Assignment

Now that you have if statements, you could use them to make decisions in your program. For this assignment, you will refine the program you wrote for Lab02b, Bills and Coins, to make the output better.

You may copy your Money.java file from Lab02b to start this assignment. Call this one BillsCoins.java (be sure to change your class name to match.)

You'll change the output in three ways:

 

Here are several possible outputs for this program (user input in red):

Please enter dollars: 40
Please enter cents: 25

40 dollars and 25 cents is:

     2 twenty dollar bills
     1 quarter

Notice there are no lines of output for tens, fives, ones, dimes, nickels, or pennies. Also, there is only 1 quarter, so the output says "quarter" instead of "quarters". There are two twenty dollar bills, so, bills is plural. Here's another run of the program:


Please enter dollars: 43
Please enter cents: 15

43 dollars and 15 cents is:

     2 twenty dollar bills
     3 one dollar bills
     1 dime
     1 nickel

Here is what will happen in the case of invalid input. (These are three separate runs):


Please enter dollars: -5
Please enter cents: 45

-5 is an invalid number of dollars.



Please enter dollars: 9
Please enter cents: -4

-4 is an invalid number of cents.



Please enter dollars: -5
Please enter cents: -6

-5 is an invalid number of dollars.
-6 is an invalid number of cents.

Notice that if one input is negative, we see a message about that input before the program terminates. If both are invalid, we will see both messages before the program terminates.

 

Testing

Test your program for all possible combinations of bills and coins. Make sure you see both singular and plural output for all bills and coins. And test your error conditions (invalid inputs).

 

Submit Your Assignment

Submit your BillsCoins.java to the HW3 dropbox on D2L.