Lab 1:   For those with Java Experience
1 Lab Objectives
2 Choose and Setup your Java environment
3 Design and Implementation Problem
4 What to Turn in

Lab 1: For those with Java Experience

1 Lab Objectives

  1. Get your Java environment configured, including with JUnit for testing

  2. Check that you can submit homework structured for automatic grading

  3. Confirm or refresh your Java design skills.

Please make sure you submit some work (including at least one class and at least one test case) to InstructAssist by the end of the lab. We are not grading your lab work, but we are going to use this submission to check that you know how to submit files such that the autograding scripts can process them. This will hopefully catch many configuration errors before it counts on the first homework.

2 Choose and Setup your Java environment

If you already have Java experience, we recommend you use Eclipse or IntelliJ (but you can use any environment you want).

If you are using your own laptop, download and install whichever tool you wish to use. If you are using DrJava on a Mac, note that you need to download/use the "Jar File", not the "Mac OS X App". See the software page for instructions on how to use the JAR file.

The software page also includes instructions on configuring your environment to use the JUnit testing framework. Make sure you leave enough time in lab to try setting up JUnit tests if you have not used them before.

3 Design and Implementation Problem

Assume you are creating a class hierarchy for a media manager like iTunes. Your software needs to manage three kinds of items, each of which has a title and a duration: songs, podcast episodes, and audio books. Despite these similarities, these items also have some differences:

Design a class hierarchy for MediaItem that has all of the features and data described here. You may put all the definitions in a single file or one definition per file, as you prefer. Your design should satisfy the following criteria (include a comment at the end identifying the aspect of your design that satisfies each one):

  1. Concepts of collection, published and categorizable are explicit in the code for your class hierarchy.

  2. Frequency checks are only supported on the pre-defined intervals.

  3. If one added a new kind of media with some combination of the collection, published and categorizable, Java would help check that all relevant methods and data were included for the new media type.

Here is a basic Main.java that you can use in your project.

Once you have your definitions, create some objects and test cases in an Examples class. This initial Examples class has the import statements that you need in order to use JUnit. The following sample shows creating an object and writing a test case for it (this assumes a Song class with just a title and song duration).

  Song HapBD = new Song("Happy Birthday", 18);

  

  @Test

  public void checkHBLen() {

     assertEquals(18, HapBD.lenInSeconds);

   }

Create similar tests for your own classes and make sure you can run them. Try a test case that fails, to make sure you know what that looks like with JUnit in your chosen tool.

4 What to Turn in

Submit a zip file of all .java files that you produced for this assignment to the Lab1 assignment in InstructAssist. Your zipped directory may contain subdirectories (such as "src" and "test", which some Java environments will create automatically). Do NOT include the .class files.

If you don’t have an account in InstructAssist, ask your lab staff for help.