I am doing my first program assignment for Java Early Objects that involves counting change. I have the program working(which is all we need) but I'm being a little OCD about the dialog box. Is there a way to get the text box next to "Price of Item: "? I have tried just putting the cost string in there with a comma or plus but both return an error.
Thanks for helping.
Here's my code:
import javax.swing.JOptionPane;
public class GideonchangeJP {
public static void main(String[] args) {
int cost;
int change;
int quarters;
int dimes;
int nickels;
int qremainder;
int dremainder;
final int credit = 100;
String inputString;
inputString = JOptionPane.showInputDialog("Credit $1.00" +
"\nPrice of Item: ");
cost = Integer.parseInt(inputString);
change = credit - cost;
quarters = change/25;
qremainder = change%25;
dimes = qremainder/10;
dremainder = qremainder%10;
nickels = dremainder/5;
JOptionPane.showMessageDialog(null, "Your change is: " + change + " Cent(s)\n" +
quarters + " Quarter(s)\n" +
dimes + " Dime(s)\n" +
nickels + " Nickel(s)");
System.exit(0);
}
}

New Topic/Question
Reply



MultiQuote




|