CS49J

Remember not to create packages. Use the default package

17A

Write a class StudentManager which uses a Map to associate students's names and their letter grades. Both the keys (names) and the values (letter grades) are Strings.

The constructor initializes an empty map.

Provide methods

Anisa: A
Carlos: B+
James: A-

Codecheck URL

17B

Write a program HashCodeSearch to search a file to see if you can find two words that have the same hash code. Read the file with a Scanner and use a data structure that maps the hashcode to a set of words with that hashcode. At the end, print out words that have the same hash code on the same line in lexicographical order. (That will be any set with a length greater than 1)

Finally print the number of duplicates divided by the number of words. It will be a really small number. That is the percentage of collisions.

Set the delimiter to use: scan.useDelimiter("[^A-Za-z0-9_]+");

The book to search is at this URL. Download the plain text and save it in your project as "war_and_peace.txt". The book is "War and Peace" - so there will be lots of words. (586,914).

You can just declare that the main method throws FileNotFoundException. No need for a try/catch

Codecheck URL

17C

Write an application IndexMaker which reads a simplified Java source file and produces an index containing identifiers . Print all the identifiers and all the line numbers on which each identifier occurs. But do not print reserved keywords. When you find an identifier, compare it against a list of reserved keywords and skip keywords. Be smart about this and do not use 50 if statements. Put the keywords in a data structure and check each identifier to see if it is in the collection. Here is a file of reserved keywords. Download it and put in your project.

Print the identifiers in lexicographical order. Display the line numbers in numeric order.

We will assume

You will need to set the delimiter: ...useDelimiter("[^A-Za-z_]+"); For simplicity, there will not be any identifiers that contain numbers.

Your output should be in this format:

ProcessRectangle: [4]
Rectangle: [2, 9, 11]
String: [7]
System: [13, 16]
args: [7]

You can simply declare that the main method throws the FileNotFoundException. You do not need to catch it.

Here are the Java files that are used: ProcessRectangle.java and PaintJobCalculator.java. CodeCheck will process both files.

Updated 5/3/2017

Use this line in your code for the file name

String filename = "ProcessRectangle.java"; //SUB "PaintJobCalculator.java"

Call the reserved keyword file reserved.txt

Codecheck URL