• 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
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

Trying to create OO based bank app

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

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
Posts: 954
4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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:
 
Marshal
Posts: 80867
505
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 954
4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Marshal
Posts: 80867
505
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 954
4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Marshal
Posts: 80867
505
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have you tried a Map<Class<?>, Penalty> ?
 
Tushar Goel
Ranch Hand
Posts: 954
4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Marshal
Posts: 80867
505
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is the access of getPenaltyMap...? Is it package‑private? I presume only the Account classes are in that package.
 
Tushar Goel
Ranch Hand
Posts: 954
4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Marshal
Posts: 80867
505
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I still don't understand why minimum balance can't be a class attribute.
 
Tushar Goel
Ranch Hand
Posts: 954
4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Marshal
Posts: 80867
505
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And why can't those be static fields of the individual account classes?
 
Sheriff
Posts: 17734
302
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Tushar Goel
Ranch Hand
Posts: 954
4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Marshal
Posts: 80867
505
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 954
4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 954
4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
[Thumbnail for FlowDiagram.PNG]
General
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic