Go Back   Java Programming Forums > Java Standard Edition Programming Help > Object Oriented Programming


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 14-03-2010, 05:06 PM
Junior Member
 

Join Date: Mar 2010
Posts: 1
Thanks: 1
Thanked 0 Times in 0 Posts
jon123 is on a distinguished road
Default Create a java small class for a bank account!!?

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.
Reply With Quote Share this thread on Facebook
Sponsored Links
Java Training from DevelopIntelligence
  #2 (permalink)  
Old 15-03-2010, 06:33 AM
Junior Member
 

Join Date: Mar 2010
Posts: 4
Thanks: 0
Thanked 3 Times in 2 Posts
heronfisher is on a distinguished road
Default Re: Create a java small class for a bank account!!?

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)
}
in my withdraw and deposit method I change the current Balance and I create a new Transaction and add it to the collection of Transactions (since I hate arrays, I would probably use one of the Collection-classes from the java.util package to store my transactions).
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.
Reply With Quote
The Following 2 Users Say Thank You to heronfisher For This Useful Post:
jon123 (15-03-2010), Json (15-03-2010)
  #3 (permalink)  
Old 24-03-2010, 03:00 PM
Junior Member
 

Join Date: Mar 2010
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
okello is on a distinguished road
Default Re: Create a java small class for a bank account!!?

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 );
}
2. I'd create two two classes; for CurrentAccount and SavingsAccount that would implement the above interface, and polymorphically provide implementation for the two methods; withdraw and deposit:
Java Code
public class CurrentAccount implements BankAccount {

  public void deposit( double amount ) {
      this.bal += bal;
  }

  public withdraw( double amount ) {
    this.bal -= bal;
  }

}
I would repeat this for the savings account.

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.
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



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


100 most searched terms
Search Cloud
2 dimensional arraylist java 2d arraylist java actionlistener actionlistener in java addactionlistener addactionlistener java convert double to integer java double format java double to integer in java double to integer java drag en drop programmeren java eclipse shortcut keys exception in thread "awt-eventqueue-0" java.lang.outofmemoryerror: java heap space exception in thread "main" java.lang.nullpointerexception exception in thread "main" java.lang.outofmemoryerror: java heap space format double in java format double java get mouse position java java 2d arraylist java actionlistener java double format java double formatting java double to int java double to integer java format double java forum java forums java get mouse position java list to map java mouse position java programming forum java programming forums java programming practice problems java send keystrokes to another application java two dimensional arraylist java.io.ioexception: premature eof java.lang.classformaterror: truncated class file java.lang.outofmemoryerror: java heap space java.util.arraylist jbutton action jbutton actionlistener jtextarea font jtextfield font size jxl.read.biff.biffexception: unable to recognize ole stream programming mutators and generics smack api two dimensional arraylist two dimensional arraylist java unable to sendviapost to url what is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20?

All times are GMT. The time now is 01:52 AM.
Powered by vBulletin® Copyright ©2000-2009, Jelsoft Enterprises Ltd.