65.7k views
0 votes
Write a programme that reads three integer values from the keyboard using the Scanner class, representing

respectively, a number of quarters, dimes, and nickels. Convert the total coin amount to dollars and
output the result.

User Dh YB
by
7.8k points

1 Answer

3 votes

Final answer:

To write a program that reads three integer values from the keyboard using the Scanner class, representing a number of quarters, dimes, and nickels, and convert the total coin amount to dollars, you can follow the steps explained in this answer.

Step-by-step explanation:

To write a program that reads three integer values from the keyboard using the Scanner class, representing a number of quarters, dimes, and nickels, and convert the total coin amount to dollars, you can follow these steps:

Here's an example code snippet:


import java.util.Scanner;

public class CoinConverter {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);

System.out.print("Enter the number of quarters: ");
int quarters = scanner.nextInt();

System.out.print("Enter the number of dimes: ");
int dimes = scanner.nextInt();

System.out.print("Enter the number of nickels: ");
int nickels = scanner.nextInt();

int totalCents = (quarters * 25) + (dimes * 10) + (nickels * 5);
double totalDollars = totalCents / 100.0;

System.out.println("Total amount in dollars: " + totalDollars);
}
}

User Lucas Walter
by
8.1k points