Question
British Purse Sophie and Sally are learning about money. Every once in a while, their parents will give them penny or shilling coins (no pounds
British Purse
Sophie and Sally are learning about money. Every once in a while, their parents will give them penny or shilling coins (no pounds at their age!). They each keep their money in a special purse, and their parents may ask them how many pence or shillings coins they have. (Note we're not interested in the monetary values, just the number of coins. Thus someone might have 25 shilling coins or 20 penny coins.) The interaction between the girls' parents and Sophie and Sally is similar to the following:
Enter 1 for Sophie, 2 for Sally, or 0 to exit: 1
Enter 1 to give pence, 2 to give shillings, 3 to query her purse: 1
Enter the pence to give: 3
Enter 1 for Sophie, 2 for Sally, or 0 to exit: 2
Enter 1 to give pence, 2 to give shillings, 3 to query her purse: 2
Enter the shillings to give: 2
Enter 1 for Sophie, 2 for Sally, or 0 to exit: 2
Enter 1 to give pence, 2 to give shillings, 3 to query her purse: 2
Enter the shillings to give: 1
Enter 1 for Sophie, 2 for Sally, or 0 to exit: 1
Enter 1 to give pence, 2 to give shillings, 3 to query her purse: 3
The purse has 3 pence, 0 shillings
Enter 1 for Sophie, 2 for Sally, or 0 to exit: 2
Enter 1 to give pence, 2 to give shillings, 3 to query her purse: 3
The purse has 0 pence, 3 shillings
Enter 1 for Sophie, 2 for Sally, or 0 to exit: 0
To get started, consider the following questions:
What are the major nouns of the scenario? Sophie, Sally, parents, pence, shilling, coin, purse
What are the relationships between these nouns?
Sophie and Sally each have purses. Having a Daughter or Child object might be possible, but in this scenario the only thing interesting about Sophie and Sally is that they each have a purse. We can treat them as names of different purse objects (i.e., they are variables of type Purse).
the parents are really just a euphemism for the user of the program. We have to interact with the user, but don't need a specific class.
pence and shillings are coins, but they also just count something--the int data type will represent them just fine
a purse contains pence and shillings, and we also need to add pence and shillings to a purse, and fetch its number of pence and shilling coins. This looks like an object.
Write a program to implement this scenario. Use two classes. One class should contain a main method and manage the dialog with the user (suggested class name BritishPurseTest). The other class should represent a Purse (suggested class name BritishPurse). The design of the Purse class is up to you. Make sure that your instance variables are private, follow the naming conventions, etc.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started