Q5 Java Class. Please do it in 2 ways, ArrayList and HashMap.
Student class represents the information of a student. It
has the following fields: name, major, id, average of grade
a. Create a Student object for 4 students
b. Save information to ArrayList<Student> (Get
information by using Scanner class)
The following is the method to get user input.
private void read() {
System.out.println("Enter student name,
major, id and average of grade.");
for (int i=0; i<4; i++) {
System.out.print(">> ");
String text = scanner.nextLine();
StringTokenizer st = new
StringTokenizer(text, ",");
String name =
st.nextToken().trim();
String department =
st.nextToken().trim();
String id =
st.nextToken().trim();
double grade =
Double.parseDouble(st.nextToken().trim());
// TODO : Add your code at here to save information
}
}
c. Print all 4 students' information. Make printAll()
method.
d. Get name of student, search and print information. Make
processQuery() method.
e. If user input “exit”, quit. In processQuery() method.
Enter student name, major, id and average of grade.
>> Jobs, Mobile, 1, 4.1
>> Cook, SW, 2, 3.9
>> Gates, Design, 3, 3.5
>> Zukerberg, Mobile, 4, 3.1
---------------------------
Name : Jobs
Major : Mobile
ID : 1
Avg. Grade : 4.1
---------------------------
---------------------------
Name : Cook
Major : SW
ID : 2
Avg. Grade : 3.9
---------------------------
---------------------------
Name : Gates
Major : Design
ID : 3
Avg. Grade : 3.5
---------------------------
---------------------------
Name : Zukerberg
Major : Mobile
ID : 4
Avg. Grade : 3.1
---------------------------
Student name >> Gates
Gates, Design, 3, 3.5
Student name >> Bill
Student name >> Jobs
Jobs, Mobile, 1, 4.1
Student name >> exit
Also please rewrite Q5 by using HashMap<String, Student>. The key is the name of the student.