1 Star 0 Fork 0

炎渊/Objects Early

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
BankAccount2.java 1.45 KB
一键复制 编辑 原始数据 按行查看 历史
炎渊 提交于 2020-04-25 01:35 . 上传作业
/**
A bank account has a balance that can be changed by
deposits and withdrawals.
*/
public class BankAccount
{
private double balance;
private int transactions;
/**
Constructs a bank account with a zero balance.
*/
public BankAccount()
{
balance = 0;
transactions = 0;
}
/**
Constructs a bank account with a given balance.
@param initialBalance the initial balance
*/
public BankAccount(double initialBalance)
{
balance = initialBalance;
transactions = 0;
}
/**
Deposits money into the bank account.
@param amount the amount to deposit
*/
public void deposit(double amount)
{
double newBalance = balance + amount;
balance = newBalance;
transactions++;
}
/**
Withdraws money from the bank account.
@param amount the amount to withdraw
*/
public void withdraw(double amount)
{
double newBalance = balance - amount;
balance = newBalance;
transactions++;
}
/**
Gets the current balance of the bank account.
@return the current balance
*/
public double getBalance()
{
return balance;
}
/**
Gets the total number of transactions of the bank account.
@return the transaction count
*/
public double getTransactionCount()
{
return transactions;
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Java
1
https://gitee.com/yan_yuan/Objects-Early.git
git@gitee.com:yan_yuan/Objects-Early.git
yan_yuan
Objects-Early
Objects Early
master

搜索帮助