Question

In: Computer Science

I. General Description In this assignment, you will create a Java program to search recursively for...

I. General Description In this assignment, you will create a Java program to search recursively for a file in a directory.

• The program must take two command line parameters. First parameter is the folder to search for. The second parameter is the filename to look for, which may only be a partial name.

• If incorrect number of parameters are given, your program should print an error message and show the correct format.

• Your program must search recursively in the given directory for the files whose name contains the given filename. Once a match is found, your program should print the full path of the file, followed by a newline.

• A sample run of the program may look like this:

//The following command line example searches any file with “Assignment” in its name

%java FuAssign7.FuAssignment7

C:\CIS 265 Assignment

C:\CIS 265\AS 2\FuAssignment2.class

C:\CIS 265\AS 2\FuAssignment2.java

C:\CIS 265\AS 3\FuCIS265\FuAssignment3.class

C:\CIS 265\AS 3\FuCIS265\FuAssignment3.java

C:\CIS 265\AS 4\FuAssign4\FuAssignment4.class

C:\CIS 265\AS 4\FuAssign4\FuAssignment4.java

C:\CIS 265\AS 4\FuAssignment4.gpj

II. Submission

This is an individual assignment. Each student needs to submit the source code files of the Java program on Blackboard.

1. Put all you Java files in a folder. Please name the folder after your package name, for example, FuAssign7. Compress the folder into a .zip file and submit the .zip file.

2. You need to only submit the source code, i.e., the Java files.

3. You may submit multiple time. Your most recent submission before the deadline will be graded.

III. Grading

1. A program that does not run will receive 0 point.

2. There is a 10-20 points deduction for each major error, e.g., missing a file in the output.

3. There is a 1-9 points deduction for each minor error, e.g., a spelling error in printed message.

4. A program that does not follow the guidelines will lose 1-10 points.

5. Any type of cheating is not tolerated. You may be asked to explain your program in person.

IV. Bonus features (optional)

If you implement any bonus feature in your program, please put a comment in your Blackboard submission and in your main Java file.

1. (5 points) Your program prints file size and date of creation for each file, e.g.,

C:\CIS 265\AS 2\FuAssignment2.class Sat Jan 18 15:47:53 EST 2020 1870

Solutions

Expert Solution

/* 
       This program lists the contents of a directory specified by
       the user.  The contents of subdirectories are also listed,
       up to any level of nesting.  Indentation is used to show 
       the level of nesting.
   
       The user is asked to type in a directory name.
       If the name entered by the user is not a directory, a
       message is printed and the program ends.
   */
         
   
   import java.io.*;
   
   public class RecursiveDirectoryList {
   
      public static void main(String[] args) {
      
         String directoryName;  // Directory name entered by the user.
         File directory;        // File object referring to the directory.
      
         TextIO.put("Enter a directory name: ");
         directoryName = TextIO.getln().trim();
         directory = new File(directoryName);
         
         if (directory.isDirectory() == false) {
                // Program needs a directory name.  Print an error message.
             if (directory.exists() == false)
                TextIO.putln("There is no such directory!");
             else
                TextIO.putln("That file is not a directory.");
         }
         else {
                // List the contents of directory, with no indentation
                // at the top level.
             listContents( directory, "" );
         }
      
      } // end main()
      
      
      static void listContents(File dir, String indent) {
              // A recursive subroutine that lists the contents of
              // the directory dir, including the contents of its
              // subdirectories to any level of nesting.  It is assumed
              // that dir is in fact a directory.  The indent parameter
              // is a string of blanks that is prepended to each item in
              // the listing.  It grows in length with each increase in
              // the level of directory nesting.
          String[] files;  // List of names of files in the directory.
          TextIO.putln(indent + "Directory \"" + dir.getName() + "\":");
          indent += "  ";  // Increase the indentation for listing the contents.
          files = dir.list();
          for (int i = 0; i < files.length; i++) {
                   // If the file is a  directory, list its contents
                   // recursively.  Otherwise, just print its name.
              File f = new File(dir, files[i]);
              if (f.isDirectory())
                 listContents(f, indent);
              else
                 TextIO.putln(indent + files[i]);
          }
      } // end listContents()
         
   
   } // end class RecursiveDirectoryList
   

Related Solutions

I. General Description In this assignment, you will create a Java program to read undergraduate and...
I. General Description In this assignment, you will create a Java program to read undergraduate and graduate students from an input file, sort them, and write them to an output file. This assignment is a follow up of assignment 5. Like assignment 5, your program will read from an input file and write to an output file. The input file name and the output file name are passed in as the first and second arguments at command line, respectively. Unlike...
I. General Description In this assignment, you will create a Java program to read undergraduate and...
I. General Description In this assignment, you will create a Java program to read undergraduate and graduate students from an input file, and write them in reverse order to an output file. 1. The input file name and the output file name are passed in as the first and second arguments at command line, respectively. For example, assume your package name is FuAssign5 and your main class name is FuAssignment5, and your executable files are in “C:\Users\2734848\eclipse-workspace\CIS 265 Assignments\bin”. The...
I. General Description In this assignment, you will create a Java program to read undergraduate and...
I. General Description In this assignment, you will create a Java program to read undergraduate and graduate students from an input file, sort them, and write them to an output file. This assignment is a follow up of assignment 5. Like assignment 5, your program will read from an input file and write to an output file. The input file name and the output file name are passed in as the first and second arguments at command line, respectively. Unlike...
I. General Description In this assignment, you will create a Java program to read undergraduate and...
I. General Description In this assignment, you will create a Java program to read undergraduate and graduate students from an input file, sort them, and write them to an output file. This assignment is a follow up of assignment 5. Like assignment 5, your program will read from an input file and write to an output file. The input file name and the output file name are passed in as the first and second arguments at command line, respectively. Unlike...
(C++) I need to Create a Copy function of a Binary Search Tree recursively providing these...
(C++) I need to Create a Copy function of a Binary Search Tree recursively providing these structure emplate <typename T> class Tree {    struct TreeNode    {        T mData;        TreeNode* mLeft = nullptr;        TreeNode* mRight = nullptr;        TreeNode* mParent = nullptr;        bool mIsDead = false;        TreeNode()        {        }        TreeNode(T tData) : TreeNode()        {            mData = tData;...
Java program In this assignment you are required to create a text parser in Java/C++. Given...
Java program In this assignment you are required to create a text parser in Java/C++. Given a input text file you need to parse it and answer a set of frequency related questions. Technical Requirement of Solution: You are required to do this ab initio (bare-bones from scratch). This means, your solution cannot use any library methods in Java except the ones listed below (or equivalent library functions in C++). String.split() and other String operations can be used wherever required....
Description: The purpose of the program is to create a Java ticket purchasing program that allows...
Description: The purpose of the program is to create a Java ticket purchasing program that allows for users to log in, purchase tickets, keep records of tickets purchased, and keep information about the user. Program Requirements: The following are the program requirements: Must be fully functioning including registration, log-in, view events, and purchase tickets Tickets should be purchased using “points”, no information should be provided via the user for payment method. Default each user to an allotted number of points...
Write a program in JAVA that takes in two words, and then it recursively determines if...
Write a program in JAVA that takes in two words, and then it recursively determines if the letters of the first word are contained, in any order, in the second word. If the size of the first word is larger than the second then it should automatically return false. Also if both strings are empty then return true. YOU MAY NOT(!!!!!!!!!!): Use any iterative loops. In other words, no for-loops, no while-loops, no do-while-loops, no for-each loops. Use the string...
Description of the Assignment: Write a Python program to (a) create a new empty stack. Then,...
Description of the Assignment: Write a Python program to (a) create a new empty stack. Then, (b) add items onto the stack. (c) Print the stack contents. (d) Remove an item off the stack, and (e) print the removed item. At the end, (f) print the new stack contents: Please use the following comments in your python script: # ************************************************* # COP3375 # Student's full name ( <<< your name goes here) # Week 8: Assignment 1 # ************************************************* #...
JAVA PROGRAM Create a Binary Search Tree with the following elements in the order mentioned below:...
JAVA PROGRAM Create a Binary Search Tree with the following elements in the order mentioned below: 5, 85, 89, 3, 2, 8, 65, 92 Print the Pre-order of this tree Print the height and the balance factor of the nodes in the order they were inserted (5, 85, 89, 3, 2, 8, 65, 92) in the form of a table with three columns and 9 rows. Use column headers “Node”, “Height”, and “Balance Factor” for the three columns respectively. Use...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT