Write a method for the purse class

Assignment Help JAVA Programming
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");
}
}

Reference no: EM13940639

Questions Cloud

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".

Reviews

Write a Review

JAVA Programming Questions & Answers

  Recursive factorial program

Write a class Array that encapsulates an array and provides bounds-checked access. Create a recursive factorial program that prompts the user for an integer N and writes out a series of equations representing the calculation of N!.

  Hunt the wumpus game

Reprot on Hunt the Wumpus Game has Source Code listing, screen captures and UML design here and also, may include Javadoc source here.

  Create a gui interface

Create GUI Interface in java programing with these function: Sort by last name and print all employees info, Sort by job title and print all employees info, Sort by weekly salary and print all employees info, search by job title and print that emp..

  Plot pois on a graph

Write a JAVA program that would get the locations of all the POIs from the file and plot them on a map.

  Write a university grading system in java

University grading system maintains number of tables to store, retrieve and manipulate student marks. Write a JAVA program that would simulate a number of cars.

  Wolves and sheep: design a game

This project is designed a game in java. you choose whether you'd like to write a wolf or a sheep agent. Then, you are assigned to either a "sheep" or a "wolf" team.

  Build a graphical user interface for displaying the image

Build a graphical user interface for displaying the image groups (= cluster) in JMJRST. Design and implement using a Swing interface.

  Determine the day of the week for new year''s day

This assignment contains a java project. Project evaluates the day of the week for New Year's Day.

  Write a java windowed application

Write a Java windowed application to do online quiz on general knowledge and the application also displays the quiz result.

  Input pairs of natural numbers

Java program to input pairs of natural numbers.

  Create classes implement java interface

Interface that contains a generic type. Create two classes that implement this interface.

  Java class, array, link list , generic class

These 14 questions covers java class, Array, link list , generic class.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd