[SOLVED] CS1331-Homework 13 Ls-Cat

20.99 $

Programming resource
Digital learning resource
Category:
✓ Practical programming resource
✓ Suitable for guided study and reference
✓ Tutor guidance available when needed

Description

Rate this product

Still stuck in the future, you’re starting to enjoy it. You’ve helped space explorers improve their data infrastructure, and briefly got launched into the world of Pokémon where you’ve left Professor Oak and the Pokemon Center eternally grateful for your services.

Unfortunately, you learn that “Georgia Tech University” was really just a front for a school named “Georgia

Tech”! Professor Oak reveals himself to be the professor of a class named CS 1331 and tells you to get back to your homework and to stop reading pointless problem descriptions.

Solution Description

For this assignment, create the following files:

  • java
  • java
  • java

FileHelper Class:

FileHelper will contain static helper methods that have functionality similar to the ls and cat unix commands.

Methods:

  • public static void printLs(String path)
    • This will print out all of the files and folders that are contained within the folder located at path.
    • You must use the printLsHelper method below.
    • You may assume that the path parameter contains the path to a folder.
  • private static void printLsHelper(String path, int indentationLevel)
    • Must recursively call itself
    • For every indentationLevel, print 4 spaces at the beginning of the line before printing anything else.
    • If the path that is passed in is a path to a file, print out the name of the file.
    • If the path that is passed in is the path to a folder, print out the name of the folder and then, indented a level, print out the contents of the folder (Hint: recursion).
    • This problem must be solved recursively or you will receive a heavy deduction (Hint: if you are not making at least one recursive call per folder, you are probably doing it wrong). – See the example below in testing your code for formatting to follow!
  • public static void printCat(String path)
    • If path isn’t a path to a real file or is a directory, throw a CatException. The message should be “Path invalid.” and pass in the path.
    • Otherwise

∗ For each line in the file, print out “{line number}: {line from text file}” ∗ See the example below in testing your code for formatting to follow!

CatException Class:

  • Make this custom Exception be a Checked Exception
  • Take a String message and String problemFile into the constructor. Pass message to super and store problemFile in a private final field called problemFile to keep track of the path to the file.
  • Override getMessage() to include the original message (Hint: use super’s getMessage()) plus the absolute path to the problemFile in the following format: “{original message}. Problem with file {absolute path}!”
    • problemFile may be an absolute path or a relative path. Make sure to print out an absolute path.
Resource details

Understand the Task Before You Use the Resource

Review the requirements, identify the programming concepts involved, study the implementation and test your understanding with your own examples and modifications.