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.
- A basic understanding of creating and implementing interfaces in Java.
- CSCI 1302 Interfaces Tutorial
- 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.
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.
-
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 -
Change into the
cs1302-hw03directory 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 thesrcsubdirectory, use thefindcommand as follows:$ find srcFor each Java file under the
srcsubdirectory, 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
NAin the second column. Also, the "Depends On" column should list any Java types in thecs1302.hw03package that the file is dependent upon.Name of the Java file Interface or Implementing Class? Fully Qualified Name (FQN) Depends On ----------------------- ---------------------------------- ---------------------------- ------------ ----------------------- ---------------------------------- ---------------------------- ------------ ----------------------- ---------------------------------- ---------------------------- ------------ -
Read through the Javadoc comments in the
Drivableinterface and write down the names of the abstract methods in your notes. -
Run the given code through
checkstyleusing thecheck1302command 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. -
Generate the API documentation website for all of the code in the
cs1302package. Host the documentation on Odin usingcs1302-hw03-docas the name for your symbolic link. What is the URL to your hosted website? -
Look at the
speedUpmethod in theCar.javafile. 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?
-
Make sure that you are still in the
cs1302-hw03directory. CompileDrivable.javaand place the compiled code under the preexistingbindirectory. To see a listing of all of the files under thebinsubdirectory, use thefindcommand as follows:$ find binNotice that interfaces are compiled the same way as classes. In your notes, write down the path for the
Drivable.classfile that the compiler generated based on the output offind. -
Compile
Car.java. Remember to set the classpath appropriately sojavaccan locate dependencies.Uh-oh. (╯°□°)╯︵ ┻━┻
- Don't stress! You're expected to see the compile-time error below:
error: Car is not abstract and does not override abstract method slowDown(double) in Drivable public class Car implements Drivable { ^ 1 errorNote: the expected error is not "package does not exist" or "cannot find symbol". If you received one of these errors, check your compilation line for mistakes.
-
Why did you receive the intended compile-time error above? Notice it says
Cardoes not override one of the methods inDrivable. Must be a typo. Hint: check spelling and capitalization.Modify
Car.javato fix the error and recompile. ┬─┬ノ( º _ ºノ) -
Compile and execute
Driver.java. It should run properly onceCar.javais compiled. For now, we only have a single class (Car.java) that implementsDrivable. Notice that thetestmethod inDriver.javatakes an argument of typeCar. For now this is okay--just observe what is going on. -
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. :)
-
Now, add a class to the
cs1302.hw03.implpackage 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 theDrivableinterface. 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:- Properly implement the interface.
- Add appropriate Javadoc comments and update your API documentation website.
- Compile your class.
- Run your program through
check1302to make sure it follows the style guidelines.
What is the command that you used to compile your class?
-
Tricky (hint below): Update
Driver.javato test your new class. Modify the existingtestmethod (don't overload the method by creating a separate method with the same name) so it can be used to testCarobjects and objects of the new type that you just created (what doCarobjects 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 theDriverclass where necessary. In your notes, summarize the changes you made.Hint: If you're stuck on this step, it is similar to the
gatherTotalDonationsmethod in the video on Interfaces provided in the 1302 Interfaces Tutorial. ThegatherTotalDonationsmethod used an array ofDonatorreferences. Your method will just need a singleDrivablereference. -
Regenerate the API documentation website for all of the code in the
cs1302package using the Javadoc tool. You should not need to recreate the symbolic link, assuming it still exists from a prior step.
-
Add an abstract method
stopto theDrivableinterface, 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? -
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.
-
Regenerate the API documentation website for all of the code in the
cs1302package. -
Run the 1302
checkstyleprogram using thecheck1302command on all.javafiles. If errors are reported, look up each error message in the Style Guide, fix the error, and repeat until no style errors remain. -
Take a minute to notice your
stopmethod in the various places that it appears in the API documentation website that you regenerated in the previous step. -
Do not type the following command:
$ nc towel.blinkenlights.nl 23The
nccommand 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.
Each student needs to individually submit their own work.
-
Create a plain text file called
SUBMISSION.mddirectly inside thecs1302-hw03directory with the following information.- Your name and UGA ID number; and
- 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 -
Change directories to the parent of
cs1302-hw03(e.g.,cd ..fromcs1302-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. -
Use the
submitcommand to submit this exercise tocsci-1302:$ submit cs1302-hw03 csci-1302Read 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.
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.