I can't figure out why this program won't work. It is supposed to be
a program for a change machine in a grocery store. It seems to all
work except for the public static void main part, it says that it is
an illegal start to the expression.
public class ChangeMachine {
public static boolean makeChange(int cents) {
//Shows what system does when no change is required
if (cents==0) {
System.out.println(" No Change Is Due") ;
return true;
}
//Change will only be given for positive numbers less than 99.
if ((cents <= 99) && (cents > 0)) {
System.out.println ("Dispensing " + cents + " cents:") ;
return true;
}
/*the below line is the one with the problems, illegal start of the
expression*/
public static void main(String args[]){
//Creating the ints of all of the coins
int quarters;
int dimes;
int nickles;
int pennies;
String ans;
final int RANGE=4;
//The number given by each of the coins is calculated
quarters = (cents / 25);
dimes = ((cents % 25) / 10);
nickles = (((cents % 25) % 10) / 5);
pennies = ((((cents % 25) % 10) % 5) / 1);
//It will print out the numbers given by each coin
if ((quarters) > (0)) {
System.out.println(" Quarters: " + quarters);
}
if ((dimes) > (0)) {
System.out.println(" Dimes: " + dimes);
}
if ((nickles) > (0)) {
System.out.println(" Nickles: " + nickles);
}
if ((pennies) > (0)) {
System.out.println(" Pennies: " + pennies);
}
//If number is not in the range given above, it will print out the
below statement.
else {
System.out.println( "Invalid Change Amount (" + cents + " cents)");
return false;
}
};
/*i don't know why, but for some reason it asked me to put a
semi-colon after the bracket above */
}
}