gpt4 book ai didi

java - 如何通过另一个构造函数添加到数组列表?

转载 作者:行者123 更新时间:2023-12-02 01:33:12 26 4
gpt4 key购买 nike

所以我需要尝试通过我的驱动程序类中的这个构造函数添加到我的资格数组列表中。我正在使用扫描仪通过键盘获取所有输入我是一名初学者程序员,我认为这只是一些基本的东西。

public class Driver {

private Scanner sc = new Scanner(System.in);
private Doctor doctor;
private Qualification qualifications;
System.out.println("Enter doctors name: ");
sc.nextLine();
String name = sc.nextLine();
System.out.println("Enter doctors date of birth");
String dob = sc.nextLine();
System.out.println("Enter doctors gender");
String gender = sc.nextLine();
System.out.println("Enter doctors address");
String address = sc.nextLine();
System.out.println("Enter doctors contact number");
String contactNumber = sc.nextLine();
System.out.println("Was the doctor qualified in Ireland?");
boolean qualifiedInIreland = sc.nextBoolean();
System.out.println("Add doctor qualifications");



Doctor doctor1 = new General(name, dob, gender, address,contactNumber, qualifiedInIreland, <Qualification> qualifications);
med1.addDoctor(doctor1);

最佳答案

med1 对象属于哪种类型?请提供完整代码

您需要将资格存储在 Arraylist 中,然后将资格的 Arraylist 传递给 Doctor 构造函数。

尝试添加这个

ArrayList<String> qualifications = new ArrayList<String>();
System.out.println("Add doctor qualifications");
while(sc.hasNext){
qualifications.add(sc.nextLine());
}

然后

Doctor doctor1 = new General(name, dob, gender, address,contactNumber, qualifiedInIreland, qualifications);

关于java - 如何通过另一个构造函数添加到数组列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55709206/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com