CISS-111 Project 5
Write a Java program to demonstrate the use of linked lists further.
Learning outcomes
- Working with Linked Lists.
- Reworking existing code to use a different data type.
- Working with Nodes and how to arrange them based on certain criteria.
- Working with databases.
- Working with exceptions.
- Confirmation program produces desired results.
Setup
Set up your IntelliJ to work with MySQL.
The Work…
You will not be using the LinkedList
from java.util
. Rather, you will create your own OrderedList
class. You should begin by getting the IterableList
from Chapter 14 (Example 4a), and renaming it to OrderedList
.
IterableList
code from the chapter uses int
. You will be converting this to use String
.This exercise is intended to build the tools necessary to understand complex memory management rather than using an array-backed class like Vector
. In addition, your class will have the Iterable
capability that will allow you to use your class objects in a foreach
loop.
The key to this design is that the list will be ordered (sorted ascending) and will not contain duplicates. Your code will maintain this order. Refer to the class notes on the visual construction of a linked list. The focus is on the insert()
method.
- The
insert()
method needs to account for duplicates. The easiest way to do this is to make this your first test and return if you discover the word already exists. - Determining the insertion position into the list is the hardest part. You will need to walk the chain of nodes in a similar way that
delete()
does. This is because you have to link both where you are coming from and where you are going. - The
delete()
code should need little more than a type change.
Database and Files
You will have one filename provided to your program on the command line. This filename is the output file. Your input will be sourced over the Internet from a MySQL database.
The tables are noted below (these have already been built for you):
mysql> show tables; +---------------------+ | Tables_in_ciss111p5 | +---------------------+ | wordsToDelete | | wordsToInsert | +---------------------+ 2 rows in set (0.00 sec)
And each table looks the same:
mysql> desc wordsToInsert; +-------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------+-------------+------+-----+---------+-------+ | word | varchar(32) | NO | | NULL | | +-------+-------------+------+-----+---------+-------+ 1 row in set (0.00 sec) mysql> desc wordsToDelete; +-------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------+-------------+------+-----+---------+-------+ | word | varchar(32) | NO | | NULL | | +-------+-------------+------+-----+---------+-------+ 1 row in set (0.00 sec)
The database select statements you will use are
select word from wordsToInsert;
and
select word from wordsToDelete;
You must do two separate queries – one to populate the list and the other to remove items to arrive at the finished list.
wordsToInsert
table contains duplicate values! You are NOT allowed to use the DISTINCT
modifier for the select statements.Results
You will produce one output file that contains all the words from wordsToInsert
in sorted order, minus the duplicates and any items specified in wordsToDelete
.
Once you have processed the two tables, it is a simple matter of iterating over the list and writing the object data to the output file.
The output file size will be 22,725 or 27,270 bytes depending on your platform and the methods used.
Submit Project5.java and OrderedList.javat to the Learning Management System.