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

A teacher holds office hours 100 times throughout the course of a school year. A

ID: 3607515 • Letter: A

Question

A teacher holds office hours 100 times throughout the course of a school year. Add a hash-table (map) to the teacher's results using STL's MULTIMAP class. This teacher uses the name of each student who attends office hours as the key value in a map and enters the subject that the student asked about. After the 100 office hour sessions, he generates an individualized report for each student in the form of a text file that indicates how many times they attended office hours in the 100 sessions and all the subjects that they came to office hours for help on (no duplicates).  

You can make the following assumptions:

1. The student names are "StudentX", where X is a number. ex: Student1, Student2, Student3, etc

2. The number of students can be randomly generated, capping at 75 students. Note that a student can come to as many different sessions as he/she wants.

3. You can generate a random string of characters for the topics or create a list of actual subjects in a file to choose from randomly.

Explanation / Answer

import java.io.IOException;

import java.nio.charset.Charset;

import java.nio.file.Files;

import java.nio.file.Path;

import java.nio.file.Paths;

import java.util.ArrayList;

import java.util.Hashtable;

import java.util.List;

import java.util.Map;

import java.util.Random;

public class STL_MULTIMAP {

static int officeHours = 100;

static int studentCAP = 75;

public static String generateRandomString(int length) {

String string = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

StringBuilder sb = new StringBuilder();

Random random = new Random();

for (int i = 0; i < length; i++) {

sb.append(string.charAt(random.nextInt(string.length())));

}

return sb.toString();

}

public static void main(String[] args) {

Random random = new Random();

Hashtable<String, List<String>> hashtableStudent = new Hashtable();

for (int i = 0; i < officeHours; i++) {

String student = "Student" + random.nextInt(studentCAP);

if (hashtableStudent.containsKey(student)) {

hashtableStudent.get(student).add(generateRandomString(5));

} else {

List<String> subjectList = new ArrayList<>();

subjectList.add(generateRandomString(5));

hashtableStudent.put(student, subjectList);

}

}

List<String> lines = new ArrayList<>();

for (Map.Entry<String, List<String>> entry : hashtableStudent.entrySet()) {

String key = entry.getKey();

List<String> value = entry.getValue();

lines.add(key + " " + value.toString());

}

Path file = Paths.get("/home/user/Documents/the-file-name.txt");

try {

Files.write(file, lines, Charset.forName("UTF-8"));

} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

}

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