Reading or writing disk files, JAVA Programming

Assignment Help:

For this assignment, you will simulate a file system. You will be neither creating files nor reading or writing disk files. Rather, you will have a simulation of a file system that resides entirely in memory in your computer.

Each file system has a top level or "root" directory. At this level, there may be an unlimited number of files. In addition to files, this top level directory may also have an unlimited number of subdirectories. These subdirectories may also have an unlimited number of files and/or subdirectories. Thus, just like on a real file system, you may have an unlimited number of files and/or directories in each directory. Since directories may contain other directories, you may have directories nested an unlimited number of levels deep.

You are required to write two files: FileSystem.java, and FileException.java. For FileException.java you will extend the class Exception in java.lang (no import needed). Your FileSystem.java source code file must include the following methods:

public class FileSystem {

                private static final String DEFAULT_NAME = "root";

                /**

                 * Constructor, creates a FileSystem instance,

                 * with the root directory given the name

                 * of the single parameter.

                 *

                 * @paramrootDirectory

                 */

                publicFileSystem(String rootDirectory) {

                }

 

                /**

                 * constructor, creates a FileSystem instance,

                 * with the root directory given the default

                 * name DEFAULT_NAME.

                 */

                publicFileSystem() {

                }

                /**

                 * creates a new subdirectory in the current directory with the directory

                 * name given as a parameter. Throws a FileException if a subdirectory

                 * with the same name or a file with the same name already exists in the

                 * current directory.

                 *

                 * @paramdirName

                 * @throws FileException

                 */

                public void makeDirectory(String dirName)

                throwsFileException {

                }

                /**

                 * Changes the current working directory to the directory specified in

                 * thenewDir string. Changes at only one level at a time (up or down)

                 * are supported. If the user specifies the string .., then the current

                 * working directory moves upward one level. If any other string parameter

                 * is given, then the current working directory moves down one level

                 * to the directory specified. If the directory indicated does not

                 * exist, then a FileException is thrown.

                 *

                 * @paramnewDir

                 * @throws FileException

                 */

                public void changeDirectory(String newDir)

                throwsFileException {

                }

                /**

                 * Creates a new file in the current working subdirectory.

                 * If a file or directory already exists with that name,

                 * then a FileException is thrown.

                 *

                 * @paramfName

                 * @param contents

                 * @throws FileException

                 */

                public void createFile(String fName, String contents)

                throwsFileException {

                }

                /**

                 * Returns true if there exists a directory with the

                 * given name in the current working subdirectory.

                 * Otherwise returns false.

                 *

                 * @paramdirName

                 * @return

                 */

                publicbooleandirectoryExists(String dirName) {

                }

                /**

                 * Returns true if there exists a file with the given

                 * name in the current working subdirectory.

                 * Otherwise returns false.

                 *

                 * @paramfName

                 * @return

                 */

                publicbooleanfileExists(String fName) {

                }

                /**

                 * Removes the directory with the given name from the

                 * current working subdirectory, if it exists, and is

                 * empty. Throws a FileException otherwise.

                 *

                 * @paramdirName

                 * @throws FileException

                 */

                public void deleteDirectory(String dirName)

                throwsFileException {

                }

                /**

                 * Deletes the file with the given name from the current

                 * working subdirectory, if it exists, otherwise throws

                 * aFileException.

                 *

                 * @paramfName

                 * @throws FileException

                 */

                public void deleteFile(String fName)

                throwsFileException {

                }

                /**

                 * Prints the directory and file names in the current working

                 * subdirectory. All directories should be printed before

                 * files. Within each group (directories and files)

                 * entries must be in sorted order (dictionary order)

                 */

                public void printDirectoryContents() {

                }

                /**

                 * Prints the entire contents of the file system tree.

                 * For each subdirectory starting with the root or top level

                 * directory, all directories and files are printed. Levels of

                 * nesting should indicated by inserting spaces before the

                 * nested directory or filename. Use 5 blank spaces for each

                 * level of nesting. Entries in a subdirectory must immediately

                 * follow that directory name in the listing.

                 */

                public void printAll() {

                }

 

 

                /**

                 * Returns the content of a file stored in the current

                 * working subdirectory identified by the parameter fName.

                 * Throws a FileException if the file is not found, or it is

                 * a directory instead of a file.

                 *

                 * @paramfName

                 * @return

                 * @throws FileException

                 */

                public String getContents(String fName)

                throwsFileException {

                }

                /**

                 * Returns the String representation of the current working directory.

                 *

                 * @return

                 */

                public String getCurrentDirectory() {

                }

 

 

                /**

                 * Returns the current number of subdirectories and files in the file

                 * system. A FileSystem with only a root directory has size == 0

                * (provided that the root directory is empty).

                 *

                 * @return

                 */

                publicint size() {

                }

The source code has been placed in your CVS accounts.

Additional Details and Requirements

The constructor will create an empty file system with a top level directory, either a name provided or DEFAULT_NAME.

File and directory names consist of a single String object. Any valid string is a valid filename except for the String ".." which indicates the parent subdirectory.

Each new entry in the file system has the following information. 1) name of directory or file, 2) text contents if the entry is a file. Text contents is a single string representing the file contents.

Each subdirectory may contain additional subdirectories and files, with no limit on the number of entries.

Within each directory, all contents should be kept in alphabetical order. All subdirectories must appear first (in dictionary order) followed by all files (in dictionary order).

When printing directories, the directory name should always be followed by a "/".

The printAll() method must be recursive.

You may use any classes that you wrote for program #1.

You may import only java.io.*, data_structures.*, java.util.Iterator, java.util.NoSuchElementException, and java.util.StringTokenizer.

Your project must include the FileSystem class and the FileException class, named appropriately. Additionally, you must implement all of the methods specified in the FileSystem class, and the name and signature of each method must match the specifications.

You may include as many additional classes as you need. Any data structures or ADT's you use must be in a package named data_structures. You must write any data structures or ADT's you need yourself, and they should handle Objects of any type, not just directories and files.

Much of the work in this assignment involves developing a good design. Give careful thought to the organization of directory/file information. The overall quality of your design will be worth approximately 30% of your grade for the assignment.

You will submit a report (maximum 5 pages) along with your source code that describes your design.

None of your public methods may return pointers to private internal objects. In particular, if you use a linked list data structure, you must not return a Node in any public method. Proper use of information hiding and encapsulation are expected.

Be careful about storing extraneous information along with files and directories. Useless replication of data is inappropriate, and will lower your overall grade.

Your project will be graded with a driver program not available to you. The driver program will instantiate instances of the class FileSystem only. Drivers must not reference any other classes in your project.


Related Discussions:- Reading or writing disk files

Explain jar archives, Explain JAR Archives ? HTTP 1.0 uses a separate ...

Explain JAR Archives ? HTTP 1.0 uses a separate connection for every request. When you're downloading several small files, the time required to set up and tear down the connec

Tasks with the classes Currency, In this assignment you work on a set of ta...

In this assignment you work on a set of tasks with the classes Currency, Money and Bank. Money and Currency You have been given a template for the Currency and Money classes (Lab1.

Difference between static and non-static variable, What is the difference b...

What is the difference between static and non-static variables? A static variable is associated with the class as a whole rather than with specific instances of a class. Non-st

Explain multiple initializers and incrementers, Explain Multiple Initialize...

Explain Multiple Initializers and Incrementers ? Sometimes it's essential to initialize several variables before starting a for loop. Similarly you may need to increment more t

Why the number of temporary workers is on the rise, Why the number of tempo...

Why the number of temporary workers is on the rise? Discuss main reasons? Temporary workers: Temporary workers are those workers that a company can hire to perform a certain ta

What are the parts of website design, What are the parts of website design?...

What are the parts of website design? Parts of web design: There are in 3 types of elements for web design and below are there names: 1. Navigation scheme 2. Overall look and

Program that compute prime numbers, The purpose of this assignment is to gi...

The purpose of this assignment is to give you practice working with one dimensional arrays. It will also introduce you to one of the oldest mathematical algorithms in the world. No

Explain in brief java applet, Explain in brief Java applet? It is a...

Explain in brief Java applet? It is a java program. It has been designed for transmitting Java code over the internet. It's automatically executed by Java-enabled W

How to wrapping your own packages in java, How to Wrapping Your Own Package...

How to Wrapping Your Own Packages in java? Java does not limit you to using just the system supplied packages. You can write your own as well. You write packages just such as

Differentiation jdk 1.02 event model and event delegation, Differentiation ...

Differentiation the JDK 1.02 event model and the event-delegation model introduced with JDK 1.1?

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd