Notices
Results 1 to 2 of 2

Thread: Need help in java program!

  1. #1 Need help in java program! 
    New Member
    Join Date
    Mar 2010
    Posts
    1
    Okay well I usually can figure most of these out on my own but this time I can't. We learned a new lesson in class and I was absent for. Also this program is due tomorrow and I dont even know where to begin so any help would be greatly appreciated.

    Heres the problem (it is problem 10-6 from the "Fundamentals of Java" textbook):
    Design a bank hierarchy for bank accounts. The concrete types of accounts are checking accounts, savings accounts, and credit accounts. Common behavior includes deposits, withdrawls, and obtaining a balance. Credit and savings accounts have an interest rate. Credit accounts have a credit line or maximum amount that may be borrowed. Be sure your design includes the appropriate interface, abstract class, and concrete class.

    Again, thank you so much if you would take the time to help. I just need to know where to get started cause this hierarchy stuff is very confusing to me. If you want to contact me directly my email is shaq1565@aim.com


    Reply With Quote  
     

  2.  
     

  3. #2  
    Forum Freshman
    Join Date
    Feb 2010
    Posts
    84
    I'm not going to design the whole thing for you. But the general idea is that you want to "abstract" the common features of your data types into a Base Class, and then extend that class to add the specific elements and behaviors needed by each type.

    So, start with an Account base class:
    Account -- has methods to add, subtract, set, and get a balance amount.

    Then extend Account for each specific kind of thing:
    CheckingAccount -- pretty much just a basic Account
    InterestAccount -- add methods to set, get, and calculate interest

    Then extend InterestAccount for your two types
    SavingsAccount -- pretty much just an InterestAccount
    CreditAccount -- probably adds monthly fees and such to calculations

    In Java one does it like this:

    public abstract class Account
    {
    public void addAmount( double dollars )
    {
    // do stuff
    }
    // more methods
    // ...
    }

    public class CheckingAccount extends Account
    {
    // add or change anything you need from Account
    // ...
    }

    // etc...


    Reply With Quote  
     

Bookmarks
Bookmarks
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •