- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
简述是创建一个账户对象,ID为1122,余额为20000英镑,年利率为4.5%,提款方式为2500英镑,存款方式为3000英镑,并打印余额、月息和日期。该帐户已创建。
我已经编写了以下代码,但在主要方法中,初始余额是错误的,应该是 20000 英镑,实际上是 20500 英镑,提款和存款也是错误的。金额应为取款 = 17,500 英镑,存款 = 20,500 英镑。关于如何解决这个问题有什么建议吗?
package Account;
import java.util.Date;
class Account {
private int id;
private double balance; //balance for account
private double annualInterestRate; //store interest rate
private Date dateCreated; //store date account created
// no arg constructor for default account
Account() {
id = 0;
balance = 0.0;
annualInterestRate = 0.0;
}
//constructor with specfic id and initial balance
Account (int newId, double newBalance) {
id = newId;
balance = newBalance;
}
//
Account (int newId, double newBalance, double newAnnualInterestRate) {
id = newId;
balance = newBalance;
annualInterestRate = newAnnualInterestRate;
}
//accessor and mutator methods
public int getId() {
return id;
}
public double getBalance() {
return balance;
}
public double getAnnualInterestRate() {
return annualInterestRate;
}
public void setId (int newId) {
id = newId;
}
public void setBalance (double newBalance) {
balance = newBalance;
}
public void setAnnualInterestRate (double newAnnualInterestRate) {
annualInterestRate = newAnnualInterestRate;
}
public void seDateCreated (Date newDateCreated) {
dateCreated = newDateCreated;
}
//Method for monthly interest
double getMonthlyInterestRate() {
return annualInterestRate/12;
}
//Define method withdraw
double withdraw (double amount) {
return balance -= amount;
}
//Define method deposit
double deposit(double amount) {
return balance += amount;
}
public static void main(String[] args) {
java.util.Date dateCreated = new java.util.Date();
Account account1 = new Account (1122, 20000, 0.045); //
//account1.withdraw(2500);
//account1.deposit(3000);
System.out.println("----------------------------------------");
System.out.println(" Welcome to your online account!");
System.out.println("Please find your account details below");
System.out.println("----------------------------------------");
System.out.println("Account ID:" + " " + account1.id);
System.out.println("Initial Balance:" + account1.getBalance());
System.out.println("Balance after Withdraw:" + " " + account1.withdraw(2500));
System.out.println("Balance after deposit" + " " + account1.deposit(3000));
System.out.println("Interest Rate:" + " " + account1.getAnnualInterestRate());
System.out.println("Monthly Interest:" + " " + "£" + account1.getMonthlyInterestRate());
System.out.println("Date Account was Created:" + " " + dateCreated);
System.out.println("------------------------");
System.out.println("The Process is complete");
System.out.println("------------------------");
}
}
最佳答案
您需要注释掉/删除以下行:
public static void main(String[] args) {
java.util.Date dateCreated = new java.util.Date();
Account account1 = new Account (1122, 20000, 0.045); //
//account1.withdraw(2500);
//account1.deposit(3000);
您调用提款/存款两次(稍后在打印报表中再次调用)。
关于java - 具有存款和取款功能的银行账户类别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59159893/
我有一个银行余额文本字段,我想根据存款/取款不断更新。这是我的代码: Bank Balance: Deposit Withdraw var balance = document.getEl
我对让 BankAccount 类实现安全提款/存款功能有疑问。到目前为止,当您向bankAccount 类提款或存款时,它会打印日志。无论如何,我的问题是如何实现安全性,例如您提取的金额不得超过您银
假设我有一个合约函数,它期望通过某个交易发送一定数量的near,该函数称为create_order , create_order需要几个论点。 我在前端以 myContract 的名称设置了我的契约(
我有一个java作业。我的任务是建立一个可以取款、存款和查询余额的银行。我的问题是,我无法在存款和取款后更新我的余额......我已经尝试了我能做的一切,但仍然无法理解逻辑。有人可以帮助添加到我的程序
我用 WooCommerce Deposits插件并希望隐藏除“本地取货”运输方式之外的所有其他运输方式,如果客户选择支付定金。 客户可以在产品页面上选择是支付 10% 的定金还是支付订单的全额。运输
我有这个 Lua 脚本,它应该创建一个新类,创建一个实例并调用函数,但是在我实际调用方法时出现错误。 Account = { balance = 0, new = function(s
我是一名优秀的程序员,十分优秀!