This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
I wrote the above program for simulating a bank account which works fine but the rule is that i should use display method for displaying the output and should put the code inside this method instead of where i have put it in paint and call the method inside paint(). I am not sure how to do that. Can anyone help me.. kanakatam
Layne, Thank you for your reply. But i did try that by putting the code in method display and tried to call inside paint. But the variables check and save are local variables to the class Lab7 and so i cannot use them inside the method display and call the method display inside paint() method. If i try to declare these variables local to Account class then it does not recognize savings and checking instances. Also i get error message "cannot resolve symbol" when using display(g) inside paint method. I am flustered now. Any help appreciated. Thanx kanakatam
Joined: Dec 06, 2001
After looking more closely at your code, it doesn't seem as nearly as simple as I thought when I first read your question. One of the problems is that I didn't notice that you already have a display() method in the Account class, but the paint() method is in Lab7 class. When you have two methods in different classes, it helps to use the class name along with the method to avoid confusion. So here we should talk about Account.display() and Lab7.paint() to clarify that the two methods are in different classes. This is the essential part I was missing with my previous comments. I thought that these two methods were in the same class
So to figure this out, let's back up for a minute? What exactly should Account.display() do? It seems likely, that it should display the information about a single Account. I would suggest that you figure out how to do this. Notice that the Account class doesn't need the variables check and save because, as you are using them in the Lab7 class, they represent the balances for two different accounts. But the Account class only represents a SINGLE account and it already has its own variable to keep track of that account's balance. In fact, you don't really need the check and save variables in Lab7 because those values are indirectly available through the saving and checking variables that represent each account.
So to reiterate, you should try to fill in Account.display() so that it prints the information for the "current account". Once you get that much, you can work on calling this method from Lab7.paint().
I hope this helps. Let us know what problems you encounter from there.
p.s. I'd also like to mention that saying "the variables check and save are local variables to the class Lab7" may be a little confusing to most Java programmers. I think I understand what you mean, but you are not using the term "local variables" correctly. To clarify, a local variable is one that is declared inside a method. Since check and save are declared in the class and outside any method, they are NOT local variables; they are "member variables". [ April 03, 2005: Message edited by: Layne Lund ]