Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //import java.util.Scanner;
- import javax.swing.JOptionPane;
- public class Lab3YunpingCui {
- public static void main(String[] args) {
- // Create a Scanner
- // Scanner input = new Scanner(System.in);
- // Receive the amount
- // System.out.print("Enter an amount in double, for example 11.56: ");
- // double amount = input.nextDouble();
- String astr = JOptionPane.showInputDialog(null, "Enter an amount in double, for example 11.56");
- double amount = Double.parseDouble(astr);
- int remainingAmount = (int)(amount * 100);
- // Find the number of one dollars
- int numberOfOneDollars = remainingAmount / 100;
- remainingAmount = remainingAmount % 100;
- // Find the number of quarters in the remaining amount
- int numberOfQuarters = remainingAmount / 25;
- remainingAmount = remainingAmount % 25;
- // Find the number of dimes in the remaining amount
- int numberOfDimes = remainingAmount / 10;
- remainingAmount = remainingAmount % 10;
- // Find the number of nickels in the remaining amount
- int numberOfNickels = remainingAmount / 5;
- remainingAmount = remainingAmount % 5;
- // Find the number of pennies in the remaining amount
- int numberOfPennies = remainingAmount;
- // Display results
- //System.out.println("Your amount " + amount + " consists of");
- String msg = "Your amount " + amount + " consists of";
- if (amount == 0.0) {
- msg = msg + "\n" + ("\tNothing");
- }
- if (numberOfOneDollars == 1) {
- //System.out.println("\t" + numberOfOneDollars + " dollar");
- msg = msg + "\n" + ("\t" + numberOfOneDollars + " dollar");
- } else if (numberOfOneDollars > 1) {
- //System.out.println("\t" + numberOfOneDollars + " dollars");
- msg = msg + "\n" + ("\t" + numberOfOneDollars + " dollars");
- }
- if (numberOfQuarters == 1) {
- //System.out.println("\t" + numberOfQuarters + " quarter");
- msg = msg + "\n" + ("\t" + numberOfQuarters + " quarter");
- } else if (numberOfQuarters > 1) {
- //System.out.println("\t" + numberOfQuarters + " quarters");
- msg = msg + "\n" + ("\t" + numberOfQuarters + " quarters");
- }
- if (numberOfDimes == 1) {
- //System.out.println("\t" + numberOfDimes + " dime");
- msg = msg + "\n" + ("\t" + numberOfDimes + " dime");
- } else if (numberOfDimes > 1) {
- //System.out.println("\t" + numberOfDimes + " dimes");
- msg = msg + "\n" + ("\t" + numberOfDimes + " dime");
- }
- if (numberOfNickels == 1) {
- //System.out.println("\t" + numberOfNickels + " nickel");
- msg = msg + "\n" + ("\t" + numberOfNickels + " nickel");
- } else if (numberOfNickels > 1) {
- //System.out.println("\t" + numberOfNickels + " nickels");
- msg = msg + "\n" + ("\t" + numberOfNickels + " nickels");
- }
- if (numberOfPennies == 1) {
- //System.out.println("\t" + numberOfPennies + " pennie");
- msg = msg + "\n" + ("\t" + numberOfPennies + " pennie");
- } else if (numberOfPennies > 1) {
- //System.out.println("\t" + numberOfPennies + " pennies");
- msg = msg + "\n" + ("\t" + numberOfPennies + " pennies");
- }
- JOptionPane.showMessageDialog(null, msg);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement