Results 1 to 9 of 9
  1. #1
    LifeElixer is offline Member
    Join Date
    Apr 2011
    Posts
    15
    Rep Power
    0

    Default Bank program difficulties

    I'm having difficulties figuring out this part of this assignment given to me.

    I have a multi-class project to create a bank...etc.

    Classes:
    Bank
    Account(has-a relationship with Bank)
    Transaction(has-a relationship with account/ composition? i'm not highly educated on the whole has-a, is-a, composition type thing)
    "abstract" Customer
    and some other non-relative sub classes that don't matter at the moment.


    i'm attempting to make the Bank class and i have the following so far:

    Java Code:
    import java.util.Scanner;
    
    public class Bank
    {
      Scanner sc = new Scanner(System.in);
      private Account[] bankAccounts;
      
    
      public Bank()
      {
        bankAccounts = new Account[5];
        index = 0;
        numAcc = 0;
        int maxNumAcc = 5;
        }
      public void addAccount()
      {
        
        
      }
    and for my Account class i have(haven't included the getBalance getCustomer toString and setCustomer and etc yet):

    Java Code:
    public class Account
    {
      Transaction transactions[] = new Transaction[25];
      Customer customer;
      private String accountNumber;
      private double balance;
      
      public Account(double bal, String accNum)
      {
        balance = bal;
        accountNumber = accNum;
    
    /*getting an error for the following line: Cannot instantiate the typeCustomer? i do have a Customer class, how do i do this?**/
    
        customer = new Customer();
      }
    my question is...

    How do i add an Account using the addAccount method in the Bank class? I need to ask the user for the customer info somewhere and i have to ask the user if they want to make a SavingsAccount or CheckingAccount which are two more classes i have made..

    also is my constructor for my Account class correct? do i need to put Customer inside the parameter?

    If there's not enough detail or code here let me know, i'll try and explain it better. ~Thanks
    Last edited by LifeElixer; 10-20-2011 at 02:03 AM.

  2. #2
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,785
    Rep Power
    7

    Default Re: Bank program difficulties

    Yes you need to ask the user for information. In a driver class would be a good place. Once the info has been gathered you have two choices. Have the driver class create a new Account object and pass that to the addAccount method. Or pass the info to the addAccount method and have it create a new Account object.
    Last edited by Junky; 10-20-2011 at 02:21 AM.

  3. #3
    LifeElixer is offline Member
    Join Date
    Apr 2011
    Posts
    15
    Rep Power
    0

    Default Re: Bank program difficulties

    if i have the abstract Customer class set up like below, how does that tie in with asking the user the info and connecting a customer to the account? that's what's confusing to me.

    Java Code:
    public abstract class Customer
    {
      private String name, address, telephoneNumber, customerNumber;
      private int age;
      
      public Customer(String nm, String adrs, String teleNum, String custNum, int ag)
      {
        name = nm;
        address = adrs;
        telephoneNumber = teleNum;
        customerNumber = custNum;
        age = ag;
      }
      
      private void setName(String nm)
      {
        name = new String(nm);
      }
      
      private void setAddress(String adrs)
      {
        address = new String(adrs);
      }
      
      private void setTelephoneNumber(String teleNum)
      {
        telephoneNumber = new String(teleNum);
      }
      
      private void setCustomerNumber(String custNum)
      {
        customerNumber = new String(custNum);
      }
      
      private void setAge(int age)
      {
        age = ag;
      }
      
      public String getName()
      {
        return name;
      }
      
      public String getAddress()
      {
        return address;
      }
      
      public String getTelephoneNumber()
      {
        return telephoneNumber;
      }
      
      public String getCustomerNumber()
      {
        return customerNumber;
      }
      
      public int getAge()
      {
        return age;
      }
      
      public abstract getSavingsInterest()
      {
      }
      
      public abstract getCheckInterest()
      {
      }
      
      public abstract getCheckCharge()
      {
      }
      
      public abstract getOverdraftPenalty()
      {
      }
      
      
      public String toString()
      {
        return(name+" "+address+" "+telephoneNumber+" ");
      }
    }

  4. #4
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,785
    Rep Power
    7

    Default Re: Bank program difficulties

    Once again you would need a driver class that controls things. Since Customer is abstract do you have a concrete class that extends it?

  5. #5
    LifeElixer is offline Member
    Join Date
    Apr 2011
    Posts
    15
    Rep Power
    0

    Default Re: Bank program difficulties

    Bank program difficulties-layout.png

    This is the layout given to me, if that answers that question?

    *Currently working on the driver class*

  6. #6
    LifeElixer is offline Member
    Join Date
    Apr 2011
    Posts
    15
    Rep Power
    0

    Default Re: Bank program difficulties

    can i create a data field in the bank class which keeps track of the number of accounts created and
    then use this variable to determine which element of the array will hold the account i am inserting?

    if i do that, what's the right way to go about keeping track of the number of accounts?

  7. #7
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,785
    Rep Power
    7

    Default Re: Bank program difficulties

    Why waste time asking us? Experiment! Write some code, compile it and run it to see if it does what you want.

  8. #8
    LifeElixer is offline Member
    Join Date
    Apr 2011
    Posts
    15
    Rep Power
    0

    Default Re: Bank program difficulties

    what does it mean when i'm given three subclasses: Adult, Senior and Student extending the *abstract* Customer class and it asks me to have the following:

    data members: each have constants SAVINGS_INTEREST, CHECK_INTEREST, CHECK_CHARGE, and OVERDRAFT_PENALTY which define values for a customer of that type.

    why are they all capitalized? i've never seen that. Thanks

    *EDIT*
    wait, can someone tell me if i'm right?
    am i just setting a constant value for the above data values for each sub class because the interest and ect. is different for each Customer's subclasses and then use the values for the above data members into the algorithms/equations?
    Last edited by LifeElixer; 10-21-2011 at 03:55 AM.

  9. #9
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,785
    Rep Power
    7

    Default Re: Bank program difficulties

    Quote Originally Posted by LifeElixer View Post
    what does it mean when i'm given three subclasses: Adult, Senior and Student extending the *abstract* Customer class
    Exactly what it says. Write a class called Adult which extends Customer. etc.

    why are they all capitalized?
    It is standard practice to have the names of constants in capitals. That way someone else reading your code can easily distinguish it from a variable.

    If you need a particular clarification about the assignment then you should ask your teacher as they are the one person who knows what it means.

Similar Threads

  1. Array Code difficulties
    By NixasMuraki in forum New To Java
    Replies: 2
    Last Post: 02-08-2011, 12:17 AM
  2. how to make to classes in the bank account program
    By buzzing in forum New To Java
    Replies: 3
    Last Post: 11-02-2010, 04:02 AM
  3. Difficulties with many-to-many association
    By berlindutza in forum Web Frameworks
    Replies: 0
    Last Post: 03-03-2010, 04:53 PM
  4. java program for updating bank details
    By java__beginner in forum New To Java
    Replies: 5
    Last Post: 03-12-2009, 03:42 PM
  5. JOptionPane Display Difficulties
    By kewlgeye in forum New To Java
    Replies: 7
    Last Post: 05-09-2008, 08:09 PM

Posting Permissions

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