[英]I can't seem to figure out what to do with this instance so that my code could print out the requirement
So the specifications are: Create a BankAccount class. 因此规格如下:创建一个BankAccount类。 It should contain the following information, stored in instance variables. 它应包含以下信息,存储在实例变量中。 I need to have a constructor: BankAccount(String firstName, String lastName, double openingBalance)
. 我需要一个构造函数: BankAccount(String firstName, String lastName, double openingBalance)
。 And a public String firstName()
, a public String lastName(),
and a public double balance()
that return the First Name, last name and balance respectively. 还有一个public String firstName()
,一个public String lastName(),
和一个public double balance()
,它们分别返回名字,姓氏和余额。
And I have this so far... 到目前为止,我有这个...
public class BankAccountAssignmentPart1 {
private String firstName;
private String lastName;
private double openBalance;
BankAccountAssignmentPart1 (String firstName, String lastName, double openBalance) {
firstName = "Alfred";
lastName = "Jones";
openBalance = 1408;
}
public String firstName() {
return firstName;
}
public String lastName(){
return lastName;
}
public double Balance(){
return openBalance;
}
public static void main(String[] args){
BankAccountAssignmentPart1 m = new BankAccountAssignmentPart1();
System.out.println(m.firstName());
System.out.println(m.lastName());
System.out.println(m.Balance());
}
} }
So the problem I have is in the line BankAccountAssignmentPart1 m = new BankAccountAssignmentPart1();
所以我的问题是行BankAccountAssignmentPart1 m = new BankAccountAssignmentPart1();
in Eclipse it says that the constructor is undefined and goes on to give suggestions to change the code such as removing the String String double or change the modifier to static which can't happen in instances....So I don't know what to do. 在Eclipse中,它说构造函数是未定义的,并继续提出更改代码的建议,例如删除String String double或将修饰符更改为static,这在实例中是不会发生的。...所以我不知道去做。
Please Help! 请帮忙!
You need to specify parameters when you call your constructor: 调用构造函数时,需要指定参数:
BankAccountAssignmentPart1 m = new BankAccountAssignmentPart1("1","2",0);
Otherwise it tries to find BankAccountAssignmentPart1() constructor (with no parameters), which is indeed undefined. 否则,它将尝试查找确实未定义的BankAccountAssignmentPart1()构造函数(不带参数)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.