Reference no: EM13940639
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.
Complete the following class in your solution:
import java.util.ArrayList;
/**
A purse holds a collection of coins.
*/
public class Purse
{
private ArrayList<String> coins;
/**
Constructs an empty purse.
*/
public Purse()
{
coins = new ArrayList<String>();
}
/**
Add a coin to the purse.
@param coinName the coin to add
*/
public void addCoin(String coinName)
{
. . .
}
/**
Returns a string describing the object.
@return a string in the format "Purse[coinName1,coinName2,...]"
*/
public String toString()
{
. . .
}
/**
Determines if a purse has the same coins in the same
order as another purse.
@param other the other purse
@return true if the two purses have the same coins in the
same order, false otherwise
*/
public boolean sameContents(Object other)
{
. . .
}
}
Use the following class as your tester class:
/**
This class tests the Purse class.
*/
public class PurseTester
{
public static void main(String[] args)
{
Purse a = new Purse();
a.addCoin("Quarter");
a.addCoin("Dime");
Purse b = new Purse();
b.addCoin("Quarter");
b.addCoin("Dime");
System.out.println(a.sameContents(b));
System.out.println("Expected: true");
Purse c = new Purse();
c.addCoin("Nickel");
c.addCoin("Dime");
c.addCoin("Nickel");
Purse d = new Purse();
d.addCoin("Nickel");
d.addCoin("Dime");
d.addCoin("Quarter");
System.out.println(c.sameContents(d));
System.out.println("Expected: false");
Purse e = new Purse();
e.addCoin("Nickel");
e.addCoin("Dime");
e.addCoin("Nickel");
Purse f = new Purse();
f.addCoin("Nickel");
f.addCoin("Dime");
System.out.println(e.sameContents(f));
System.out.println("Expected: false");
}
}
Minimise the chance of something going wrong
: How can the team use project management tools to minimise the chance of something going wrong? This section should be approximately 400 words long plus relevant diagrams.
|
Determine which cost separation methods is being used
: Determine which of the following cost separation methods is being used: the high-low method, the scattergraph method, or the method of least squares.
|
Introduction we presented gas mileage data
: In the chapter introduction we presented gas mileage data for 2000 and 2009 model year compact cars. We will use histograms and back-to-back stem-and-leaf plots to compare the mileage between these two groups of cars. The following tables present the..
|
If sinking fund cash is used to purchase investments
: If sinking fund cash is used to purchase investments, those investments are reported on the balance sheet as marketable securities.
|
Write a method for the purse class
: 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.
|
Fifo inventory costing method
: The company uses the FIFO inventory costing method, and it computes a new, monthly, fixed manufacturing overhead rate based on the actual number of meals produced that month. All costs and production levels are exactly as planned.
|
Company produces a variety of stationery products
: Tyrone Company produces a variety of stationery products. One product, sealing wax sticks, passes through two processes: blending and molding. The weighted average method is used to account for the costs of production.
|
How many agencies were involved in the investigation
: How many agencies were involved in the investigation? Which agency was in charge? Were any political figures involved or participating: Who were they and what role did they play?
|
Java nearest neighbor algorithm
: I need a java class named "Topology" that includes methods "NearestNeighbor" and "RandomNeighbor".
|