Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

change machine programming

  Asked By: Harry    Date: Nov 28    Category: Java    Views: 3825
  

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 */
}

}

Share: 

 

4 Answers Found

 
Answer #1    Answered By: Guadalupe Rogers     Answered On: Nov 28

Looks like you don't close your makeChange method.

 
Answer #2    Answered By: Gustavo Taylor     Answered On: Nov 28

Where would I put  the closing bracket?
Thank you sooooo much for all of your time and help by the way!

 
Answer #3    Answered By: Velma Adams     Answered On: Nov 28

I marked the spot where you need to put  it, it is below.

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;
}


}******** Bracket here *******


/*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  */ }

}

 
Answer #4    Answered By: Wilbur Hall     Answered On: Nov 28

Even after the closing bracket in that place I have a
feeling that the code will be wrong....I think that
the JVM is throw an error about return  types mis match

 
Didn't find what you were looking for? Find more on change machine programming Or get search suggestion and latest updates.




Tagged: