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

Use the constructor, Can we use the constructor, instead of init(), to init...

Can we use the constructor, instead of init(), to initialize servlet? Ans) Yes. Of course you can use the constructor instead of init(). There's nothing to stop you. But you sho

Need java netbeans platform developer, Project Description: I want a lot...

Project Description: I want a lot of developers to develop modules The basic purpose of this project is to prepare a standard ERP Software Company will be divided into module

PROBLEM 2, #The objective is to implement a menu-based system for Bank Acco...

#The objective is to implement a menu-based system for Bank Accounts in order to simulate a very simple banking system. Many structures have to be declared to manage bank accounts.

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

Program with eclipse and enumeration , Problem Definition A new Met Of...

Problem Definition A new Met Office web application will allow users of their web site to view rainfall statistics for months and years in the UK. The application allows the m

What is the jsf, JavaServer Faces(JSF) is a framework for building web-base...

JavaServer Faces(JSF) is a framework for building web-based user interface in Java. Unlike Swing, JSF provides widgets like buttons, hyperlinks, checkboxes, etc. in dissimilar ways

Need mahjong puzzle game, Need Mahjong puzzle game I want someone to mak...

Need Mahjong puzzle game I want someone to make this game ( Mahjong puzzle game) for me in Android ONLY. If you have high level programming knowledge in Android then please b

Farm production system, Farm Production System Project Description: I...

Farm Production System Project Description: I require software that will allow me to input/record the daily production of our farm and allow me to view the data back in the o

Minimum shelfs, send me the java code for minimum shelf program

send me the java code for minimum shelf program

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