Question: Java file name: HW3_Bills.java Write a program that asks the user for an amount and calculates and print the minimum number of bills of 20,10,5,


Java file name: HW3_Bills.java Write a program that asks the user for an amount and calculates and print the minimum number of bills of 20,10,5, and 1 needed to pay that amount. In order to use the minimum number of bills, you must pay as many bills of 20 as possible, and then the largest number of bills of 10 and so on. Logic/ Processing steps: Compute and store the max number of bills of 20. Hint: this is the same as asking how many times can I fit 20 into my amount? Compute the remaining amount. Hint: This is the remainder of dividing the amount by 20. Compute and store the max number of bills of 10. Compute the remaining amount. Compute and store the max number of bills of 5. Compute the remaining amount. Note that this amount that could not be payed with 20,10 and 5) can only be payed with bills of 1, so this is how many bills of 1 are needed. Print table formatted (aligned) as shown in the sample run. In particular the cells for the number of bills should have a width of 4 spaces. (E.g. see how the number of bills of 20 in sample run 1 (30) and in sample run 2 (3) do not miss align the table cells.) Prints the total number of bills given (of any value). Hints: 1. You should save the number of each bills since you need to use it (to print) twice. 2. A cell in the last row in the table will have nothing printed when the number of bills is 0 and a number otherwise. What Java instruction allows you to choose to do one action or another based on data? 3. To 'print nothing' you can print an empty string ("") or a string with just a space in it(""). 4. You can print a SINGLE line in Java with SEVERAL printf statements. It does not have to be a single printf. Consider using different printf() for the cell for each bill. So one printf will print "2" and another will print "1", etc. Finally, for the last line, note that as you print the cell, you will have either a number or a space to print. --- Sample run 1: This program will calculate the minimum number of bills of 20,10,5, and 1 needed to pay a given amount. Enter the integer amount that you need to pay: 619 - -- - - - -- - - -- | Bill value 1 20 10 5 1] Num of bills | 30 | Num of bills | 30. 11 11. - - 11 11. - - - - - 4| 41 - - - - - - - - -- - - - - - - - Total bills: 36 Bye --- Sample run 2: This program will calculate the minimum number of bills of 20,10,5, and 1 needed to pay a given amount. Enter the integer amount that you need to pay: 74 | Bill value 1 20 10 5 11 - - - -- - - Num of bills | 31 10 0 4 | Num of bills | 31. 1 I 4|| ------------- Total bills: 8 Bye
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
