bankaccount.java

来自「一些java的小程序.包括排序,一些bank的小计算,」· Java 代码 · 共 82 行

JAVA
82
字号
public class BankAccount{	// Declare instance variables accountNumber, name, balance.	//[add here]		private int accountNumber;	private String name;	private double balance;	// Leave this declaration	private static int accountCount = 1;		// Start account numbers at 1.	public BankAccount(String ownersName, double openingBalance)	{		// Assign unique account number to this instance of bank account		accountNumber = accountCount++;		// initialize instance variables.		//[add here]		name = ownersName;		balance = openingBalance;	}	// insert get and set methods for the class here.	// [add here]	public void setName(String ownersName)	{		name = ownersName;	}		public void setBalance(double aBalance)	{		balance = aBalance;	}		public String getName()	{		return name;	}		public double getBalance()	{		return balance;	}	// Withdraw an amount from this account	public void withdraw(double amount)	{		double tempBalance = balance;		if((tempBalance - amount) >= 0)		{			balance -= amount;		}			}	// Deposit an amount to this account	public void deposit(double amount)	{		balance += amount;	}	// This method returns a String representing the state of this account.	public String toString()	{		// create a string to return here.		StringBuffer info = new StringBuffer(10);		info.append("Account Number: ");		info.append(accountNumber);		info.append('\n');		info.append(" Owner's Name: ");		info.append(name);		info.append("\n");		info.append(" Balance: ");		info.append(balance);				return info.toString();	}}

⌨️ 快捷键说明

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