Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

You have a list of NetIDs (Strings), followed by the course number that a studen

ID: 3759414 • Letter: Y

Question

You have a list of NetIDs (Strings), followed by the course number that a student is enrolled in. The listing is in no particular order, and could look something like:

sbody12 LIS452

anywann3 LIS501

sbody12 LIS590DB

sbody12 LIS501

bsimps3 CPSC440

anywann3 CPSC440

... etc.

Write a program that reads the data in from the console. If the NetID is -1, then stop.

Use the HashMap class to map from a String to an ArrayList of type String that holds each class that the student is enrolled in. The declaration will look like this:

HashMap<String, ArrayList<String>> students = new HashMap<String, ArrayList<String>>() ;

After al the data is input, iterate through the map and output the NetID and all the classes stored in the ArrayList for that student. The results should be a list of classes organized by student ID.

WARNING: This is the most challenging program you have seen to date. It will take more time than you possibly expect. I am available to answer questions, and feel free to work together. Remember to break it down into small steps, and think about what you are doing at each step. Suggest starting with just entering the NetID and ClassID and making sure you can see them as separate strings, then add them to a simple HashMap of HashMap<String, String>, and THEN move onto adding the ClassId to an existing array.

Explanation / Answer

public class Main {
public static void main(String[] args) {arraylist<Student> students = getStudentsinfo();
Map<String, arraylist<Student>> map = new HashMap<String, arraylist<Student>>(); //student declaration with hashmap
for (Student i : students) { // for loop using
if (map.containsKey(i.getCourse())) {
map.get(i.getCourse()).add(i);
} else {arraylist<Student> newList = new arraylist<Student>(); //New Array List of the Student
newList.add(i);
map.put(i.getCourse(), newList);
}
}
System.out.println(map); // print the values
}
private static arraylist<Student> getStudentsinfo() {arraylist<Student> list = new arraylist<Student>();
list.add(new Student("sbody12", "LIS452"));
list.add(new Student("anywann3", "LIS501"));
list.add(new Student("sbody12", "LIS590DB"));
list.add(new Student("sbody12", "LIS501"));
list.add(new Student("bsimps3 ", "CPSC440"));
list.add(new Student("anywann3", "CPSC440"));

return list;
}
}
class Student {
public Student(String name, String Course) {
this.name = name;
this.Course = Course;
}
private String name;
private String Course;
public String getCourse() {
return Course;
}
@Override
public String toString() {
return name; //names of the students
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote