Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 修改构造函数_Java_Constructor_Account_Bank - Fatal编程技术网

Java 修改构造函数

Java 修改构造函数,java,constructor,account,bank,Java,Constructor,Account,Bank,我有一个任务要求我修改构造函数。说明如下: 修改两个帐户构造函数 第一个构造函数将接受帐号作为参数,并设置帐号属性(类变量) 第二个构造函数将接受帐号和初始帐户余额,并设置相应的属性 我不懂的是“设置账号属性”和“设置对应属性” 我的两个构造函数是: public Account(String newAccountType, double depositAmount, long accountNumber) { this.accountType = newAccountType;

我有一个任务要求我修改构造函数。说明如下:

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

我不懂的是“设置账号属性”和“设置对应属性”

我的两个构造函数是:

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);
}  


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

您的第二个方法不是构造函数。表面上(如果您的任务有意义的话)应该有另一个名为
Account
的函数,它的参数列表与第一个不同;这是另一个构造函数。请看,您应该阅读“类变量”是什么,然后您应该能够完成此步骤。为此,请提示您对新参数做了什么?谢谢各位,我将查看这些网站。我显然对这门学科不太在行@如果我读对了作业,我会制作一个存储帐户所有者的ArrayList。这有关系吗?
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");
    }
}