I need help with and array for a program that acts like a cash register. The user will input an items price and then there payment. It will tell you the change and then tell you what kinda of change to use, see example:
Use JOptionPane to take inputs from the user and display the results.
Example:
--------
If the user enters
Amount Due = 5.52 // First Input from the User
Amount Given = 10.00 // Second Input from the User
Calculate the Balance Due
Balance Amount = $ 4.48
and display the balance due in denomination as (The following four lines will be ONE Output to the user)
$1 bill = 4 (4.00)
Quarters = 1 (0.25)
Dimes = 2 (0.20)
Pennies = 3 (0.03)
This last part, where you display the change that will be given back, ie: how many quarters, dimes, nickels, pennies is the part I am having problems with.
Can some one help? Please pardon my coding abilities, I am still learning how to do this and would really appreciate any help you can with my program.
Thanks in advance.
import javax.swing.*;
import java.text.*;
public class CashReg
{ //Start
public static void main (String [] args)
{ //Start Main
int count = 0;
char c1 = 0;
String price = null;
String payment = null;
String change = null;
boolean correct = false;
while(!correct)
{ //Start Loop
price = JOptionPane.showInputDialog (null,"Enter the amount of the item for purchase");
if (price.length() < 1) //Loop
{
JOptionPane.showMessageDialog (null, "You did not enter a purchase amount, try again please.");//Error message
}
payment = JOptionPane.showInputDialog (null,"Enter your payment amount.");
if (payment.length() < 1) //Loop
{
JOptionPane.showMessageDialog (null, "You did not enter a payment amount, try again please.");//Error message
}
else
{
correct = true; //Boolean to confirm that there are enough characters
}
}
for (int i=0; i<price.length(); i++)
{
if (Character.isUpperCase(price.charAt(i)))
{
count++;
}
} //End loop
// response = price - payment;
JOptionPane.showMessageDialog (null, "You item costs "+price+" and you payed "+payment+" and your change will be "+change);
System.exit(0);
} //End Main
} //End