OK I'm in my very first java programming class. My assignment is to create a program vendMachine.java basically we have to make a program that takes dollars and returns change for an item. Ive written out parts of the code but I'm so flipping confused i dont think Ill ever get this programming crap! Ive been at this for hours.
Anyway. my biggest problem is getting my program to compute change! I dont know how to approach this. any ideas? Here's what I've Got so far. I know its not much but please give me some startup advice as to how to compute change.
Thanks in advance.
PS. my professor says using the Modulous arithmetic operator will make this easier.
CODE
import javax.swing.JOptionPane;
public class vendMachine
{
public static void main (String[] args)
{ /*Below is the list of Variables used in this class.*/
double dollar = 1.00;
double quarter = 0.25;
double dime = 0.10;
double nickel = 0.05;
double penny = 0.01;
double Snickers = 0.34;
double MilkyWay = 0.34;
double AlmondJoy = 0.34;
String snackString;
JOptionPane.showMessageDialog (null, "This machine takes ONLY DOLLARS");
snackString = JOptionPane.showInputDialog
(null, "Type in your desired snack.\n Snickers\n MilkyWay\n AlmondJoy",
"Available Snacks", JOptionPane.INFORMATION_MESSAGE);
JOptionPane.showMessageDialog (null, "Your total is 34 Cents");
JOptionPane.showMessageDialog (null, "The number of Quarters is 2\nThe number of Dimes is 1\nThe number of nickles is 1\nThe number ofpennie's is 1");
}
}