aspose file tools*
The moose likes Beginning Java and the fly likes Need some help to put me in the right direction Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Need some help to put me in the right direction" Watch "Need some help to put me in the right direction" New topic
Author

Need some help to put me in the right direction

eric hayth
Greenhorn

Joined: Apr 09, 2009
Posts: 7
Someone can close this topic if they want.
Balu Sadhasivam
Ranch Hand

Joined: Jan 01, 2009
Posts: 874


Eric , Welcome to Javaranch.



I can find the total of all the transactions but not the sum of just the deposits



If you just need sum of deposits , better have a instance variable "deposits" and sum each time deposits is made .
eric hayth
Greenhorn

Joined: Apr 09, 2009
Posts: 7
Thanks a bunch


Resolved.
Balu Sadhasivam
Ranch Hand

Joined: Jan 01, 2009
Posts: 874



You are welcome and welcome here !!
eric hayth
Greenhorn

Joined: Apr 09, 2009
Posts: 7
Thanks!

Now I need to find the accounts that have overdrawn. Good luck to me.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40059
    
  28
Welcome to JavaRanch, Eric Hayth

Please avoid vague thread titles; we need to know what the thread is about.

SELECT name, number FROM account WHERE balance < 0;

Oh, no, that is how you would do it in SQL for a database We all learn how to do that sort of thing in Java whereas databases are more suitable for that sort of data. </naughty digression>

You need to iterate through all your Accounts and find which have a balance < 0. By analogy with your other methods you will probably end up working out the total balances in overdrawn accounts, or a count of how many are overdrawn.

You might do better to add this method to the Account classThe correct implementation will be shorter than what I wrote.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40059
    
  28
By the way, in your method which averages interest rates, where does the 4 come from? You cannot expect there always to be 4 accounts.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40059
    
  28
Do you really want the methods to find how many accounts are overdrawn in the Account class? It sounds like something which ought to be in the Bank class. And the Bank class should have the Account[] as a field.
eric hayth
Greenhorn

Joined: Apr 09, 2009
Posts: 7
There is no bank class I am just messing with the account class. I fixed the code so now we know how many accounts there are.
I would like the methods


eric hayth
Greenhorn

Joined: Apr 09, 2009
Posts: 7
Would it start something like this?


Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40059
    
  28
No. The withdraw method is void, so it doesn't return a result which you can compare to 0. That bit of code probably won't compile. Anyway, you need a method in the Account class.

I would suggestI have already dropped hints about the isOverdrawn() method; you should find it easy to implement.

If you are learning OO programming, set up a Bank class with the Account[] array as a field and methods to count total balances in all accounts, etc. That is what you need to get used to, using several classes together. You can probably copy most of the methods almost unchanged from what you have got working so far After all, you have corrected the problem with that averaging method OK
eric hayth
Greenhorn

Joined: Apr 09, 2009
Posts: 7
Can someone help me with the concept of "flags". I need to have in this piece of code a flag to check if there are any overdrawn accounts, and if there are display the accounts. It does that now, but what if there are no accounts that are overdrawn.


eric hayth
Greenhorn

Joined: Apr 09, 2009
Posts: 7
I got someone to help me out. Thanks to everyone that helped me.
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10535
    
    9

Please do not erase the topic contents after you got the solution.

It makes it very difficult for others to understand what the original topic was about. Also, in future, other people who might have the same problem and are looking for a solution would not benefit from it.


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40059
    
  28
Maneesh is correct. Please reinstate the original text.
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 19073
    
  40

eric hayth wrote:Someone can close this topic if they want.


With the previous version of the JR forum, some topics used to get deleted as soon as the question has been answered. And unless someone actually paid attention, no one knew that the topic originator "peed into the well that he just drank from". With this version of the forum, it is not possible to delete the topic.

Don't be selfish. Topic are to help others that may have similar issues too... And some people don't like to help selfish people. Please restore the question.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Need some help to put me in the right direction