Please write this Java program as simple as possible and with comments throughou
ID: 3881591 • Letter: P
Question
Please write this Java program as simple as possible and with comments throughout explaining what's happening. Thanks! Exercise 5: Write a Java program (name it Lab2Exercise5)that determines the values of coins in a jar and prints out the total dollars and cents. The program prompts the user to enter the number of coins (quarters dimes, nickels, and pennies). Print out the number of coins entered for each coin type on separate lines followed by the total amount of money in the jar as dollars and cents, such as: Total = 321 Dollars and 34 Cents. Use proper labels for all outputs and comment your code properly.Explanation / Answer
import java.util.Scanner;
public class Lab2Exrcise5
{
public static void main(String[] args)
{
int quarters; // Number of quarters, to be input by the user.
int dimes; // Number of dimes, to be input by the user.
int nickles; // Number of nickles, to be input by the user.
int pennies; // Number of pennies, to be input by the user.
double dollars; // Total value of all the coins, in dollars.
Scanner s=new Scanner(System.in);
/* Ask the user for the number of each type of coin. */
System.out.println("Enter the number of quarters: ");
quarters = s.nextInt();
System.out.println("Enter the number of dimes: ");
dimes = s.nextInt();
System.out.println("Enter the number of nickles: ");
nickles = s.nextInt();
System.out.println("Enter the number of pennies: ");
pennies = s.nextInt();
/* Add up the values of the coins, in dollars. */
dollars = (0.25 * quarters) + (0.10 * dimes)
+ (0.05 * nickles) + (0.01 * pennies);
/* Report the result back to the user. */
System.out.println("The total in dollars is $" + dollars);
} // end main()
} // end class