• 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 ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

question in a beginning java problem

 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If I understand correctly, do just as you described. First create a method named display and move the code that you currently have in paint() to it:

Then change paint() to call display():

Notice that I made display take a reference to a Graphics object as a parameter. This allows paint() to pass the correctly configured object on to it.

If you have any more questions let us know.

Layne

HTH
 
kanaka tam
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

Keep Coding!

Layne

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 ]
 
BWA HA HA HA HA HA HA! Tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic