Skip to content

Lab 6 - Default Interface Methods Practice

Instructions

  1. Create a new interface, PropertiesLoader, and place it in the java112.utilities package.
  2. Add a default method to create a properties object.

    package java112.utilities;
    
    
    import java.io.*;
    import java.util.*;
    
    
    /**
     * This interface contains a default method that can be used anywhere a Properties
        * object is needed to be loaded.
        * @author Eric Knapp
        *
        */
    public interface PropertiesLoader {
    
        /**
         * This default method will load a properties file into a Properties instance
            * and return it.
            * @param propertiesFilePath a path to a file on the java classpath list
            * @return a populated Properties instance or an empty Properties instance if
            * the file path was not found.
            */
        default Properties loadProperties(String propertiesFilePath){
            Properties properties = new Properties();
            try {
                properties.load(this.getClass().getResourceAsStream(propertiesFilePath));
            } catch (IOException ioException) {
                ioException.printStackTrace();
            } catch (Exception exception) {
                exception.printStackTrace();
            }
            return properties;
        }
    }
    
  3. Copy LabThree and name it LabSix.

  4. Implement the PropertiesLoaderInterface in LabSix and call the default method to load the properties. This method call will replace the code you originally had to load the properties.

Screenshots

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

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

  1. lab6-happyPath.png: The command line output when running your program's "happy path".
  2. 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 7 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 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.
  • Instance variables are private.
  • Avoid using hard-coded values; utilize parameters passed into the program through the command line.
  • Provide friendly and informative messages to users before displaying stack traces for error situations. Add this to the PropertiesLoader interface!