Skip to content

Lab-1-6 – The Ins and Outs

Objective

Practice combining the I/O classes to read in from a file, then output the file contents to a new file while using correct exception handling. You are required to use try-with-resources in this lab.

Tip

  1. Use the command $ ant build_labs to compile and build the class.
  2. Use the command $ ant run_tests_lab6 to test the class.
  3. Use the script $ ./runLabs1.sh LabSix InputFileName OutputFileName to run the class.

Instructions

  1. Create a new java class named LabSix in the java112.labs1 package.
  2. Add a main method.
  3. Add code in the main that will:
    1. Check to see if there are two command line arguments. The first will be the name of an input text file. The second will be the name of the output file the class will make.
    2. If there aren’t two arguments then the method will output: " Please enter two arguments on the command line, an input file name and an output file name" and terminate.
    3. If there are two arguments, then the method will instantiate an instance of the LabSix class and call its runmethod. The two arguments will be passed to the run method.
  4. Add a run method.
    1. The method will have a void return type.
    2. The method will have two String parameters. The first is the input file path that will be read. The second is the output file path for the file that will be created.
  5. Add code in the run method that will:
    1. Open the input file path for reading.
    2. Open the output file path for writing.
    3. Loop through the input file line by line and write each line to the output file.
    4. Close both files.
  6. The class must pass the lab 6 tests.
  7. Verify you can run the class.
    1. Think carefully about what your program should do. Does it work?
    2. How should you test your error handling? Do it!

Screenshots

To receive credit for this lab save screenshot(s) in the projects/screenshots/week3 directory.

You may combine the below into one screenshot and name it lab6.png.

  1. lab6-inputFile.png: The input file.
  2. lab6-tests.png: The command line output showing all unit tests passing
  3. lab6-happyPath.png: The command line output when running your program's "happy path".
  4. lab6-errorHandling.png: The command line output demonstrating the error handling in your program.

Submit Weekly Labs

  1. Add, commit, and push!
  2. Verify all work, including screenshots are visible in GitHub.
  3. Create a new issue in GitHub: "Week 3 ready for review".
  4. Copy the below text and paste it into the "Add a description" textarea. Answer the reflection questions in the space provided.

    @kkschumacher
    
    #### How are you doing? 
    **Are you encountering any issues preventing you from completing this week's assignments? What can I do to better support you this week?**
    
    #### What did you find particularly enlightening this week?
    
    
    #### What challenges (if any) did you encounter in your learning this week?
    
    
    #### What questions (if any) do you have about the material covered this week?
    
  5. Click "Submit new issue"


Rubric

All of the following must be satisfied to achieve a "Met" status

  • Screenshot should clearly show tests passing.
  • Screenshot should clearly show expected output when running the program (happy path).
  • Screenshot should clearly show any error conditions handled by the program code.
  • Code and screenshots are properly named and saved in the correct directory.
  • All lab steps have been accurately and appropriately implemented.
  • Code adheres to the course coding standards.
  • Commit messages are concise, atomic, and effectively describe the change(s) made.
  • JavaDoc documentation is properly implemented, providing clarity and understanding of the code's functionality and usage.
  • External sources (websites, classmates, AI tools, etc), if utilized, are referenced and documented within the code as comments.

Additional Considerations

  • Issue created correctly with thoughtful answers to the reflection questions.
  • Avoid using hard-coded values; utilize parameters passed into the program through the command line.
  • Catch and handle all exceptions.
  • Provide friendly and informative messages to users before displaying stack traces for error situations.
  • Correct implementation of try-with-resources to manage resources.