If input is 0, your output should be:
Your amount is zero
If input is -2000.25, your output should be:
Your amount is negative
If input is 23.67, your output should be:
Your amount 23.67 consists of
23 dollars
2 quarters
1 dime
1 nickel
2 pennies
this is my attempt at it any help would be greatly appreciated
______________________________________...
import javax.swing.JOptionPane;
public class homework3 {
public static void main(String[] args) {
double number;
double dollar = 1;
double quarter = .25;
double dime = .10;
double nickel = .05;
double penny = .01;
double numDollars = 0;
double numQuarters = 0;
double numDimes = 0;
double numNickels = 0;
double numPennies = 0;
String input = JOptionPane.showInputDialog
("Please enter the amount.");
number = Double.parseDouble(input);
double total = number;
while(number > 0){
if(number - dollar>= 0){
numQuarters ++;
total -= dollar;
continue;
}
if(number - quarter>= 0){
numQuarters ++;
total -= quarter;
continue;
}
if(number - dime >= 0){
numDimes ++;
total -= dime;
continue;
}
if(number - nickel >= 0){
numNickels ++;
total -= nickel;
continue;
}
if(number - penny >= 0){
numPennies ++;
total -= penny;
continue;
}
if ( total == 0 ){ break;
}
JOptionPane.showMessageDialog( null, "The amount $" + number + "consist of/n" + numDollars + " Dollars/n" + numQuarters +" Quarters/n" + numDimes + " Dimes/n" + numNickels + " Nickels/n"+ numPennies + " Pennies");
System.exit(0);
}
if( number == 0.0) {
JOptionPane.showMessageDialog( null,"No Change");
}
else if( number < 0.0) {
JOptionPane.showMessageDialog( null,"Amount is Negative");
}
else
JOptionPane.showMessageDialog( null,"not working");
System.exit(0);
}
}
Tags: