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

Create an executable application in java, This assignment requires you to d...

This assignment requires you to design, implement and test a program using Java features from the first half of the subject content. You are required to implement in Java all the c

Write an aspect that counts different kinds of method calls, Problem statem...

Problem statement Part 1 Write an aspect that counts different kinds of method calls in a Java program. Your aspect should meet the following requirements:  The aspect should ma

Compiler Design - Limit the loops, Problem : Compiler Design - Limit the lo...

Problem : Compiler Design - Limit the loops Rajni is a newbie to the programming and while learning the programming language he came to know the following rules: ???• Each

Exercise\servletexercise, Ask question # Write a servlet to display a table...

Ask question # Write a servlet to display a table that contains factorials for the numbers from 0 to 10,

What do you understand by private and public class, What do you understand ...

What do you understand by private, protected and public? These are accessibility modifiers. Private is the most restrictive, whereas public is the least restrictive. There is n

Write the hashcode() method of java.lang.object, Write the hashCode() metho...

Write the hashCode() method of java.lang.Object Anytime you override equals() you should also override hashCode(). The hashCode() method should ideally return the similar int f

Prepare a java program, Using Java, write the class Time which consists of ...

Using Java, write the class Time which consists of the following: (a) three private integer data members (hours, minutes and seconds). (b) a constructor to initialise the dat

How can you performance tune your database?, 1. De normalizes your tables w...

1. De normalizes your tables where required. 2. Proper use of index columns: An index based on numeric parts is more efficient than an index based on character columns. 3. Re

Write a program that manages a list of train tickets, A fictitious train co...

A fictitious train company, 'Transrail', has commissioned you to write a program that manages a list of train tickets. The program should display a text menu that prompts the us

Give an example for passing arguments to methods, Give an example for Passi...

Give an example for Passing Arguments to Methods ? class Car { String licensePlate = ""; // e.g. "New York 543 A23" double speed = 0.0; // in kilometers per h

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