Objectives:
• Become familiar with the SetADT interface
• Learn to use iterators
• Learn to use generic types
• Read files using provided libraries
• Practice incremental development
Hand-in Requirements
• Source for IntegerSetTester.java (10 pts)
• Source for WordSetTester.java (10 pts)
All projects and laboratories will be submitted electronically through webCT. Zip up your entire project directory to submit as the source. (Right click on the project folder and follow the SentTo link.)
Overview:
This project provides practice with using generics, iterators, and the SetADT. You will create two test programs. IntegerSetTester will create sets of integers and perform various set operations on them. WortSetTester will create sets of words from a file and output statistics.
Part I: Sets of integers
• Download the trysetsproject.zip file and import it into your Eclipse workspace as a starting point for this project. Use File -> Import > General -> Existing Projects into Workspace -> Select Archive File to import the zip file, see the "Bringing your program home" section in http://www.cs.utsa.edu/~javalab/lab/eclipse/getstartedeclipse.html for more details on how to import the zipped project.
• Compile and run IntegerSetTester.
• Create a new SetADT called set1 of Integer objects. Use ArraySet as the implementation.
• Add 1000 random Integer objects (with values between 1 and 50) to set1.
• Output set1 and its size. Why doesn't set1 contain 1000 elements?
• Create an Integer iterator for set1. Remove from set1 the first item returned by the iterator.
• Create a second set called set2 by adding 100 random Integer objects with values between 1 and 10.
• Output set2.
• Create a set3 which is the union of set1 and set2. Output set3 and its size.
• (On your own) Create a set4 which is the intersection of set1 and set2. Output set4 and its size.
• (On your own) Find and output the maximum value in set1.
Part II: Reading words from a file using WordReader
The WordReader class provides a String iterator over the words of a file.
• Create a new class called WordSetTester in the trysets project.
• Add code to WordSetTester to create a WordReader for short.txt.
• Write a loop that outputs the successive words obtained from WordReader one per line.
Part III: Creating sets of words from a file
The code in this part should be added to the WordSetTester class of Part III.
• Create a SetADT called shortSet that contains String objects.
• Create a WordReader called shortReader for the file short.txt.
• Add the words in short.txt to shortSet (by iterating through shortReader).
• Output the unique words and the number of unique words in short.txt (by using shortSet).
• (On your own) Create a set called poeSet that contains the words in the file poe.txt. Output the number of unique words in poe.txt.
• (On your own) Output the words that are in both shortSet and poeSet.
• (On your own) Output the words that are in shortSet but not in poeSet.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment