Go Back   Computer Forums > General Computing > Programming
Click Here to Login
Join Computer forums Today


Reply
 
Thread Tools Search this Thread Display Modes
 
Old 11-18-2006, 08:18 PM   #1
Daemon Poster
 
ericf1993's Avatar
 
Join Date: Nov 2005
Posts: 671
Default need help on a banking java program

i have created a account class
Code:
import java.text.NumberFormat;

public class Account
{
	private NumberFormat fmt = NumberFormat.getCurrencyInstance();
	
	private final double RATE = 0.035; //interest rate of 3.5%
	
	private int acctNumber;
	private double balance;
	private String name;
	
	//---------------------------------------------------------------
	// Sets up the account by defining its owner, account number, and 
	// balance.
	//---------------------------------------------------------------
	
	public Account (String owner, int account, double initial)
	{
		name = owner;
		acctNumber = account;
		balance = initial;
	}
	//-------------------------------------------------------------------
	// Validates the transaction, then deposits the specified amount into 
	// the account. returns the new balance.
	//-------------------------------------------------------------------
	
	public double deposit (double amount)
	{
		if (amount < 0) //deposit number is negative
		{
			System.out.println();
			System.out.println("Error : Deposit amount is invalid.");
			System.out.println(acctNumber + " " + fmt.format(amount));
		}
		else
		{
			balance = balance + amount;
		}
		return balance;
	}	
		//--------------------------------------------------------------
		//validates the transaction. then withdraws the specified amount
		//from the account. returns the new balance.
		//--------------------------------------------------------------
		
	public double withdraw (double amount, double fee)
	{
		amount += fee;
		if (amount < 0) //withdraw value is negative
		{
			System.out.println();
			System.out.println("Error: Withdraw amount is invalid");
			System.out.println("Account: " + acctNumber);
			System.out.println("Requested: " + fmt.format(amount));
		}
		else
		{
			if (amount > balance) //withdraw value exceeds balance
			{
				System.out.println();
				System.out.println("Error: Insufficient funds.");
				System.out.println("Requested: " + fmt.format(amount));
				System.out.println("Available: " + fmt.format(balance));
			}
			else
			{
				balance = balance - amount;
			}
		}
		return balance;
		
	}
	
	public double transfer (double withdaw, double deposit, int account)
	{
		
	}
	//----------------------------------------------------------------
	// adds interest to the account and returns the new balance.
	//----------------------------------------------------------------
	
	public double addInterest ()
	{
		balance += (balance * RATE);
		return balance;
	}
	
	
		//----------------------------------------------------------------
		// Returns the current balance of the account.
		//----------------------------------------------------------------
		
	public double getBalance ()
	{
		return balance;
	}
		
		//-----------------------------------------------------------------
		// returns the account number. 
		//-----------------------------------------------------------------
	public int getAccountNumber ()
	{
		return acctNumber;
	}
		
		//----------------------------------------------------------------
		// Returns a one-line description of the account as a string
		//----------------------------------------------------------------
	
		
	public String toString ()
	{
		return (acctNumber + "\t" + name + "\t" + fmt.format(balance));
	}
	
	
}
how do you add a transfer method where it transfers money from one account to another, sorry i am still new at this and need help, so please be nice

thanks
__________________

ericf1993 is offline   Reply With Quote
Old 11-20-2006, 12:42 AM   #2
Baseband Member
 
Join Date: Jul 2006
Posts: 58
Default Re: need help on a banking java program

You need to add a method (call it transferFunds or whatever), it will accept a parameter of type account (forget what you called your main class). Then after that you can refer to the one you called the method from with the key word "this" and then use the one you passed as a parameter as the other one you transfer to or from. And then you just put your coding in the method.

You can also code it as a static method and have it pass two paramaters of type account (transferFunds(a1, a2)) and then use those variable names to do the code. There's many ways to do it.

Sorry for the half -sorted explanation, I'm about to go to bed. If you need more help I can help you maybe tomorrow or someone else can do it.
__________________

Lightning_Rider is offline   Reply With Quote
Old 12-05-2006, 08:49 PM   #3
In Runtime
 
Tech N9ne's Avatar
 
Join Date: Apr 2006
Posts: 223
Send a message via MSN to Tech N9ne
Default Re: need help on a banking java program

ok, my laptop is beyond fucked and i need help. when i start up, it goes to the windows logo then it starts this repeating error message saying media test failure and starts retrying but it never goes threw, and restarting doesnt work, so its basically the worlds most expensive paper weight atm. so could anybody plz help. im pretty sure its some error in the start up options somewere someplace but i dunno
__________________
Intel(R) Core(TM)2 Quad CPU Q6600 @ 2.40GHz|2.00 GB DDR2 800mhz|NVIDIA GeForce 8800 GTX OC|Evega Nforce 680 SLI|500 gig HD|
Tech N9ne is offline   Reply With Quote
Old 12-05-2006, 08:56 PM   #4
In Runtime
 
Tech N9ne's Avatar
 
Join Date: Apr 2006
Posts: 223
Send a message via MSN to Tech N9ne
Default Re: need help on a banking java program

srry clicked on the wrong forum lol
__________________
Intel(R) Core(TM)2 Quad CPU Q6600 @ 2.40GHz|2.00 GB DDR2 800mhz|NVIDIA GeForce 8800 GTX OC|Evega Nforce 680 SLI|500 gig HD|
Tech N9ne is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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 Off



All times are GMT -5. The time now is 10:56 AM.


Powered by vBulletin® Version 3.8.8 Beta 4
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Search Engine Friendly URLs by vBSEO 3.6.0