Java program 3. Write a Java program that repeatedly asks the user to enter two
ID: 3665658 • Letter: J
Question
Java program
3. Write a Java program that repeatedly asks the user to enter two monetary amounts expressed in old- style British currency: pounds, shillings, and pence then converts to decimal pounds. There were 20 shillings to a pound, and 12 penceto a shilling. The notation for this old system used the pound sign, and two decimal points, so for example, £5.2.8 meant 5 pounds, 2 shillings, and 8 pence. Today's decimal pound system consists of only pounds and pence, with 100 pence to a pound (like U.S. dollars and cents). Thus, £5.2.8 in the old notation is £5.133 in decimal pounds. Let the user run the program as many times as they wish and check case on Y/Ninput. Output the result to two decimal places. Output should look similar to below. Sample Run Enter pounds 7 Enter shillings 17 Enter pence 9 Decimal pounds £7.89 Run again (Y/N)? N Hint: The pound symbol f is (decimal 163).Explanation / Answer
Program:
import java.util.Scanner;
public class Pounds {
private static Scanner sca;
public static void main(String arg[])
{
char choice;
int pound,shilling,pence;
double decimal_pound=0.0;
sca = new Scanner(System.in);
do
{
System.out.print(" Enter Pounds: ");
pound=sca.nextInt();
System.out.print(" Enter Shillings: ");
shilling=sca.nextInt();
System.out.print(" Enter Pence: ");
pence=sca.nextInt();
decimal_pound+=pound;
decimal_pound+=(shilling+pence/12.0)/20.0;
System.out.printf("Decimal Pounds : £%.2f",decimal_pound);
System.out.println(" Run Again (Y/N)? : ");
choice=sca.next().charAt(0);
}while(choice=='Y' || choice=='y');
}
}
Result:
Enter Pounds: 7
Enter Shillings: 17
Enter Pence: 9
Decimal Pounds : £7.89
Run Again (Y/N)? :
y
Enter Pounds: 7
Enter Shillings: 17
Enter Pence: 12
Decimal Pounds : £15.79
Run Again (Y/N)? :
N
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.