Skip to content

Programming by Design

If you're not prepared to be wrong, you'll never come up with anything original. – Sir Ken Robinson

  • About
  • Java-PbD
  • C-PbD
  • ASM-PbD
  • Algorithms
  • Other

CISS-111 Project 8

Posted on May 1, 2023 By William Jojo
CISS-111-Project
CISS-111 Project 8

Write a Java program to demonstrate using an N-ary tree to replicate a filesystem structure.


Learning outcomes

  • Working with N-ary trees.
  • Working with existing code to build a new representation.
  • 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.

Important Note!
Be sure to complete the testing needed to confirm you have good connectivity to the database. If you cannot successfully connect, please get in touch with your instructor before proceeding.

The Work…

You will be using the N-ary tree detailed in Special-Purpose Trees in Chapter 18.

Create a filesystem as the Directories class does. Then for each pathname you process, you need to either create a directory (D) or a file (F) as designated by the type provided by the database.

You must also account for the lack of path components to create the filesystem object.

With each pathname:

  • Determine the type to be created.
  • Get the root object from the filesystem and find the node that will be used to create the new object.
  • Traverse the path to the object’s parent.
  • Create the object or produce errors as appropriate.

You do not need to create a new method to perform these tasks. All of the processing can be performed in main().


Database

Your input will be sourced over the Internet from a MySQL database. The table is noted below:

mysql> show tables;
+---------------------+
| Tables_in_ciss111p8 |
+---------------------+
| pathnames           |
+---------------------+
1 row in set (0.00 sec)

And each table looks the same:

mysql> desc pathnames;
+-------+--------------+------+-----+---------+-------+
| Field | Type         | Null | Key | Default | Extra |
+-------+--------------+------+-----+---------+-------+
| path  | varchar(128) | NO   |     | NULL    |       |
| type  | varchar(8)   | NO   |     | NULL    |       |
+-------+--------------+------+-----+---------+-------+
2 rows in set (0.00 sec)

The database select statement you will use is

select path,type from pathnames;

You must do only one query and process the results to create your tree.


Results

You will produce an output to the screen that represents the errors encountered. As a last step, you will display the tree you created using printTree().

Sample output is shown below:

Unable to create object stdio.h. Path not found (/usr/local/include/stdio.h).
Unable to create object p8.out. Path not found (/home/stan/output/p8.out).

Tree:
/
  usr (DIR)
    local (DIR)
      bin (DIR)
        get-opts.sh (FILE)
  tmp (DIR)
    snap-private-tmp (DIR)
      snap.lxd (DIR)
        tmp (DIR)
  home (DIR)
    bill (DIR)
      mydir (DIR)
        files (DIR)
          content.dat (FILE)
    julie (DIR)
      fiber (DIR)
        inventory.dat (FILE)

The database table was created using the following SQL statements:

insert into pathnames values ('/usr', 'D');
insert into pathnames values ('/usr/local', 'D');
insert into pathnames values ('/usr/local/bin', 'D');
insert into pathnames values ('/usr/local/bin/get-opts.sh', 'F');
insert into pathnames values ('/usr/local/include/stdio.h', 'F');
insert into pathnames values ('/tmp', 'D');
insert into pathnames values ('/tmp/snap-private-tmp', 'D');
insert into pathnames values ('/tmp/snap-private-tmp/snap.lxd', 'D');
insert into pathnames values ('/tmp/snap-private-tmp/snap.lxd/tmp', 'D');
insert into pathnames values ('/home', 'D');
insert into pathnames values ('/home/bill', 'D');
insert into pathnames values ('/home/bill/mydir', 'D');
insert into pathnames values ('/home/bill/mydir/files', 'D');
insert into pathnames values ('/home/bill/mydir/files/content.dat', 'F');
insert into pathnames values ('/home/stan/output/p8.out', 'F');
insert into pathnames values ('/home/julie', 'D');
insert into pathnames values ('/home/julie/fiber', 'D');
insert into pathnames values ('/home/julie/fiber/inventory.dat', 'F');

The order of the inserts was intentional to guarantee the directory structure could be created successfully.


Submit Project8.java to the Learning Management System.

Post navigation

❮ Previous Post: IntelliJ JDBC Configuration
Next Post: Group Project 1 (of 2) ❯

Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

Copyright © 2018 – 2025 Programming by Design.