CS111 Programming Assignment 9
Map and HashMap

Instructor: Trish Cornez


Program 1

      Using the Map and HashMap classes, write a program that reads a textfile containing a large amount of text. This file can be anything from your favorite poem to a New Yorker article.

      Use a HashMap to store a list of words that appear in the file and how many times they occur.

      Example:
        DEATH be not proud, though some have called thee
        Mighty and dreadfull, for, thou art not so,
        For, those, whom thou think, thou dost overthrow,
        Die not, poore death, nor yet canst thou kill me.
        From rest and sleepe, which but thy pictures bee,

      Produces:
          and 2
          art 1
          be 1
          bee 1
          but 1
          called 1
          canst 1
          death 2
          die 1
          dost 1
          dreadfull 1
          for 2
          from 1
          have 1
          kill 1
          me 1
          mighty 1
          nor 1
          not 3
          overthrow 1
          pictures 1
          poore 1
          proud 1
          rest 1
          sleepe 1
          so 1
          some 1
          thee 1
          think 1
          those 1
          thou 4
          though 1
          thy 1
          which 1
          whom 1
          yet 1

Guidelines

  1. Create the textfile.
  2. Determine the key/value pair for the Map.
  3. Read each word from the text file and strip it clean so that all non-letters are removed.


Program 2

      Design a console-based Java program to manage multiple classes in a school. Each class has students, and each student has multiple subjects with corresponding grades. Use HashMap extensively to manage this data.


      Program Requirements:
      1. Data Models (implement as Java Classes):
        Course (example CS110, CS111) has a list of students
        Each Student has a name, ID, and a list of courses.


      2. Data Structures:
        Use a Student class to store information about a student. Use a HashMap to store courses by name.
        Within each Course, use HashMap to store students.


      Functional Requirements to Test:
      1. Add courses.
      2. Add students to a courses
      3. List all students in a course