Lab 2: I’m a dot thing living in a grid world | CS 2113 Software Engineering - Fall 2023

Lab 2: I’m a dot thing living in a grid world

View the video for this lab on youtube.

Setup

Download the DotChaser.java file.

Download the Plotter.jar file.

Download the Lab2_Tester.java file.

Github setup

Use git, as discussed in Lab 0, to create a repo called gitusername-lab2, add these two files to it, and commit and push the changes to github. The timestamp of your invitation of the grader as a collaborator must be from this lab session.

Running your program

Run your lab on the command line by executing the following pipeline

java DotChaser | java -jar Plotter.jar

The program Plotter.jar is provided for you.

Testing your lab

There is no test script for this lab. Your grade is based on a code review of your object-oriented design principles; see the grading rubric.

Part 1: Rewriting the code using OOP (75 pts)

Take a look at the DotChaser program. You can compile and run it as is:

javac DotChaser.java
java DotChaser

You’ll see some interesting (but boring) output.

55 50 b
45 50 r
done
56 50 b
45 51 r
done
57 50 b
46 51 r
done
58 50 b
.
.
.

Each line represents the location and color of a “Thing” dot in each round. The end of a round is indicated by “done”

55 50 b <- round i, blue dot at row 55, column 50
45 50 r <- round i, red dot at row 45, column 50
done    <- end round
56 50 b <- round i+1, blue dot at row 56, column 50
45 51 r <- round i+1, red dot at row 45, column 51
done    <- end round

As noted, a list of coordinates is pretty boring, so we also provided you a Plotter program that reads coordinates from stdin and plots them for a nice little visual of moving dots. Try it out yourself:

java DotChaser | java -jar Plotter.jar 

The output of DotChaser is piped into Plotter, which plots each of the dots at the row,col coordinates and color given. The “done” at the end of a group of lines tells us that we are done with the “round”, so now the updated display should be shown, and what follows will be values for the next “round”. What you get is a really pretty animation like below.

DotChaser

So what do you have to do? Well, the program DotChaser is written entirely as a Procedural Program. You will re-write it as an Object-Oriented Program, and once done, you will extend its functionality a bit as well.

Note that the plotter can plot more than just red and blue. Here are your color choices as you make your things: r (red), b (blue), g (green), y (yellow), o (orange), p (pink), m (magenta), k (black).

Part 1: Create a UML diagram for your Things (10 pts)

Use Violet UML (or another tool) to generate a UML diagram for your many Thing types after reading the explanations below.

Create a UML diagram. Include it in your repo, named ‘UML.png’ and link it into your README.

Part 2: Rewrite DotChaser functionality into several classes using good OOP (65 pts)

Rewrite DotChaser as an object-oriented program. You will (presumably) be creating other .java files as well. The output of DotChaser should not change, but the design must follow all the good object-oriented design principles we have discussed. In particular, you must use encapsulation, information hiding, inheritance, and polymorphism. Maximize code reuse; keep implementation and interface as separate as possible. Your inheritance should follow the picture on the right.

You must do these things:

Be sure to add all your new Java files to the repo for submission.
</div>

Part 3: Add a new Thing (15 pts)

The original DotChaser had two types of Things: typeA, which randomly choses left, right or straight at every round; and typeB, which randomly chooses left, right or straight every 10th round. Now that you have a nice object-oriented version, create a third type of Thing called TypeC. What exactly it does is up to you, but it needs to use some diagonal motion (i.e. left-right-left-right-… sequences, or draws a circle, triangle, or other shape). The principal thing to keep in mind is how OOP makes this easier and cleaner.

Create a third ThingC type that must have.

  1. Ensure that the orignal DotChaser still works the same as before, even after you’ve added your new type of ThingC. That is, the red and blue dots act normally.
  2. The new type of ThingC must move in a new way different than typeA or typeB.
  3. In your README.md indicate the name of the new type and the Java file used to program it. Be sure to add that file to your repo for submission :)
  4. Add a paragraph to the README.md file that explains how your new OOP design makes adding new types of ThingCSs easy.
  5. Add a final paragraph to the README.md that explains exactly where in your program there is a polymorphic function call, and how that plays an essential role in the program functioning properly.

Be sure to add all your new Java files to the repo for submission.

Here’s an example of a solution with an extra yellow thing doing spirals:

DotChaser Spiral Yellow

Grading rubric and submission

Junit testing

To run your unit tests – remember, you need to have the junit jar file in the same directory – compile and run your code with the following commands on the terminal (depending on your OS):

Windows

javac -classpath ".;junit-platform-console-standalone-1.7.0-M1.jar" *.java
java -classpath ".;junit-platform-console-standalone-1.7.0-M1.jar" org.junit.runner.JUnitCore Lab2_Tester

Mac/Linux

javac -classpath ".:junit-platform-console-standalone-1.7.0-M1.jar" *.java
java -classpath ".:junit-platform-console-standalone-1.7.0-M1.jar" org.junit.runner.JUnitCore Lab2_Tester

Use git, as discussed in lab zero, to submit your work in a repo called gitusername-lab2. You will be graded on the following:

Item Points
the name of the repo for this lab matches the pattern gitusername-lab2 3
the grader has been added as a collaborator to the repo 4
the repo has been made private 3
[unit test] TypeA and TypeB are child classes of Thing 5
[unit test] Thing does not use if-statements nor the instanceof operator 5
[unit test] no static methods besides main in any of your classes 5
[unit test] the Thing class is responsible for movement, utilizing good OOP 5
[unit test] the Thing class contains the appropriate fields, utilizing good OOP 5
[unit test] the Thing class uses abstraction appropriately in all places, utilizing good OOP 5
TypeA and TypeB classes turn appropriately, utilizing good OOP 5
[unit test] the TypeA and TypeB contain the minimum number of fields necessary (declare each on a new line), utilizing good OOP 5
[unit test]TypeA and TypeB contain the minimum number of methods necessary, utilizing good OOP 5
[unit test] the ThingList class contains the Node class as an inner class, utilizing good OOP 5
[unit test] the ThingList class has methods to addAll, moveAll, and printAll Things inside the list/queue 5
the TypeC class meets the specifications above 15
a README file as specified above is included 5
a UML diagram matching the code implementation as been included, that lists all classes and their methods and fields 10
the new implementation preserves the original DotChaser functionality for TypeA and TypeB 5
TOTAL 100