我想用另一个类的方法时遇到了一些麻烦。带两个参数的构造函数Java
所以我必须从我的班级AccountType, 打印到控制台interestRate和帐户类型,并将其存入我的客户类中,并且我已将它完美地用余额调用BankAccount类。
BankAccount balance = new BankAccount();
并且从构造函数调用时只使用一个参数,但现在,我想打电话给有两个参数的构造函数,我得到一个错误。
public void printAccountInformation()
{
BankAccount balance = new BankAccount(); // This work fine
AccountType rate = new AccountType(); // but here i get error because the constructor in the account type takes two arguments
AccountType type = new AccountType(); // but here i get error because the constructor in the account type takes two arguments
System.out.println("Greetings dear: " + name);
System.out.println("Your street: " + street);
System.out.println("Your town " + town);
System.out.println("Your postalCode " + postalCode);
System.out.println("Your PhoneNumber " + telephoneNumber);
System.out.println("User balance: " + balance.getBalance());
System.out.println("User Account type: " + type.getAccountType());
System.out.println("Your InterestRate Is: " + rate.getInterestRate());
}
这里是我的ACCOUNTTYPE类
public class AccountType
{
// Attributes
private String accountNameType;
private float interestRate = 0.0f;
// Constructor
public AccountType(String types, float rate)
{
accountNameType = types;
interestRate = rate;
}
// accessor
public String getAccountType()
{
return accountNameType;
}
public float getInterestRate()
{
return interestRate;
}
}
我在做什么错在这里?
你已经注意到你自己的构造函数有两个参数,但你已经通过了0. – FatalError 2014-09-26 17:01:44
你有没有试过在类中定义一个无参构造函数? – IdusOrtus 2014-09-26 17:03:59