Skip to content

cs1302uga/cs1302-hw03

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 

Repository files navigation

hw03 Interfaces (ADTs)

Approved for: Fall 2022

This class exercise is designed to get you acquainted with Interfaces in Java. When a seasoned programmer or potential employer asks you if you know Object-Oriented Programming (OOP), they do not mean, "do you know classes and objects?" Instead, they mean, "do you know the pillars of OOP?" The pillars of OOP are interfaces, inheritance, and polymorphism. In this exercise, we continue the exploration of interfaces and interface-based polymorphism. 

Prerequisite Knowledge

Course-Specific Learning Outcomes

  • LO2.e: (Partial) Utilize existing generic methods, interfaces, and classes in a software solution.
  • LO3.b: Create class, interface, method, and inline documentation that satisfies a set of requirements.
  • LO3.c: Generate user-facing API documentation for a software solution.
  • L04.b: Utilize interface-based polymorphism in a software solution.

Questions

In your notes, clearly answer the questions in the following exercise steps. All instructions assume that you are logged into the Odin server.

NOTE: For each step, please provide in your notes the full command that you typed to make the related action happen along with an explanation of why that command worked. Some commands require multiple options. It is important to not only recall what you typed but also why you typed each of them. If context is necessary (e.g., the command depends on your present working directory), then please note that context as well. You won't need to submit your notes in your final submission. However, if done properly, your exercise notes will serve as a helpful study guide for the exam.

Exercise Steps

Checkpoint 1 Steps - Getting Started

  1. Use Git to clone the repository for this exercise onto Odin into a subdirectory called cs1302-hw03:

    $ git clone https://github.com/cs1302uga/cs1302-hw03.git
    
  2. Change into the cs1302-hw03 directory that was just created and look around. There should be multiple Java files contained within the directory structure. To see a listing of all of the files under the src subdirectory, use the tree command as follows:

    $ tree src
    
  3. Generate the API documentation website for all of the code in the cs1302 package. Host the documentation on Odin using cs1302-hw03-doc as the name for your symbolic link. What is the URL to your hosted website?

  4. Using the API documentation website you generated in the last step, look at the documentation for the three class files provided in the starter code. For each Java file, fill out a row in a table similar to the following in your notes:

    Note: If a class is not an interface and does not implement an interface, write NA in the second column. Also, the "Depends On" column should list any Java types in the cs1302.hw03 package that the file is dependent upon.

    Name of the Java file Interface or Implementing Class? Fully Qualified Name (FQN) Depends On
    ----------------------- ---------------------------------- ---------------------------- ------------
    ----------------------- ---------------------------------- ---------------------------- ------------
    ----------------------- ---------------------------------- ---------------------------- ------------
  5. Read through the Javadoc comments for the Drivable interface on the API website you generated or in the source code. Make a note of the methods contained in the interface. You may find it helpful to write them in your notes.

  6. Look at the speedUp method in the Car.java file. Compare the Javadoc comment for the method in that file to the documentation listed for that method in the API documentation website. Notice that there is no Javadoc comment in the source code. However, a comment still shows up on the website. How is this possible?

  7. Run the given code through checkstyle using the check1302 command and fix any errors that it gives. Remember to use the 1302 Style Guide as a reference for the various types of errors that may pop up.

  8. Before moving on, we highly recommend drawing out the UML diagram for these classes and creating a compile script for quick and easy compilation.


CP


Checkpoint 2 Steps

  1. Make sure that you are still in the cs1302-hw03 directory. Compile Drivable.java and place the compiled code under the preexisting bin directory. To see a listing of all of the files under the bin subdirectory, use the tree command as follows:

    $ tree bin
    

    Notice that interfaces are compiled the same way as classes. Your output should be similar to the following:

    bin
    └── cs1302
        └── hw03
            └── contract
                └── Drivable.class
    
  2. Compile Car.java. Remember to set the classpath appropriately so javac can locate dependencies.

  1. Compile and execute Driver.java. It should run properly once Car.java is compiled. For now, we only have a single class (Car.java) that implements Drivable. Notice that the test method in Driver.java takes an argument of type Car. For now this is okay--just observe what is going on.

  2. Think of something else in real life that is capable of being driven (other than a car). This can be anything - have fun with it. :)

  3. Now, add a class to the cs1302.hw03.impl package that represents your new drivable type. That type should be something that is capable of being driven (speeding up and slowing down) and therefore a perfect candidate for a class that implements the actions in the Drivable interface. Make sure that your class properly implements the interface. Also make sure that your class compiles. Here is a small list of things you should do:

    1. Properly implement the interface.
    2. Add appropriate Javadoc comments and update your API documentation website.
    3. Compile your class.
    4. Run your program through check1302 to make sure it follows the style guidelines.

    What is the command that you used to compile your class?

  4. Tricky (hint below): Update Driver.java to test your new class. Modify the existing test method (don't overload the method by creating a separate method with the same name) so it can be used to test Car objects and objects of the new type that you just created (what do Car objects and objects of your new type have in common?). You should not change the name of the method, its return type, or the number of parameters. However, you may modify other parts of the method signature as well as the method's body, as needed. Be sure to update the Javadoc comments in the Driver class where necessary. In your notes, summarize the changes you made.

    Hint: If you're stuck on this step, it is similar to the gatherTotalDonations method in the video on Interfaces provided in the 1302 Interfaces Tutorial. The gatherTotalDonations method used an array of Donator references. Your method will just need a single Drivable reference.

  5. Regenerate the API documentation website for all of the code in the cs1302 package using the Javadoc tool. You should not need to recreate the symbolic link, assuming it still exists from a prior step.


CP


Checkpoint 3 Steps

  1. Add an abstract method stop to the Drivable interface, including appropriate Javadoc comments for what the method should do. Recompile the interface as well as any code that depends on the interface. Did any compilation problems occur? If so, where and why?

  2. Without further modifying the code in the interface, fix the errors observed in the previous step. If you find yourself writing additional methods in any of the other Java source code files, then be sure to include appropriate Javadoc comments. For each affected file, list the commands you used to verify that you fixed the errors. Repeat this step, as needed, until the code compiles.

  3. Regenerate the API documentation website for all of the code in the cs1302 package.

  4. Run the 1302 checkstyle program using the check1302 command on all .java files. If errors are reported, look up each error message in the Style Guide, fix the error, and repeat until no style errors remain.

  5. Take a minute to notice your stop method in the various places that it appears in the API documentation website that you regenerated in the previous step.

  6. Do not type the following command:

    $ nc towel.blinkenlights.nl 23
    

    The nc command provided above is not related to the exercise. If you type it in, then you may end up wasting time. The command connects you to a highly addictive form of entertainment provided Sten S. Stans, an elite Dutch Unix engineer.


CP


Submission Steps

Each student needs to individually submit their own work.

  1. Create a plain text file called SUBMISSION.md directly inside the cs1302-hw03 directory with the following information.

    1. Your name and UGA ID number; and
    2. The full link to the website generated in this exercise.

    Here is an example of the contents of SUBMISSION.md.

    Sally Smith (811-000-999)
    https://webwork.cs.uga.edu/~user/cs1302-hw03-doc
    
  2. Change directories to the parent of cs1302-hw03 (e.g., cd .. from cs1302-hw03). If you would like to make a backup tar file, the instructions are in the submissions steps for hw01. We won't repeat those steps here and you can view them as optional.

  3. Use the submit command to submit this exercise to csci-1302:

    $ submit cs1302-hw03 csci-1302
    

    Read the output of the submit command very carefully. If there is an error while submitting, then it will displayed in that output. Additionally, if successful, the submit command creates a new receipt file in the directory you submitted. The receipt file begins with rec and contains a detailed list of all files that were successfully submitted. Look through the contents of the rec file and always remember to keep that file in case there is an issue with your submission.

    Note: You must be on Odin to submit.

CP


License: CC BY-NC-ND 4.0 License: CC BY-NC 4.0

Copyright © Michael E. Cotterell, Bradley J. Barnes, and the University of Georgia. This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License to students and the public and licensed under a Creative Commons Attribution-NonCommercial 4.0 International License to instructors at institutions of higher education. The content and opinions expressed on this Web page do not necessarily reflect the views of nor are they endorsed by the University of Georgia or the University System of Georgia.

About

Homework Assignment 3 for CSCI 1302

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages