• Post Reply Bookmark Topic Watch Topic
  • New Topic

Need some help on some Java Homework  RSS feed

 
Ren Erene
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. Programming Exercise: Purse
Implement a class named Purse. A purse contains a collection of coins. For simplicity, we will only store the
coin names in an ArrayList<String> . In the Purse class, you should:
(1) Supply a method
public void addCoin(String coinName)
This method add one coin name to the ArrayList .
(2) Supply a method
public String toString()
This method returns a string that contains the coins in the purse in the following format
Purse[Quarter, Dime, Nickel, Dime]
(3) Supply a method
public void reverse()
This method reverses the sequence of coins in a purse.
For example, if the reverse method is called with a purse
Purse[Quarter, Dime, Nickel, Dime]
, then the purse is changed to
Purse[Dime, Nickel, Dime, Quarter]
(4) Supply a method
public void transfer(Purse other)
This method 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.transer(b), a is
Purse[Quarter, Dime, Nickel, Dime, Dime, Nickel]
, and b is empty
(5) Supply a method
public boolean sameContents(Purse other)
This method checks whether the other purse has the same coins in the same order.
For example, if a is
Purse[Quarter, Dime, Nickel, Dime]
, and b is
Purse[Quarter, Dime, Nickel, Dime]
,then the call a.sameContents(b) returns true
Also, implement the PurseTester class to test the above methods of the Purse class


I'm struggling with Arrays and need help badly!
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ren Erene wrote:1. Programming Exercise: Purse
Implement a class named Purse. A purse contains a collection of coins. For simplicity, we will only store the
coin names in an ArrayList<String> . In the Purse class, you should:
(1) Supply a method
public void addCoin(String coinName)
This method add one coin name to the ArrayList .
(2) Supply a method
public String toString()
This method returns a string that contains the coins in the purse in the following format
Purse[Quarter, Dime, Nickel, Dime]
(3) Supply a method
public void reverse()
This method reverses the sequence of coins in a purse.
For example, if the reverse method is called with a purse
Purse[Quarter, Dime, Nickel, Dime]
, then the purse is changed to
Purse[Dime, Nickel, Dime, Quarter]
(4) Supply a method
public void transfer(Purse other)
This method 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.transer(b), a is
Purse[Quarter, Dime, Nickel, Dime, Dime, Nickel]
, and b is empty
(5) Supply a method
public boolean sameContents(Purse other)
This method checks whether the other purse has the same coins in the same order.
For example, if a is
Purse[Quarter, Dime, Nickel, Dime]
, and b is
Purse[Quarter, Dime, Nickel, Dime]
,then the call a.sameContents(b) returns true
Also, implement the PurseTester class to test the above methods of the Purse class


Email me back at [DELETE] to communicate with me 1-1 I have a template formed for the code. I'm struggling with Arrays and need help badly!



Welcome to the ranch. Please note that JavaRanch is a learning site... as such we expect you to ShowSomeEffort. Also, since other users can learn form this, we also expect you to UseTheForumNotEmail.

So.... what have you done so far? And what issues are you running into?

Henry
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!