1 Star 0 Fork 0

谢继业/Using Objects and Implementing Classes

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
BankAccount.java 1.17 KB
一键复制 编辑 原始数据 按行查看 历史
谢继业 提交于 2020-05-07 22:02 . add BankAccount.java
/**
A bank account has a balance that can be changed by
deposits and withdrawals.
*/
public class BankAccount
{
private double balance;
/**
Constructs a bank account with a zero balance.
*/
public BankAccount()
{
balance = 0;
}
/**
Constructs a bank account with a given balance.
@param initialBalance the initial balance
*/
public BankAccount(double initialBalance)
{
balance = initialBalance;
}
/**
Deposits money into the bank account.
@param amount the amount to deposit
*/
public void deposit(double amount)
{
double newBalance = balance + amount;
balance = newBalance;
}
/**
Withdraws money from the bank account.
@param amount the amount to withdraw
*/
public void withdraw(double amount)
{
double newBalance = balance - amount;
balance = newBalance;
// your work here
balance = balance-1;
}
/**
Gets the current balance of the bank account.
@return the current balance
*/
public double getBalance()
{
return balance;
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/xjyng/Using-Objects-and-Implementing-Classes.git
git@gitee.com:xjyng/Using-Objects-and-Implementing-Classes.git
xjyng
Using-Objects-and-Implementing-Classes
Using Objects and Implementing Classes
master

搜索帮助