用java编写基于文本的UI,以管理AccountList类的使用,不能使构造函数工作



给定地址,帐户和帐户列表类已经创建,我已经坚持使用BankUI类的构造函数几个小时了,我觉得我犯了一个非常基本的错误。其他类编译正确,但我得到

constructor Account in class Account cannot be applied to given types; 
required: java.lang.String, java.lang.String, java.lang.String, java.lang.String
found: no arguments
reason: actual and formal argument lists differ in length
The operator that you use here cannot be used for the type of value that you are using it for. You are either using the wrong type here or the wrong operator.

我想这与我的帐户构造函数是一堆用于名称/帐号等的字符串有关。只是不知道我哪里出了问题,我已经尝试了几种不同的组合。

显然我的节目都有"不兼容的类型"?真的不确定解决这些问题:/

public class BankUI
{
private Scanner keyboard;
private ArrayList accounts;
private Account account;
public BankUI()
{
    keyboard = new Scanner(System.in);
    Account account = new Account();
}
 public void addAcc()
{
}
 public void getNumberOfAccs()
{
    System.out.println("There are" + Account.getNumberOfAccs + " accounts.");
}
public void showAll()
{
    for (Account account : accounts)
        System.out.println(account);
}
public void removeAcc()
{
}

您的Account类需要 4 个String s 作为构造函数参数,例如 new Account("foo", "bar", "baz", "1337") .

你应该做的第一件事是确定,什么作为参数传递,并将它们作为构造函数参数提供给BankUI类。

我认识到的第二件事是您在BankUI的构造函数中初始化您的帐户。与其写Account account = new Account();我敢打赌,你想初始化你的字段,这将是account = new Account("your", "four", "strings", "here");的,就像上面的一行。

最新更新