Become familiar with the generic interfaces representing Abstract Data Types (ADTs) in the Java Collections Framework
Select and compose collection ADTs to solve problems
Prepration: Template code and example data
Please download lab06.zip, extract it to a known location on your computer, and open it as a project in IDEA. Open “src/Index.java”; if you see errors in the editor and a banner saying “Project JDK is not defined”, set the SDK to your Java 17 installation by clicking "Setup SDK" in the banner.
Task 1: Operations for “sequence” ADT
Brainstorm at least 4 operations that you would expect a sequence (or list) of values to support.
Task 2: Data structures for sequences
Identify at least 2 data structures that you have implemented in this class so far that could support all of the operations that characterize a sequence.
Task 3: Indexer application
Your goal is to create an index of a text file. The index lists all of the unique words appearing in the file, in alphabetical order, and indicates which lines of the file they appear on. Here is an example of a portion of an index:
would 6 9 10 15 17
year 5
yet 15
you 8 9 10 11 12 13 16 20
young 1 3 4 13
This indicates that the word “young” appears on four different lines in the file, including on the first and third lines. If a word occurs multiple times on the same line, that line number is only included once.
This problem can be solved with very little code by leveraging Java’s built-in implementations of appropriate ADTs. By solving the problem in terms of ADT operations (rather than jumping straight to code), it is easier to verify that your solution will work, and the same algorithm can readily be implemented in multiple languages.
Identify ADTs
Select a combination of ADTs (from those supported by Java’s collections framework) that would be suitable for storing the information needed to create the index. Specify their generic types.
Construct the index
In “Index.java”, declare fields of the types you selected above. Initialize these fields by constructing instances of appropriate classes from the Java collections framework.
Read the specification for indexWord(), then implement that method using your fields.
Print the index
Read the specification for printIndex(), then implement that method using your fields.
Run class Main, which will use the Index class to create and print an index for the included file “Austen.txt”. Answer the following questions about the resulting index and check your results with a neighboring group or with a consultant:
How many different lines does the word “with” appear on?
What is the last word alphabetically in the document?
On which line does the word “dinner” occur?
Submission
Open the assignment page for “Discussion activity 6” in CMSX
[Recorder] Find the “Group Management” section and invite each group member
[Others] Refresh the page and accept your invitation
[Recorder] Take a picture of your work and save as either a JPEG or a PDF file named “discussion_responses”. After all invitations have been accepted, upload your picture as your group’s submission.
Ensure that your group is formed and your work submitted before the Friday evening deadline.
Tips and reminders
Discussion is not a race. Focus on the current activity being facilitated by your TA and engage your whole group to propose and explain ideas.
Elect a recorder to maintain the “master” copy of your work (others are still encouraged to jot down ideas on scratch paper). Rotate this position each week.
It is a violation of academic integrity to credit someone for work if they were not present when the work was done, and the whole group is accountable. Your CMS group must only include classmates who attended section with you on that day. Remember that our participation policies accommodate occasional absences without penalty.
It is your individual responsibility to ensure that you are grouped on CMS and that your group’s work is submitted before the deadline. Log into CMS the day after section to ensure that everything is in order, and contact your groupmates if not. It would be prudent for multiple members to photograph the group’s work.
Only one group member (typically the recorder) needs to upload a submission. But their submission must not be uploaded until after all group members have confirmed their membership in CMS (contact your TA if you have trouble grouping in CMS).