Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create a class that calculates and displays the conversion of an entered number

ID: 3897246 • Letter: C

Question

Create a class that calculates and displays the conversion of an entered number of dollars into currency denominations - 100s, 50s, 20s, 10s, 5s, and 1s. Obtain all inputs and display all outputs using dialog boxes. Save the class as Dollars.Java.

Code Example:

import javax.swing.*;

public class Test{

public static void main(String [] args){

    double dblInput = 0.0;
    int intInput = 0;
    String rawInput;

    rawInput = JOptionPane.showInputDialog(null, "Please enter a double value. Example: 33.44");
    dblInput = Double.parseDouble(rawInput);
    System.out.println("The value entered is: " + dblInput);

    rawInput = JOptionPane.showInputDialog(null, "Please enter an int value. Example 231");
    intInput = Integer.parseInt(rawInput);
    System.out.println("The value entered is: " + intInput);

    System.exit(0);
}
}

Explanation / Answer

Please let me knownif you have any issue

import javax.swing.*;

publicclass Dollar {

public static void main(String[] args) {

int lInputAsInt = 0;

int lRemainder = 0;

String lInput;

String output = "";

lInput = JOptionPane.showInputDialog(null, "Please enter a dollar amount: ");

lInputAsInt = Integer.parseInt(lInput);

output = output + "The value entered is $" + lInputAsInt + " ";

output = output + "100s: " + (lInputAsInt / 100) + " ";

lRemainder = lInputAsInt % 100;

output = output + " 50s: " + (lRemainder / 50) + " ";

lRemainder = lRemainder % 50;

output = output + " 20s: " + (lRemainder / 20) + " ";

lRemainder = lRemainder % 20;

output = output + " 10s: " + (lRemainder / 10) + " ";

lRemainder = lRemainder % 10;

output = output + " 5s: " + (lRemainder / 5) + " ";

lRemainder = lRemainder % 5;

output = output + " 1s: " + lRemainder + " ";

// printing on console. Remove if not needed

System.out.println(output);

// printing using dialog box. Remove if not needed

JOptionPane.showMessageDialog(null, output);

System.exit(0);

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote