Can someone help me with this Sophie and Sally are learning

Can someone help me with this?

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. The other class should represent a Purse. The design of the Purse class is up to you. Make sure that your instance variables are private, follow the naming conventions, etc.

Solution

import java.util.Scanner;
class BritishPurse
{
public static void main (String args[])
{
Scanner in = new Scanner(System.in);
int p1=0,p2=0,s1=0,s2=0,choice=0, c1=0, c2=0, d1=0,d2=0;
do
{
System.out.println(\"Enter 1 for Sophie 2 for Sallie, or 0 to exit: \");
choice=in.nextInt();
switch (choice)
{
case 1 :
System.out.println(\"Enter 1 to give pence, 2 to give shillings, 3 to query her purse: \");
c1=in.nextInt();
if (c1==1)
{
System.out.println(\"Enter the pence to give: \");
d1=in.nextInt();
p1=p1+d1;
}
else if(c1==2)
{
System.out.println(\"Enter the shillings to give: \");
d1=in.nextInt();
s1=s1+d1;
}
else if (c1==3)
{
System.out.println(\"The purse has \"+p1+\" pence and \"+s1+\" shillings.\");
  
}
break;

case 2 :
System.out.println(\"Enter 1 to give pence, 2 to give shillings, 3 to query her purse: \");
c2=in.nextInt();
if (c2==1)
{
System.out.println(\"Enter the pence to give: \");
d2=in.nextInt();
p2=p2+d2;
}
else if(c2==2)
{
System.out.println(\"Enter the shillings to give: \");
d2=in.nextInt();
s2=s2+d2;
}
else if(c2==3)
{
System.out.println(\"The purse has \"+p2+\" pence and \"+s2+\" shillings.\");

}
break;
case 0 :
System.out.println(\"Successfully exited from program.\");
break;

}
}while (choice !=0);
}
}

Can someone help me with this? Sophie and Sally are learning about money. Every once in a while, their parents will give them penny or shilling coins (no pounds
Can someone help me with this? Sophie and Sally are learning about money. Every once in a while, their parents will give them penny or shilling coins (no pounds

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site