6  5L. Generics In Java- 2

6.1 Project Overview

.
├── src/
│   └── GenericsPractice/
│       └── Matrix.java
└── test/
    └── GenericsPractice/
        └── MatrixTest.java

6.2 Detailed Instructions

Your task is to complete the implementation of a generic Matrix class. Currently, the Matrix class is empty. A matrix is a two-dimensional arrangement of elements. You access elements with a row and column index. For example:

Matrix<String> tttBoard = new Matrix<String>(3, 3);
tttBoard.put(0, 0, "x");
if (tttBoard.get(1, 2).equals("o")) . . .

Please implement put and get methods based on the above usage description. Here, the first argument is the row index and the second is the column index.

Since we are not allowed to use generic arrays, we use an ArrayList of ArrayLists instead (an ArrayList that contains another ArrayList inside of it).

First, sketch in a notebook how you envision the rows and columns of a matrix being stored inside this ArrayList of ArrayLists. This ArrayList should be called elements. There should also be two integer members of this class - rows and columns - that store the size of the matrix.

Complete the implementations of the class. Be sure to implement getters and setters. This is what the constructor should look like:

public Matrix(int rows, int columns) {
    this.rows = rows;
    this.columns = columns;
    elements = new ArrayList<ArrayList<T>>();
    for (int i = 0; i < rows; i++) {
        ArrayList<T> row = new ArrayList<T>();
        for (int j = 0; j < columns; j++)
            row.add(null);

        elements.add(row);
    }
}

This constructor implementation also tells you what the fields of the Matrix class should be.

6.3 Rubric

  • Project must compile, otherwise no grade.
  • Complete JavaDoc for GenericsPractice.Matrix (5 points)
  • All tests passing for GenericsPractice.MatrixTest (20 points)

6.4 Project Files

Download the project files here.

6.5 Opening Project in Visual Studio Code

  1. Download the project files from

  2. Unzip the files to preferably an ITSC 2214 folder for this class. You must have created this folder before for previous labs. Unzip_Location_ITSC_2214

  3. Launch Visual Studio Code. Go to File > Open Folder…, navigate and select the folder where you have extracted the zip file. Vs_code_extract_zip

6.6 Update the autograder

First, please update your autograder by running:

umm update

6.7 Checking Autograder Feedback

You can check your grade locally by following these steps:

  1. Open a terminal. To open a terminal in Visual Studio Code on different operating systems:

    • Windows: Press ” Ctrl + ` ” or ” Ctrl + Shift + ` ” to open the integrated terminal.

    • Mac: Press ” Cmd + ` ” or ” Cmd + Shift + ` ” to open the integrated terminal.

  2. Run the command:

    umm grade ./script.rhai

6.8 Submitting your Project

When you are ready to submit your assignment:

  1. Open a terminal. To open a terminal in Visual Studio Code on different operating systems:

    • Windows: Press ” Ctrl + ` ” or ” Ctrl + Shift + ` ” to open the integrated terminal.

    • Mac: Press ” Cmd + ` ” or ” Cmd + Shift + ` ” to open the integrated terminal.

  2. You can copy and run the umm create-submission command in the terminal, and that should create a zip file with a name similar to submission-2024-01-24-15-04-50.zip.

    umm create-submission
  3. Submit the submission-2024-... .zip file to Gradescope. The submission zip file will appear in the file explorer tab of VS Code. You can right click on this file and click on reveal in explorer (windows) or reveal in finder (mac) in order to find this file. then, you can drag and drop this to gradescope for submission.