bankaccount.java

来自「This will simulate a bank account and ut」· Java 代码 · 共 74 行

JAVA
74
字号
//
//
//

public class BankAccount
{
	private static final double interest = .04;
	private double balance;
	private static int account=100;

	public BankAccount()
	{
		setBalance();
		account++;
	}

	public BankAccount(double bl)
	{
		balance = bl;
		account++;
	}

	private void setBalance()
	{
		balance = ((int)(Math.random()*100000))/100.0;
	}

	public String deposit(double d)
	{
		if(d<=0)
		{
			return "Deposit Rejected";
		}
		else
		{
			balance+=d;
			return "Deposit Accepted";
		}
	}

	public String withdraw(double w)
	{
		if(balance-w<0)
		{
			return "Withdraw Rejected - Insufficient Funds";
		}
		else
		{
			balance-=w;
			return "Withdraw Accepted";
		}
	}

	public double calcInterest()
	{
		balance=balance+(balance*interest);
		return balance;
	}

	public int getAccount()
	{
		return account;
	}

	public double getBalance()
	{
		return balance;
	}

	public static double getInterest()
	{
		return 100*interest;
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?