I am trying to create a App base on user input with ArrayList. But there is some problem that I need to understand first.
PS: I want to try with normal value first before going into user input. And this is just a rough sketch up to make me understand how to use multiple arguments in a arraylist.
This is the Student
package test;
import java.text.SimpleDateFormat;
import java.util.Date;
public class Student {
private String name;
private Date DOB;
private String[] friend;
private String school;
public Student(String name, Date DOB, String[] friend, String school) {
this.name = name;
this.DOB = DOB;
this.friend = friend;
this.school = school;
}
public void display() {
System.out.println("Name : " + name);
SimpleDateFormat df = new SimpleDateFormat("dd-MM-yyyy");
System.out.println("Released Date : " + df.format(DOB));
System.out.println("Best Friend : " + friend[0] + ", " + friend[1]);
System.out.println("Director : " + school);
}
public String getName() {
return name;
}
}
This is the StudentApp
package test;
import java.util.ArrayList;
public class StudentApp {
private ArrayList<Student> students = new ArrayList<Student>();
public void start() {
addStudent();
}
public void addStudent() {
System.out.println("- Add Student Info -");
students.add(/* Need to ask the user to input their information like their name,DOB,friend,school*/);
}
}
how can I add in values to the arraylist if there is multiple arguments needed? (String, Date, String[], String). Because when I tried adding some value with the correct arguments needed into the students.add, it will show me an error saying
The method add(int, Student) in the type ArrayList is not applicable for the arguments (String, null, String, String)