简体   繁体   English

我似乎无法弄清楚如何处理此实例,以便我的代码可以打印出要求

[英]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.

相关问题 我似乎无法弄清楚接下来要做什么。 它一直说“不是声明” - I can't seem to figure out what to do next. It keeps saying “Not a statement” 我似乎无法弄清楚如何打印所有包括重复的单词 - I can't seem to figure out how to get this print out all the words including the duplicates 无法弄清楚我的合并排序代码有什么问题 - Can't figure out what is wrong with my merge sort code 我无法在代码中找出“ Java InputMismatchException错误” - I can't figure out the “Java InputMismatchException errors” in my code 似乎无法弄清楚为什么我的循环不会进展 - Can't seem to figure out why my loop wont progress 您好,我似乎无法弄清楚为什么我的程序无法正常工作 - Hello I can't seem to figure out why my program isn't working 我似乎无法弄清楚如何将答案显示为计算器项目的单词? - I can't seem to figure out how to display answers as words for my Calculator Project? 我的代码做错了什么? 翻译成 PigLatin 并无法弄清楚如何打印返回值 - What am I doing wrong with my code? Translating into PigLatin and cant figure out how to print returned value 我无法在程序中使用PrinterWriter,有人可以帮我解决吗? - I can't use PrinterWriter in my program, could anyone help me figure it out? 我无法弄清楚输入是否为空 - I can't figure out to print if input is empty or not
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM