0

我有一个任务需要我修改构造函数。指令是:

修改两个 Account 构造函数 第一个构造函数将接受帐号作为参数并设置帐号属性(类变量) 第二个构造函数将接受帐号和初始帐户余额并设置相应的属性

我不明白的是“设置帐号属性”和“设置相应属性”。

我的两个构造函数是:

public Account(String newAccountType, double depositAmount, long accountNumber) {
    this.accountType = newAccountType;
    Random randomGenerator = new Random(); // Random Number Generator for account             number creation                           
    this.accountNumber = randomGenerator.nextInt(10000);                                
    setAccountStatus("Active"); // call account status setter to set the status to active
    DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");                                                                    
    Date date = new Date(); 
    this.dateOpened = dateFormat.format(date).toString();
    this.lastTransaction = dateFormat.format(date).toString();
    deposit(depositAmount);
    System.out.println("Account successfully opened! Your current balance is: " + this.accountBalance);
}  

public void deposit(double depositAmount, long accountNumber, int initialAccountNum, double accountBalance) {
    if (this.accountStatus == "Active") {
        this.accountBalance = this.accountBalance + depositAmount;
        System.out.println("Deposit successful");
        System.out.println("Balance: " + this.accountBalance);
        DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
        this.lastTransaction = dateFormat.format(date).toString();
    } else {
        System.out.println("Account is inactive");
    }
}

我已经将 accountNumber 添加到第一个和第二个构造函数中。完成这项任务的正确方法是什么?谢谢

4

0 回答 0