Java 具有存款和取款功能的银行账户类别
本简介旨在创建一个账户对象,ID为1122,余额为20000英镑,年利率为4.5%,使用2500英镑的提款法和3000英镑的存款法,以及打印余额、月利息和账户创建日期 我已经写了下面的代码,但在主要方法中,初始余额是错误的,应该是20000英镑,而不是20500英镑,取款和存款也是错误的。提取金额应为17500英镑,存款金额应为20500英镑。有什么建议可以让你喜欢这个吗Java 具有存款和取款功能的银行账户类别,java,class,Java,Class,本简介旨在创建一个账户对象,ID为1122,余额为20000英镑,年利率为4.5%,使用2500英镑的提款法和3000英镑的存款法,以及打印余额、月利息和账户创建日期 我已经写了下面的代码,但在主要方法中,初始余额是错误的,应该是20000英镑,而不是20500英镑,取款和存款也是错误的。提取金额应为17500英镑,存款金额应为20500英镑。有什么建议可以让你喜欢这个吗 package Account; import java.util.Date; class Account { priva
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);
您调用取款/存款两次(稍后在打印对账单中再次调用)。您需要注释掉/删除以下行:
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);
您调用取款/存款两次(稍后在打印对账单中再调用一次)。这真的有效吗?例如
“初始余额:”+account1.getBalance
不调用getBalance
函数。我是编程新手,对自己做错的事情有点困惑。它返回20500英镑,而不是20000英镑的实际初始余额。您调用account1。提取(2500);和账户1.存款(3000);twice@Someprogrammerdude这意味着您的程序将不会使用.getBalance
进行编译-可能是一个输入错误,我想您的意思是。getBalance()
这真的可以编译吗?例如“初始余额:”+account1.getBalance
不调用getBalance
函数。我是编程新手,对自己做错的事情有点困惑。它返回20500英镑,而不是20000英镑的实际初始余额。您调用account1。提取(2500);和账户1.存款(3000);twice@Someprogrammerdude意味着您的程序将不会使用.getBalance
进行编译-可能是输入错误,我想您的意思是.getBalance()