Inf1 OP : Lab Sheet Week 5
Overview

These exercises give you a taster of multi-dimensional arrays, combine static methods with instance methods, show you how to use external third party libraries and the basics of file system paths.

Note

In order to carry out some of these exercises, you will need classes from a third-party library called stdlib developed by Sedgewick & Wayne:

You might find it useful to browse the documentation of corresponding library classes when you have to use them.

Third party library classes are usually bundled together in a java archive file or jar-file.

If you are using a Java project in IntelliJ

You will have to download the stdlib.jar manually and include it into your IntelliJ project following these steps:

  1. Select File from the main menu bar
  2. Select Project Structure ...
  3. Select Modules under Project Settings on the left
  4. Open the Dependencies tab
  5. Click the + sign on the right
  6. Select JARs or directories ...
  7. In the new menu, find your downloaded stdlib.jar, select it and press ok (you might need to refresh the directory structure by clicking the circular refresh button in the top menu.)
This will add the library classes to your IntelliJ project and you can now use them. The manual download does not require you to import any packages.

If you are using a Gradle project in IntelliJ

You do not need to download the files yourself, they are instead offered via an online repository called Maven. To include the stdlib into your Gradle project, do the following:

  1. Open the file build.gradle
  2. Add a line for stdlib in the dependencies section under the dependencies for JUnit:
  3. dependencies {
      compile group: 'com.googlecode.princeton-java-introduction', name: 'stdlib', version: '1.0.1'
    }
                              
  4. Now select the circular refresh button in the gradle panel on the right or select import changes from the pop up message to integrate the new library into your IntelliJ project.
This will allow you to use the classes from the stdlib library but for this version you will have to use to correct package imports. To be on the safe side, add import edu.princeton.cs.introcs.*; to every file where you use classes from that library. You will also need to do that for the provided unit tests.