This week's book giveaway is in the OCAJP forum.
We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!
See this thread for details.
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Need some help to put me in the right direction

 
eric hayth
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Someone can close this topic if they want.
 
Balu Sadhasivam
Ranch Hand
Posts: 874
Android Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a bunch


Resolved.
 
Balu Sadhasivam
Ranch Hand
Posts: 874
Android Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


You are welcome and welcome here !!
 
eric hayth
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks!

Now I need to find the accounts that have overdrawn. Good luck to me.
 
Campbell Ritchie
Sheriff
Pie
Posts: 49789
69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 49789
69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 49789
69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Would it start something like this?


 
Campbell Ritchie
Sheriff
Pie
Posts: 49789
69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I got someone to help me out. Thanks to everyone that helped me.
 
Maneesh Godbole
Saloon Keeper
Posts: 11092
13
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Campbell Ritchie
Sheriff
Pie
Posts: 49789
69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maneesh is correct. Please reinstate the original text.
 
Henry Wong
author
Marshal
Pie
Posts: 21409
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic