📄 bankaccount.java
字号:
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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -