Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

WNNrite a class called Purse. Purse should have the following: three int instance variables: pounds, shillings and pence. a no argument constructor ( i .

WNNrite a class called Purse. Purse should have the following: three int instance variables: pounds, shillings and pence. a no argument constructor (i.e., Purse()) that initializes the instance variables to 0.
a mutator method void addPounds(int poundsToAdd)
a mutator method void addShillings(int shillingsToAdd) You may assume shillingsToAdd is less than 20.
Note that if addShillings increases the number of shillings to 20 or more, the pounds value should be increased until shillings is less than 20.
a mutator method void addPence(int penceToAdd) You may assume penceToAdd is less than 12. Note that if addPence increases the number of pence to 12 or more, the shillings value should be increased until pence is less than 12.
an accessor method int getPounds() that returns the number of pounds in the purse an accessor method int getShillings() that returns the number of shillings (<20) in the purse.
an accessor method int getPence() that returns the number of pence (<12) in the purse.
a mutator method void spend(int poundsToRemove, int shillingsToRemove, int penceToRemove) that removes the specified amount of money from the purse. You may assume the purse has sufficient total funds to cover the withdrawal, though you may have to break a pound into shillings, or a shilling into pence.
an accessor method String toString() that returns a String representation of the purse (such as "pounds 3, shillings 10, pence 5")
Create : A tester class, PurseTester, is attached for your use. PurseTester has only a single main method, and does the following: creates two Purse objects, sophie and sally has a loop whose body executes two times.
For each execution of the loop, it asks the user for the pounds, shillings and pence sophie and sally (each) should add to their purses ;displays the amount of money in each purse; asks the user for the pounds, shillings and pence sophie and sally (each) should spend; displays the amount of money in each purse

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Time Series Databases New Ways To Store And Access Data

Authors: Ted Dunning, Ellen Friedman

1st Edition

1491914726, 978-1491914724

More Books

Students also viewed these Databases questions

Question

What are Decision Trees?

Answered: 1 week ago

Question

What is meant by the Term Glass Ceiling?

Answered: 1 week ago