• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • paul wheaton
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Tim Holloway
  • Carey Brown
  • salvin francis

Need some help to put me in the right direction

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Someone can close this topic if they want.
 
Ranch Hand
Posts: 874
Android VI Editor Java
  • 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 VI Editor Java
  • 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.
 
Marshal
Posts: 65411
248
  • 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
Marshal
Posts: 65411
248
  • 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
Marshal
Posts: 65411
248
  • 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
Marshal
Posts: 65411
248
  • 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.
 
Bartender
Posts: 11445
18
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • 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
Marshal
Posts: 65411
248
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maneesh is correct. Please reinstate the original text.
 
author
Posts: 23838
141
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux 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
 
I'm a lumberjack and I'm okay, I sleep all night and work all day. Lumberjack ad:
Enterprise-grade Excel API for Java
https://products.aspose.com/cells/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!