Lab 7: private, Getters, Setters, toString, and Memory Representation


Due Friday, February 23 at 11:59 PM

Goals for This Lab

By the time you have completed this work, you should be able to:

Provided files:

Step-by-Step Instructions

Step 1: Edit Rectangle.java

Download the Rectangle.java file, and open it in jGrasp (or a text editor of your choice). You will need to define a constructor for this class, along with a series of methods. The comments in Rectangle.java provide further details. Note that there is no main method, so you cannot run this program directly.

Step 2: Download, Open, Compile, and Run the Tests In RectangleTest.java

Download the RectangleTest.java file, being sure to put it in the same folder/directory as your Rectangle.java file from step 1. RectangleTest.java contains a bunch of tests for the methods you wrote in the previous step. Use the instructions here to open RectangleTest.java as a tests file, then compile and run the tests. All the tests have been provided, and assuming you implemented your methods correctly in the previous step, they should all pass.

You do not need to save the compiled file. However, you should still complete this step, as this step makes sure that yor completed the previous step correctly.

Step 3: Edit RectangleMain.java

Download the RectangleMain.java file, and open it in jGrasp (or a text editor of your choice). You will have to complete the addSomethingToWidthHeight method in this file. The comments in RectangleMain.java provide further details. Example output from this program follows:

BEFORE:
R1: Rectangle(3, 4)
R2: Rectangle(5, 6)

AFTER:
R1: Rectangle(8, 9)
R2: Rectangle(9, 10)

Step 4: Complete the Lab 7 Handout

A handout concerning memory representation and program outputs is distributed along with this lab. Complete the questions in the handout. You may physically turn in the handout on class Wednesday, or scan it / take high-quality pictures of it and submit it along with your code to Canvas.

Step 5: Turn in Your Solution Using Canvas

Log into Canvas, and go to the COMP 110L class. Click “Assignments” on the left pane, then click “Lab 7”. From here, you can upload your answers and your code. Specifically, you must turn in the following two files:

If you choose to digitally submit your handout, you must submit it in one of the following formats:

In addition, if you collaborated with anyone else, be sure to download collaborators.txt and write the names of the people you collaborated with in the file, one per line. Please submit this file along with the other files.

You can turn in the assignment multiple times, but only the last version you submitted will be graded.