0

was wondering where im going wrong, any ideas?

Modifying variable value from method

Implement a method empty() in the TicketMachine class that simulates the effect of removing all money from the machine It should have a void return type and the body should simply set the total variable/field to zero.

Does this method need any parameters? No

Is this method a mutator or accessor? mutator

Paste the whole method into the space below

public void empty(int return) 
{ 
balance = 0; 
}

Mark: 0 out of 3

Comments:

* Test 1 (0.0 out of 3)



TicketMachine.java:26: <identifier> expected
  public void empty(int return)
                        ^
  TicketMachine.java:60: ')' expected
  }
  ^
  2 errors

The output should have been:

      No it doesn't need parameters 
       and it is a mutator
      TicketMachine emptied successfully

This is what was actually produced:

      Exception in thread "main" java.lang.NoClassDefFoundError: TicketMachine

3 Answers 3

1

You called your method parameter return:

public void empty(int return) 

which is a reserved keyword in Java hence the error above. Rename the parameter...

Sign up to request clarification or add additional context in comments.

2 Comments

OP mentions that the method shouldn't have parameters. They are putting things between the () and apparently doesn't understand that those are parameters in Java.
Sorry, not sure what you mean. What or who is OP?
1

The question seems to indicate that there should be no parameters.

public void empty() {
balance = 0;
}

6 Comments

ive try'd that before, in return i got TicketMachine.java:28: cannot find symbol symbol : variable balance location: class TicketMachine balance = 0; ^
Is there anymore code? The sample that you have supplied does not have enough detail to be able to fully answer your question. I assumes that there was a variable in the TicketMachine class because it was referred to in your sample code.
ive added the full programs code, hopefully it could make it easier
The variable definitions have been commented out. You need to move add a / afer the final * in the top comment . As it exists this code will not even compile.
i did that because iwas playing around with the code, but evene without it being hidden this error still pops up and im still confused
|
0

I have no idea what you're actually asking. But one of the problems might be that return in Java is a reserved word. I can't imagine this ever compiled as you have it. Change it to something else (return0 maybe?) and see if that fixes your problem.

1 Comment

TicketMachine.java.28: cannot find symbol\ symbol : variable balance location: class TicketMachine balance = 0; ^ i get that error

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.