192k views
2 votes
The Coins class was created to hold all your loose change, kind of like a piggy bank! For this exercise, you are going to simulate starting a bank with a specific number of coins, then adding to your piggy bank to bring your total to $2.12. What you need to do: Create a Coins object that initially has 4 quarters, 3 dimes, 2 nickels, and 1 penny. After you create the initial object, print out the total, then add coins to your bank until you have a total of 15 coins totaling 2.12. You will need to figure out which combination gets you to the correct total with the correct number of coins! When you are finished, call the method to print the bank count then the bank total to verify that you got the correct values.

1 Answer

4 votes

Final answer:

To simulate a piggy bank with the Coins class, start with a value of $1.41 from 4 quarters, 3 dimes, 2 nickels, and 1 penny, then add 2 quarters, 2 dimes, and 6 pennies to reach a total of 15 coins and $2.12.

Step-by-step explanation:

To start a simulated piggy bank with the Coins class, first we need to determine the value of the initial coins: 4 quarters (4 x $0.25 = $1.00), 3 dimes (3 x $0.10 = $0.30), 2 nickels (2 x $0.05 = $0.10), and 1 penny ($0.01). This gives a starting total of $1.41.

To reach exactly $2.12 with a total of 15 coins, we need to add coins worth $0.71, while the total number of added coins is 10 (since we start with 10 coins). One possible combination to reach a total of $2.12 with 15 coins is to add 2 quarters ($0.50), 2 dimes ($0.20), and 6 pennies ($0.06). With this, the total value would be $1.41 + $0.50 + $0.20 + $0.06 = $2.12 and the total number of coins would be 4+2 quarters, 3+2 dimes, 2 nickels, and 1+6 pennies, which equals 15 coins.

Once you have the right amount, you would call the method to print the bank count and then the bank total to confirm your values.

User Ayush Khare
by
8.8k points