JAVA HELP Using the following variables write program statem
JAVA HELP:::
Using the following variables, write program statements to calculate and print out the total value of the money.
int numQuarters, numDimes, numNickels, numPennies; // entered by the user
double totalValue; // calculated by your code
Note that you do not need to write the code that would read the values in from the user- you can just use these four variables.
For example, if
numQuarters = 3
numDimes = 4
numNickels = 2
numPennies = 7
Your code would calculate totalValue to be 1.32.
Use good design principles, including constants.
Solution
CalculateTotValue.java
import java.util.Scanner;
public class CalculateTotValue {
public static void main(String[] args) {
//Declaring constants
final double QUARTERS=0.25,DIMES=0.10,NICKELS=0.05,PENNIES=0.01;
//Scanner class object is used to read the inputs entered by the user
Scanner sc=new Scanner(System.in);
//Declaring variables of type double
double no_quarters,no_dimes,no_nickels,no_pennies,total;
//Getting the no of quarters entered by the user
System.out.print(\"Enter no of Quarters :\");
no_quarters=sc.nextDouble();
//Getting the no of dimes entered by the user
System.out.print(\"Enter no of Dimes :\");
no_dimes=sc.nextDouble();
//Getting the no of nickels entered by the user
System.out.print(\"Enter no of Nickels :\");
no_nickels=sc.nextDouble();
//Getting the no of pennies entered by the user
System.out.print(\"Enter no of Pennies :\");
no_pennies=sc.nextDouble();
//calculating the total value
total=no_quarters*QUARTERS+no_dimes*DIMES+no_nickels*NICKELS+no_pennies*PENNIES;
//displaying the total value
System.out.println(\"Total value is :\"+total);
}
}
______________________
Output:
Enter no of Quarters :3
Enter no of Dimes :4
Enter no of Nickels :2
Enter no of Pennies :7
Total value is :1.32
___________Thank You

