Results 1 to 9 of 9
Thread: Bank program difficulties
- 10-20-2011, 01:47 AM #1
Member
- Join Date
- Apr 2011
- Posts
- 15
- Rep Power
- 0
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:
and for my Account class i have(haven't included the getBalance getCustomer toString and setCustomer and etc yet):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() { }
my question is...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(); }
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. ~ThanksLast edited by LifeElixer; 10-20-2011 at 02:03 AM.
- 10-20-2011, 02:11 AM #2
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.
- 10-20-2011, 02:18 AM #3
Member
- Join Date
- Apr 2011
- Posts
- 15
- Rep Power
- 0
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+" "); } }
- 10-20-2011, 02:22 AM #4
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?
- 10-20-2011, 02:30 AM #5
Member
- Join Date
- Apr 2011
- Posts
- 15
- Rep Power
- 0
- 10-20-2011, 02:47 AM #6
Member
- Join Date
- Apr 2011
- Posts
- 15
- Rep Power
- 0
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?
- 10-20-2011, 02:52 AM #7
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.
- 10-21-2011, 03:48 AM #8
Member
- Join Date
- Apr 2011
- Posts
- 15
- Rep Power
- 0
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.
- 10-21-2011, 04:42 AM #9
Re: Bank program difficulties
Exactly what it says. Write a class called Adult which extends Customer. etc.
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.why are they all capitalized?
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
-
Array Code difficulties
By NixasMuraki in forum New To JavaReplies: 2Last Post: 02-08-2011, 12:17 AM -
how to make to classes in the bank account program
By buzzing in forum New To JavaReplies: 3Last Post: 11-02-2010, 04:02 AM -
Difficulties with many-to-many association
By berlindutza in forum Web FrameworksReplies: 0Last Post: 03-03-2010, 04:53 PM -
java program for updating bank details
By java__beginner in forum New To JavaReplies: 5Last Post: 03-12-2009, 03:42 PM -
JOptionPane Display Difficulties
By kewlgeye in forum New To JavaReplies: 7Last Post: 05-09-2008, 08:09 PM


LinkBack URL
About LinkBacks
Reply With Quote


Bookmarks