Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Java Expert


Home >> Java

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 coins;

/**
Constructs an empty purse.
*/
public Purse()
{
coins = new ArrayList();
}

/**
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");
}
}

Java, Programming

  • Category:- Java
  • Reference No.:- M91611512
  • Price:- $20

Priced at Now at $20, Verified Solution

Have any Question?


Related Questions in Java

Assessment -java program using array of Assessment -JAVA Program using array of objects

Assessment -JAVA Program using array of objects Objectives This assessment item relates to the course learning outcomes as stated in the Unit Profile. Details For this assignment, you are required to develop a Windowed G ...

Assessment instructionsin this assessment you will design

Assessment Instructions In this assessment, you will design and code a simple Java application that defines a class, instantiate the class into a number of objects, and prints out the attributes of these objects in a spe ...

Operating systems assignment -problem 1 sharing the bridgea

Operating Systems Assignment - Problem 1: Sharing the Bridge A new single lane bridge is constructed to connect the North Island of New Zealand to the South Island of New Zealand. Farmers from each island use the bridge ...

Assignment game prototypeoverviewfor this assessment task

Assignment: Game Prototype Overview For this assessment task you are expected to construct a prototype level/area as a "proof of concept" for the game that you have designed in Assignment 1. The prototype should function ...

Overviewyou are required to use java se 80 and javafx to

Overview You are required to use Java SE 8.0 and JavaFX to develop a Graphical User Interface (GUI) for the FlexiRent rental property management program created in Assignment 1. This assignment is designed to help you: 1 ...

Project requirementsfor the problem described in the next

Project requirements For the problem described in the next section, you must do the following: 1. include your student ID at the end of all filenames for all java code files. Three classes have been identified in section ...

Can someone please help me with the following java

can someone please help me with the following java question The input is an N by N matrix of nonnegative integers. Each individual row is a decreasing sequence from left to right. Each individual column is a decreasing s ...

Simple order processing systemquestion given the classes

Simple Order Processing System Question: Given the classes Ship (with getter and setter), Speedboat, and SpeedboatTest. Answer the following questions: Refine the whole application (all classes) and create Abstract class ...

Assignment - java program using array of objectsobjectives

Assignment - JAVA Program using array of objects Objectives - This assessment item relates to the course learning outcomes as stated in the Unit Profile. Details - For this assignment, you are required to develop a Menu ...

Answer the following question whats the difference public

Answer the following Question : What's the difference public inheritance and private inheritance? What can derived classes inherit from base classes? What cannot be inherited from base classes?

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As