Campbell Ritchie wrote:I can see other things:
Your indentation is inconsistent; you are changing from K&R indentation to Allman indentation and back surprisingly quickly. Inconsistent indentation will confuse you into misreading your own code. Also always precede { at the end of the line by whitespace. Your cash() method is no use to the other code. It doesn't tell other code whether you have any money, and the hard‑coded amount may become inaccurate.
Carey Brown wrote:I don't see where you are calling miniStatement().
Ganesh Patekar wrote:Manish Pamnani,
I have merged your newly created topic into this topic to maintain it's integrity. Please don't create multiple threads for the same problem. I hope that helps.
Carey Brown wrote:Look at every place your variable "three" is used. None of them are calling setuserName().
Not only method miniStatement() but also all other setter and getter methods too. When you create a new object which will have It's own separate fields like userName, userBalance etc. you have to assign values to these fields by invoking methods like setuserName(" userName"), setatmPin(...) etc on each object referred by one, two and three reference variables.Manish Pamnani wrote:if I want to create new users then everytime I have to call the method miniStatement with a new object?
Please excuse my sloppy handwriting.
We know field userName of object referred by one is set to "Manish" so prints Manish but you haven't set any values to other fields of object referred by one hence If you try to print any other fields of this object by invoking getter method on reference variable one like both prints 0 since we haven't set any values to these variables so they have default value 0 because atmBalance and atmPin are of int type.Manish Pamnani wrote:
Ganesh Patekar wrote:
We know field userName of object referred by one is set to "Manish" so prints Manish but you haven't set any values to other fields of object referred by one hence If you try to print any other fields of this object by invoking getter method on reference variable one like both prints 0 since we haven't set any values to these variables so they have default value 0 because atmBalance and atmPin are of int type.Manish Pamnani wrote:
Each object have their own fields so you have to set them by invoking appropriate setter methods, to get values invoke getter methods and other method too like miniStatement and cash too on every object you create.
As Carey Brown suggested It's good to use constructor to initialize these fields and use toString method to print output.
If you haven't understood yet please go through The Java™ Tutorials: What Is an Object and What Is a Class?
Manish Pamnani wrote:. . . but i couldn't figure out a way to make the "atmBalance" variable static so that it could be shared among all objects of ATM we create?
Humans and their filthy friendship brings nothing but trouble. My only solace is this tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
|