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

  Correct example of inheritance

Which of the following relationships is not a correct example of inheritance?  Parent to Children  Aunt to Uncle  Grandparent to Grandchild

  Create set methods for color and height, but not for price

Create a class for the business named Candle that contains data fields for color, height, and price. Create get methods for all three fields

  Which parts of the assignment were you not able to complete

Which parts of the assignment were you not able to complete fully? For each, explain why you were unable to complete this part and what steps you took to attempt to complete it. Give me as much detail as possible such that I may award partial cred..

  Program that allows a user to input coordinates

In Java make a program that allows a user to input coordinates as to make a Hexagon via an array, and my professor has set the standards of: Write a class Polygon which draws a hexagon for a set of numbers given by the user.

  Give an implementation of the queue adt using an array

Give an implementation of the Deque ADT using an array, so that each of the update methods run in O(1) time. Program has to be written in Java.

  Are scripting languages such as javascript better choice

Based on Keston (2008), does the C++ programming language have a role in developing Web 2.0 application solutions based on service-oriented architectures (SOA)? Explain why or why not. Are scripting languages such as JavaScript Perl or Python bett..

  Program called power that displays the positive powers

Write a program called Power that displays the positive powers of 2. When the user enters the exponent at a prompt, the program displays 2 to that power. The program halts when the user enters -1

  Constructs a rectangle object

Write an AreaTester program that constructs a Rectangle object and then computes and prints its area. Use the getWidth and getHeight methods. Also print the unexpected answer.

  Write a java application that reads a file containing text

Write a Java application that reads a file containing text. Your program should read each line and display it on the console screen preceded by line numbers.

  Write a static method named showtwos

Write a static method named showTwos

  Create menu-based programs using guis

You will learn how to create menu-based programs using GUIs. Please respond to all of the following prompts with 1-2 paragraphs of original content: Discuss GUI components, explain how to handle key and mouse events, and state how they relate to GU..

  Write a method that takes a string as input and returns

Write a method that takes a String as input and returns the reverse of that String. Then write a second method that uses the first method to test whether or not an input String is a palindrome.

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