Hi all I am having some issues with an assignment I need some guidance with the red wording the rest I have been able to finish. Give me a hint or something....thanks
Write a Java program that modifies Example 2.4, “Computing Changes.” Display the non-zero denominations only. Display singular words for single units like 1 dollar and 1 penny, and display plural words for more than one unit like 2 dollars and 3 pennies. (Use 23.67 to test your programs.) If the user enters zero or a negative amount, your program should exit properly and display a message stating that the amount entered by the user was zero or negative.
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
//I have coded the above and added it to this I just cannot figure out or wrap my head around the task
//below if anyone could help me out in my mind it seems simple but for some reason I cant make it work
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
Important Notes : The input and output must use JOptionPane dialog and display boxes.
// ComputeChange.java: Break down an amount into smaller units import javax.swing.JOptionPane; public class ComputeChange { /** Main method */ public static void main(String[] args) { double amount; // Amount entered from the keyboard // Receive the amount entered from the keyboard String amountString = JOptionPane.showInputDialog(null, "Enter an amount in double, for example 11.56", "Example 2.4 Input", JOptionPane.QUESTION_MESSAGE); // Convert string to double amount = Double.parseDouble(amountString); int remainingAmount = (int)(amount * 100); if(amount == 0){ String message1= String.format("Your amount is zero."); JOptionPane.showMessageDialog(null, message1); System.exit(0);} if(amount < 0){ String message2= String.format("Your amount is negative."); JOptionPane.showMessageDialog(null, message2); System.exit(0);} // Find the number of one dollars int numOfOneDollars = remainingAmount / 100; remainingAmount = remainingAmount % 100; // Find the number of quarters in the remaining amount int numOfQuarters = remainingAmount / 25; remainingAmount = remainingAmount % 25; // Find the number of dimes in the remaining amount int numOfDimes = remainingAmount / 10; remainingAmount = remainingAmount % 10; // Find the number of nickels in the remaining amount int numOfNickels = remainingAmount / 5; remainingAmount = remainingAmount % 5; // Find the number of pennies in the remaining amount int numOfPennies = remainingAmount; // Display results String output = "Your amount " + amount + " consists of \n" + numOfOneDollars + " dollars\n" + numOfQuarters + " quarters\n" + numOfDimes + " dimes\n" + numOfNickels + " nickel\n" + numOfPennies + " pennies"; JOptionPane.showMessageDialog(null, output, "Example 2.4 Output", JOptionPane.INFORMATION_MESSAGE); System.exit(0); } }