Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Purse 1. Implement a class Purse. A purse contains a collection of coins. For simplicity, we will only store the coin names in an ArrayList

Purse

1. Implement a class Purse. A purse contains a collection of coins. For simplicity, we will only store the coin names in an ArrayList.

a. Supply a method

void addcoin(String coinName)

that adds a coin to the purse.

b. Write a method toString() to the Purse class that prints the coins in the purse in the format

Purse[Quarter, Dime, Nickel, Dime]

2. Write a method reverse that reverses the sequence of coins in a purse. Use the toString method of the preceding assignment to test your code. For example, if reverse is called with a purse

Purse[Quarter, Dime, Nickel, Dime]

Then the purse is changed to

Purse[Dime, Nickel, Dime, Quarter]

3. Write a method for the Purse class,

public void transfer(Purse other)

that transfers the contents of one purse to another. For example, if a is

Purse[Quarter, Dime, Nickel, Dime]

and b is

Purse[Dime, Nickel]

then after the call, a.transfer(b), a is

Purse[Quarter, Dime, Nickel, Dime, Dime, Nickel]

and b is empty.

4. Write a method for the Purse class

public boolean sameContents(Purse other)

That checks whether the other purse has the same coins in the same order.

5. Write a method

public boolean sameCoins(Purse other)

that checks whether the other purse has the same coins, perhaps in a different order. For example, the purses

Purse[Quarter, Dime, Nickel, Dime]

and

Purse[Nickel, Dime, Dime, Quarter]

should be considered equal. You will probably need one or more helper methods.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Spatial Database Systems Design Implementation And Project Management

Authors: Albert K.W. Yeung, G. Brent Hall

1st Edition

1402053932, 978-1402053931

More Books

Students also viewed these Databases questions

Question

What are four principles of effective post project reviews?

Answered: 1 week ago

Question

5. List the forces that shape a groups decisions

Answered: 1 week ago

Question

4. Identify how culture affects appropriate leadership behavior

Answered: 1 week ago