Hi all, so I am relatively new to java, just started a class this year and overall I like it. However, every so often, my teacher gives us a project which gives me some issues. This week, she wants us to create an ATM machine, which has a log in, a pin to enter, and after those two steps, the options to check account balance starting at 0 dollars, the option to deposit any amount of money, and the option to withdraw money only by multiples of 20 dollars. The account is not allowed to go negative. Then an option to logout must also be present. However, I am having some issues. I have accomplished the login steps that were requested, however, the options in the account for balance, withdraw, and deposit do not work. If anyone could help me fix these issues, it would be very much appreciated. I have been working on separating my code into methods too, so I am not putting lot and lots of code into my launcher class, as I know that is an issue I have, so feel free to criticize me there as well. My main problem right now when I try to compile is I get an error telling me that it cannot find my options variable. Although, I believe there may be more problems after that issue is fixed. Here is my code:
From the code shown, you seem to ... well ... to start, do you know the difference between a local variable, an instance variable, and a static variable?
First, your aTMTester class contains lots of instance variables, but you are trying to access them like they are static variables. You can't do that -- as the scope of a static method doesn't have the this reference needed to access the instance variable. Also, this is probably the major cause of many complaints by the compiler.
Second, the instance variables of the aTMTester class are never initialized.... but .... I am going to speculate that you have a deeper issue here. I speculate that you are confusing the instance variable of the aTMTester class with the local variables of the main() method of the aTMLauncher class. These are two different sets of variables. Setting one doesn't affect the other. In rereading the code, it looks like you never declared the set of local variables in the main() method of the aTMLauncher class (that I referred to). So, I struck out the paragraph above.
Second, you are attempting to access private variables of the aTMTester class from the aTMLauncher class without any context. You simply can't do that. For example, the compiler can't figure out that when you want to access the deposit variable in the main() method, you mean the instance variable of a completely different class. You actually have to tell the compiler which class (and for instance variables, which instance) these variables are located.
Perhaps, it would be a good idea to start with the Oracle tutorial on variables...