Question: Write a class CoinPurse with the following attributes: in Java a. CoinPurse purseName b. Number of quarters c. Number of dimes d. Number of nickels

Write a class CoinPurse with the following attributes: in Java

a. CoinPurse purseName

b. Number of quarters

c. Number of dimes

d. Number of nickels

e. Number of pennies

Create appropriate constructor, accessor, mutator, toString and equals methods. The equals() method returns true if the each CoinPurse has the same number of coins of each type (name doesnt matter. In the constructor use set methods to set the each of the values. The constructor should be a set of int parameters defining the number of quarters, dimes, nickels and pennies. If a number less than 0 is supplied in any parameter just leave the default value for the parameter. Also create a default constructor that sets the number of coins of each type to 1 and the purseName to DefaultPurse.

Also code the following methods for this class.

a. totalAmount - returns total value in the purse as a double

b. moneyFromQuarters returns the amount of money in quarters as a double

c. moneyFromDimes returns the amount of money in dimes as a double

d. moneyFromNickels returns the amount of money in nickels as a double

e. moneyFromPennies returns the amount of money in pennies as a double

Create a class CoinPurseClient to test the CoinPurse class.

a. Read in a purse name and a set of quarters, dimes, nickels and pennies.

b. Construct a CoinPurse and test all the methods except equals().

c. Create a second CoinPurse using the default method.

d. Print out the second CoinPurse using toString().

e. Compare the first CoinPurse to the second CoinPurse using the equals method and print out the result.

f. Set the values of the second CoinPurse equal the values of the first CoinPurse using accessor and mutator methods as appropriate

g. Print out the second CoinPurse using toString().

h. Compare the first CoinPurse to the second CoinPurse using the equals method and print out the result. Sample Output: Please enter the purse name: Super Saver Please enter number of quarters, dimes, nickels and pennies: 5 6 4 8

Demonstrating the get() methods:

The number of quarters of coins in purse Super Saver is 5

The number of dimes of coins in purse Super Saver is 6

The number of nickels of coins in purse Super Saver is 4

The number of pennies of coins in purse Super Saver is 8 Demonstrating toString() In the coin purse Super Saver:

The number of quarters is: 5

The number of dimes is: 6

The number of nickels is: 4

The number of pennies is :8 Demonstrating valuation methods

Total purse value for Super Saver is $2.13

Amount from quarters for Super Saver is $1.25

Amount from dimes for Super Saver is $0.60

Amount from nickels for Super Saver is $0.20

Amount from pennies for Super Saver is $0.08 In the coin purse DefaultPurse:

The number of quarters is: 1

The number of dimes is: 1

The number of nickels is: 1

The number of pennies is :1

Super Saver and DefaultPurse do not have the same coin set

The updated Default Purse:

In the coin purse DefaultPurse:

The number of quarters is: 5

The number of dimes is: 6

The number of nickels is: 4

The number of pennies is :8

Super Saver and DefaultPurse have the same coin set

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!