• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Cant find variable and how do I get the rest of my ATM to work?

Ranch Hand
Posts: 105
Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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:

Posts: 23907
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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...


pie. tiny ad:
Thread Boost feature
    Bookmark Topic Watch Topic
  • New Topic