0

So I need to try to add to my qualification arrayList through this constructor in my driver class. I'm taking all my input in through the keyboard using scanner I'm a beginner programmer and I think its just something basic.

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);

2 Answers 2

1

med1 object is of which type? Please provide full code

You need to store qualifications in Arraylist , then pass Arraylist of qualification to Doctor constructor.

Try adding this

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

and then

Doctor doctor1 = new General(name, dob, gender, address,contactNumber, qualifiedInIreland, qualifications);
Sign up to request clarification or add additional context in comments.

1 Comment

Okay, thank you. med1 is declared at the beginning. private DoctorAPI med1 = new DoctorAPI();
1

You don't need to specify any type parameter, when passing them to the function:

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.