GeeCON Prague 2014*
The moose likes Java in General and the fly likes Trying to create OO based bank app Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Java in General
Bookmark "Trying to create OO based bank app" Watch "Trying to create OO based bank app" New topic
Author

Trying to create OO based bank app

Tushar Goel
Ranch Hand

Joined: Dec 29, 2013
Posts: 254
Campbell...Really? It is what you wrote earlier minus the == true bit. Well, as near as I could remember it, anyway.

Yes it is

Campbell....I thought we had discussed reopening a closed account, in which case that method should throw an Exception.

Yes we did but i put this check on another methods instead of setActivate() method itself.

Junilu
Don't get down on yourself or apologize for not knowing any better.....................Here's a search that brings up a few, including JavaRanch's own style

Thanks for motivating and sharing the links. I read java ranch style guide and update my code accordingly. I have update setActivate method as below



Tushar Goel
Ranch Hand

Joined: Dec 29, 2013
Posts: 254
I tried to make a penalty system:

Penalty will be applicable for 2 cases:
1) If minimum balance is not maintained and this checked on Quarterly basis. I will do this later.
2) If over withdraw happened.





PenaltyRule:
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39073
    
  23
Surely the method should take the amount as an argument and be called on the Account object.
Would you have a static penalty amount in the Account class; different subclasses can have different penalties? That would make the penalty the same for all instance of a particular type of account.
Tushar Goel
Ranch Hand

Joined: Dec 29, 2013
Posts: 254
ould you have a static penalty amount in the Account class; different subclasses can have different penalties?

I tried to have that implemented but in this case i always getting penalty value from parent class.

I tried to have simple example as well but result is same:


It always print 5. So i can not use but i think i need to define static methods and have to override them
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39073
    
  23
The static method is declared in class A so it uses the field in class A. Remember things static are not polymorphic. Their values are statically linked before run‑time. Things polymorphic (=instance methods) are linked dynamically at run‑time. I think it is because of static linking that they chose the keyword static.
Tushar Goel
Ranch Hand

Joined: Dec 29, 2013
Posts: 254
then we cannot have static penalty amount in the Account class so that different subclasses can have different penalties because we defining all methods (deposit, withdraw etc)
or call (penalty or interest etc) from account class itself so it always uses value from the parent not subclasses.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39073
    
  23
Have you tried a Map<Class<?>, Penalty> ?
Tushar Goel
Ranch Hand

Joined: Dec 29, 2013
Posts: 254
Thanks Campbell... I made below changes:


Account class I have removed other variables from the account constructor to check if implementation of penalty is correct. If its correct then other will be implemented in same way


SavingAccount One of the type of account
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39073
    
  23
What is the access of getPenaltyMap...? Is it package‑private? I presume only the Account classes are in that package.
Tushar Goel
Ranch Hand

Joined: Dec 29, 2013
Posts: 254
Yes, it is package private. the package name is 'onlinebanking' and all classes except utility and test classes in it.

So should i initialize all other things like minimum balance , interest rate etc like this ?
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39073
    
  23
I still don't understand why minimum balance can't be a class attribute.
Tushar Goel
Ranch Hand

Joined: Dec 29, 2013
Posts: 254
because like Penalty , minimum balance is also variable. Each type of account having different minimum balance. Say Saving type of account have 504 minimum
but the Salary account have 0 minimum balance etc. (Actually in real life i am having both type of accounts and they have same amount of minimum balance)
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39073
    
  23
And why can't those be static fields of the individual account classes?
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4474
    
    6

Have a look at Martin Fowler's analysis patterns for accounting: http://martinfowler.com/apsupp/accounting.pdf

It might help you see the different possibilities for organizing your code and concepts if you read through this article and Fowler's examples. One of the more interesting things about these patterns is that some things that you may think should be implemented as attributes of an object can actually be treated as "rules". For example, a minimum balance rule can be applied to some types of accounts, applied differently for others, and perhaps not at all for some.


Junilu - [How to Ask Questions] [How to Answer Questions]
Tushar Goel
Ranch Hand

Joined: Dec 29, 2013
Posts: 254
Campbell Do you mean this?






Have a look at Martin Fowler's analysis patterns

Thanks for sharing the link Junilu, Yes, i am checking the same and get back to the post...


Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39073
    
  23
I haven't had the time to read that Martin Fowler link, but I never knew about it before.

Might be worth reading the Martin Fowler link and digesting it before doing anything else.
Tushar Goel
Ranch Hand

Joined: Dec 29, 2013
Posts: 254
I found it to be little bit difficult to understand but i am still trying to understand what Martin wanted to convey, it will take some more time.. So, please be with me...
Tushar Goel
Ranch Hand

Joined: Dec 29, 2013
Posts: 254
Hi, Sorry for delay. I am quite busy with personal and official commitment so could not able to spare much time.

Thanks Junilu, for the link it is very good. As per doc, i have re-modified my application... This looks like as per screenshot. Please suggest.



[FlowDiagram.PNG]

 
GeeCON Prague 2014
 
subject: Trying to create OO based bank app