COMP 139 - Lab 2 - Interfaces, APIs, and Exceptions

Learning Outcomes and Introduction

In this lab assignment you will learn about:

Task 1: Using Interfaces

  1. Examine the classes below and consider what functionality they have in common. Come up with an idea for a program that could do something useful with a collection of objects like these.

    class Bicycle Download Bicycle.java
    class Horse Download Horse.java
    class Freezer Download Freezer.java
  2. Create at least one interface to provide the functionality that your program will need to work with all three given classes. Modify each of the classes as necessary to implement your interfaces consistently.

    Include the modified classes in your lab package to submit with the rest of your work in this assignment.

  3. Create at least one more class that implements your new interfaces.
  4. Write a prototype of your "useful" program in a main method class named Lab2Task1.

    Keep it simple! For example, it's okay to use pre-determined data so that you don't have to deal with real user input. Just make sure that your program demonstrates the use of your interfaces and polymorphism techniques in a way that could work with all of the classes in this task and any future implementations of your interfaces!

Task 2: Using API Documentation

  1. Create the class Rational as described by API documentation given below.

    Make sure that you read and understand the API documentation for the BigInteger and BigDecimal classes; the implementation of Rational should mostly rely on using the methods provided by these other classes!

  2. Write a main method class named Lab2Task2 that demonstrates using Rational instances to get a precise answer for a calculation that would not be accurate using floating-point math.
Open in new window

Submission

Completing all tasks in this lab should result in at least 8 separate Java files within a single package named like LastnameFirstname_lab2. Compress the package directory into a ZIP archive and upload it to the D2L assignment.

The marks for this lab are heavily weighted towards good coding practice and style. Pay attention to your code formatting, make sure you have documented all public members using JavaDoc, and include basic unit tests for all functions.

NOTE: This assignment is to be done individually. You can help one another with problems and questions, but in the end everyone must do their own work.

CriteriaMarks
Programs compile and run without error 2
Good coding style 2
Task requirements met or exceeded 2
Total 6