|
||
|
|||
|
I need to create a bank account class which consists of deposit and withdraw methods. I need to have a current account and savings account?
I also need help on how to extend it so I can ask the user to inpt their withdrawal amount and deposit and it gives out the balance using scanner funtion? So far i have something like this, isit right?.. Java Code
public abstract class BankAccount {
private double balance;
public BankAccount() {
balance = 0.;
}
public void deposit(double amount) {
balance += amount;
}
public withdraw(double amount) {
// check...
balance -= amount;
}
}
public class CurrentAccount extends BankAccount {
// additional stuff
}
public class SavingsAccount extends BankAccount {
// aditional stuff
}
Last edited by helloworld922; 24-03-2010 at 08:38 PM. |
|
|||
|
If I had to make a Bank Account class I would prefer the following interface:
Java Code
Class Bank Account{
public Bank Account()
public void withdraw(double amount)
public void deposit(double amount)
public Transaction getTransaction(int index)
public int transactionCount()
public double getCurrentBalance()
private void addTransaction(Transaction t)
}
The Print Transaction and Read Transaction methods I would not place in the Bank Account-class, neither in my Transaction- class. It makes my classes depend on the UI. Prove of this is, I need to change lot of code in order to get things right.It's better to do this printing-logic in a class of its own or in your Application-class.
__________________
acekard 2 Last edited by helloworld922; 24-03-2010 at 08:39 PM. |
|
|||
|
My approach would be as follows:
1. I'd create an bank account interface with the two methods; withdraw and deposit: Java Code
public interface BankAccount {
private double bal;
public void withdraw( double amount );
public void deposit( double amount );
}
Java Code
public class CurrentAccount implements BankAccount {
public void deposit( double amount ) {
this.bal += bal;
}
public withdraw( double amount ) {
this.bal -= bal;
}
}
To track changes made, I would use an AOP framework to take care of policy changes in security, and things like that. I hope this helps. Last edited by helloworld922; 24-03-2010 at 08:38 PM. |
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Java Source/APIs to create a Fourm | softwarebuzz | Java Theory & Questions | 2 | 09-01-2010 05:46 AM |
| COULD NOT CREATE JAVA VIRTUAL MACHINE | aubrey4444 | Java Theory & Questions | 16 | 08-12-2009 03:57 PM |
| Java Phonebook Assignment (Small Bugs) | Dawson | What's Wrong With My Code? | 1 | 08-05-2009 01:55 PM |
| Bank account GUI | AlanM595 | AWT / Java Swing | 5 | 02-04-2009 09:39 AM |
| Bank Account Program | keith | File I/O & Other I/O Streams | 10 | 31-03-2009 04:40 PM |