Everthing that I wanted to work has worked and now the final part, I need to check if a student of certain id has certain vaccine or not and the result should be in true or false only. I know that I have to use +listofInfos.contains():' but I don't know how to use it nor where to use it.
import java.util.ArrayList;
import java.util.Scanner;
public class Student {
private static class Info {
private String student_name;
private int student_id;
private String vaccine_name;
private int vaccine_id;
public Info(String student_name, String vaccine_name, int student_id, int vaccine_id) {
this.student_name = student_name;
this.student_id = student_id;
this.vaccine_name = vaccine_name;
this.vaccine_id = vaccine_id;
}
public String getStudentName() {
return student_name;
}
public int getStudentId() {
return student_id;
}
public String getVaccineName() {
return vaccine_name;
}
public int getVaccineId() {
return vaccine_id;
}
}
public static void main(String[] args) {
ArrayList<Info> listofInfos = new ArrayList<Info>();
addInfo(listofInfos);
}
private static void addInfo(ArrayList<Info> listofInfos) {
Scanner myKB = new Scanner(System.in);
System.out.println("How many datas do you want to input?");
int b = myKB.nextInt();
for (int i = 0; i <=(b-1); i++) {
myKB.nextLine();
System.out.println("Enter Student Name:");
String student_name = (myKB.nextLine());
System.out.println("Enter Vaccine Name:");
String vaccine_name = (myKB.nextLine());
System.out.println("Enter StudentID:");
int student_id = (myKB.nextInt());
System.out.println("Enter Vaccine Id:");
int vaccine_id = (myKB.nextInt());
listofInfos.add(new Info(student_name, vaccine_name, student_id, vaccine_id ));
}
for (Info List : listofInfos) {
System.out.println("Student Name:"+ List.getStudentName() + "\tStudent ID:" + List.getStudentId() + "\tVaccine Name:" + List.getVaccineName() + "\tVaccine ID:" + List.getVaccineId());
}
}
}