Docsity

Word Locator in Java in Database Management System - Assignment 1 | EECS 484, Assignments of Database Management Systems (DBMS)

Toggle sidebar
bg1
Page 1 of 5
EECS 484 Individual Assignment 1 - Word Locator in Java
Due: Wednesday, January 21 @ 10:30 AM
Problem Description
The goal of this assignment is help you transition your C++ skills to Java programming skills on
material that you should know from EECS 281. We will be using Java for application-level SQL
programming in the course because a lot real-world programming for database applications is
done in Java. However, we will be using C++ for implementing the Minirel2K database system
(last two projects) because most systems programming is still done in C++.
In this assignment you are to develop a “word locator” program written in Java, which will allow
a user to check if a specified (re)occurrence of a specified query word appears in the input text
file. The goal is to use efficient data structures for the task.
Program Specification
Your program code must be in a single file “WordLocator.java”. When started, your program
will display a prompt “>” (printed on stdout) and will then be ready to accept one of the
following four (4) commands, each terminated by a newline, where <WHITESPACE> is a
sequence or 1 or more space or a tab characters:
1. “load<WHITESPACE><filename>”: This command loads the specified file. The file may
be specified by either an absolute or a relative pathname. Running this command should
result in your program parsing and storing the words in this file in a data structure that can be
queried using the locate command (described below). A word is defined as a sequence of
upper and lower case letters in the English alphabet (i.e. characters ‘a’ to ‘z’, and ‘A’ to ‘Z’),
numbers, and the apostrophe. All other characters are considered as white space and will
therefore be treated as terminating a word. Two successive load commands should be treated
as if there is an intermediate “new” command (see below) in between the two commands.
2. “locate<WHITESPACE><word><WHITESPACE><n>” : This command outputs the
number of the word, counting from the beginning of the file, of the nth occurrence of the
word (n must be an integer that is 1 or higher). Word numbering starts from 1, so the first
word in the load file has a word number of 1. To match the word in the locate command with
a word in the load file you should use a case-insensitive string comparison method. If there
are no matches for the locate command, print “No matching entry”.
As an example, the following are legal locate commands: “locate si ng 3” and “locate sing 3”
both locate the 3rd occurrence of “sing”, but the second command has a few additional blank
spaces around the parameter “sing”.
The following commands are not legal: “locate si ng3”, “locate s ing 3q”. The first command does
not specify a parameter <n>, and in the second command the parameter <n> is not an integer.
A command is also considered invalid if <n> is an integer less than 1.
Note that the command “locate sing23 4” is a legal command for locating the fourth occurrence
of the word “sing23”.
3. “new” : This command resets the word list to the original (empty) state.
4. “end” : This command terminates the program.
pf3
pf4
pf5

Partial preview of the text

Download Word Locator in Java in Database Management System - Assignment 1 | EECS 484 and more Assignments Database Management Systems (DBMS) in PDF only on Docsity!

EECS 484 Individual Assignment 1 - Word Locator in Java

Due: Wednesday, January 21 @ 10:30 AM

Problem Description

The goal of this assignment is help you transition your C++ skills to Java programming skills on material that you should know from EECS 281. We will be using Java for application-level SQL programming in the course because a lot real-world programming for database applications is done in Java. However, we will be using C++ for implementing the Minirel2K database system (last two projects) because most systems programming is still done in C++. In this assignment you are to develop a “word locator” program written in Java, which will allow a user to check if a specified (re)occurrence of a specified query word appears in the input text file. The goal is to use efficient data structures for the task.

Program Specification

Your program code must be in a single file “WordLocator.java”. When started, your program will display a prompt “>” (printed on stdout ) and will then be ready to accept one of the following four (4) commands, each terminated by a newline, where is a sequence or 1 or more space or a tab characters:

  1. “ load< filename > ”: This command loads the specified file. The file may be specified by either an absolute or a relative pathname. Running this command should result in your program parsing and storing the words in this file in a data structure that can be queried using the locate command (described below). A word is defined as a sequence of upper and lower case letters in the English alphabet (i.e. characters ‘a’ to ‘z’, and ‘A’ to ‘Z’), numbers, and the apostrophe. All other characters are considered as white space and will therefore be treated as terminating a word. Two successive load commands should be treated as if there is an intermediate “new” command (see below) in between the two commands. “ locate< word >< n > ” : This command outputs the number of the word, counting from the beginning of the file, of the n th occurrence of the word ( n must be an integer that is 1 or higher). Word numbering starts from 1, so the first word in the load file has a word number of 1. To match the word in the locate command with a word in the load file you should use a case-insensitive string comparison method. If there are no matches for the locate command, print “ As an example, the following are legal locate commands: “ ” and “ ” b oth locate the 3rd^ occurrence of “sing”, but the second command has a few additional blank spaces around the parameter “sing”. The following commands are not legal: “ ” , “ ”. The first command does not specify a parameter , and in the second command the parameter is not an integer. A command is also considered invalid if is an integer less than 1. Note that the command “ ” is a legal command for locating the fourth occurrence of the word “sing23”.
  2. “ new ” : This command resets the word list to the original (empty) state.
  3. “ end ” : This command terminates the program.

Your program should respond to incorrect commands in the following ways:

  • If a bad command is entered, print the precise string “ ”, and go to the next prompt. Examples of bad commands are: and Other examples of bad command include the locate command having a word that is not legal as per the definition above. For example “ra#s” and “rats!” are invalid word parameters.
  • Note that if an incorrect load command is entered, such as (no filename) then your data structure should not be reset. In other words, if you have a previously loaded file, subsequent locate commands should still query that previously loaded file. Similarly if the load command specifies an invalid file name, then you should not reset the data structure. In both cases of the invalid load command outlined above, please print the standard error message “ ”. 1
  • If there is extraneous content in the command, such as or print out the standard error message: “ ”
  • All the command keywords are case insensitive, so “LoCATe sing 2” is a valid command, and should be treated as “locate sing 2”.
  • If a user enters a line that is empty or contains only whitespaces, simply print a new prompt.
  • Ignore whitespaces at the beginning or end of a line.

Example

Given the following sample text file, sixpence.txt: (^1) The error handling component of this assignment has deliberately been simplified to ease the programming load. In a real application, one should print error messages that identify the specific error and help the user in correcting their input. You will get sufficient practice in such error handling methods when you work on the Minirel assignments.

Getting Started

The files for this assignment can be downloaded from CTools in archived form (P1.tar.gz). Using any of the campus Linux machines, you can decompress the files using the following commands:

gunzip P1.tar.gz tar – xvf P1.tar You should then have a directory P1/ containing the following files:

  1. WordLocator.java: Empty file in which you have to add your solution code.
  2. Makefile: A sample makefile.
  3. sixpence.txt: A sample text file.
  4. sixpence.cmd: A sample command file.
  5. sixpence.out: Sample output when the command “wl < sixpence.cmd” is run.
  6. wrnpc.txt: Another sample text file (sample command and outputs are not provided for this file). Copy these files into your workspace. You should end up with your solution code in the file WordLocator.java. In addition you must create a text file called DESIGN.txt. The file DESIGN.txt should describe the following design and program criteria:
  7. Explain your choice of data structure. Did you consider any other data structures besides the one that you implemented? How did you arrive at your final choice of the data structure?
  8. What is the best, average, and worst case complexity of your implementation of the locate command in terms of the number of words in the file that you are querying? (You need to provide all three - best, average, and worst-case analysis, as well as an explanation). For the complexity, I am only interested in the big-Oh analysis. When computing the average complexity, you can assume that the number of occurrences of any particular word is small compared to the total number of words in the input file.
  9. What is the average case space complexity of your data structure in terms of the number of words in the input file? In other words, using the big-Oh notation, what is the expected average size of your data structure in terms of the number of words? Please do not create or submit any other files! All other files will be ignored!

Development Platform

You are welcome to use any environment for your development, but you must provide us with a version that will work with /usr/bin/java on CAEN workstations that are reachable via ssh to loginlinux.engin.umich.edu. You can type in “java - version” to check the Java version. Please make sure that your code works with this version. If you use features in a newer version of Java, then you may fail our tests and your grade will be adversely affected.

Coding and Testing

This program must be written in Java. Your coding style should have intuitive, well-defined classes, clean interfaces, modular design, and informative variable names. The code should be

well-documented. Each file should start with a header describing the purpose of the file and should also contain your uniqname(s). Testing for correctness involves more than just seeing if a few test cases produce the correct output. You should test your program on some large files (e.g., 100K-10 MB in size) to see that it gives adequate performance and still works correctly. In addition to the test driver that we provide, your assignment will be tested against our (more comprehensive) test driver. You are encouraged to develop additional tests on your own. To compile the code, we will use the following command: % javac WordLocator.java To run it, we will use the following: % java WordLocator

Submitting Your Assignment

To submit the assignment, we will use CTools. Please see the instructions on the course website. Important: Try to access CTools several days before the deadline to confirm that you can see “EECS 484 001 F08” and the instructions for the first assignment. If you try to access CTools for the first time right before the deadline, you may miss the deadline.

Grading

This assignment is worth 8% of your grade. Your score for the assignment is as follows:

  • 60% correctness
  • 20% good design choices
  • 10% quality of design report
  • 10% programming style You may be penalized on design choices if the algorithmic complexity of your solution is poor. For example, if you have an algorithm that takes on average O(n^2 ) time to execute the locate command, then you have a very poor design. The programming style points are to make sure that you follow good programming practices. Your code should be commented and structured so that any other programmer can easily understand it. For this assignment, there are no free late days. Assignments will not be accepted after the deadline.