CSE 11 Programming Assignment 3

Due Date: Tuesday, October 19, 10:00PM Pacific Time

Learning Goals

You can come to lab hours, in-person or remote, to get a pre-grading check-off for this assignment.

You can see the check-off instructions here:

https://docs.google.com/document/d/1Vw_rkgNaRNNgVJpricZC1s_6icoftsssUOVCOyemCsU/edit?usp=sharing

Collaboration

Different assignments in this course have different collaboration policies. On this assignment, you can collaborate with anyone in the course, but you must create your own memory diagrams and descriptions for answers. In your submission, give credit to all students and course staff who helped you with this assignment by noting their name and how you used their ideas or work. Note that using someone’s work without giving credit to them is a violation of academic integrity.

Submission Checklist

You can download the starter code for this assignment here:

https://github.com/ucsd-cse11-f21/cse11-pa3-starter

You should submit:

Task 1

Task 1 Code

In the file Task1.java, add the following class definitions (you can copy/paste them from here):

class C1 {
  C2 other;
  C1(C2 other) {
    this.other = other;
  }
}

class C2 {
  int x;
  C2(int x) {
    this.x = x;
  }
}

Then add a class definition called Task1 with the following fields:

Task 1 Memory Diagram

Then, create a memory diagram of the objects you created. Focus on the objects as they appear in the output and as created at the end of the program (there are no meaningful stack frames to draw). Submit the memory diagram in task1-diagram.png (or another similar image file type). Submit the code in Task1.java1.

Your memory diagram should include:

You can draw it on paper and take a picture, draw it digitally, or use a tool like Google Drawing to create it.

Task 2

Create a class named R that has two fields: one of type String and one of type R. Give it the usual constructor that initializes both fields. Put the class in a file called ExamplesR.java. Add an ExamplesR class to this file, and answer the following question with code and comments in that file:

Construct an example R object. Were you able to? Copy the output of running your program into a comment in ExamplesR.java if you were able to, and explain why you think it’s not possible if you weren’t.

Submit the ExamplesR.java file for this task.

Task 3

In Lecture 9 we discussed drawing traces and memory diagrams for the RectRegion class. Draw a trace of the method call to contains in the following example:

RectRegion pa3Rect = new RectRegion(new Point(10, 20), new Point(30, 40));
Point p = new Point(50, 60);
boolean result = this.pa3Rect.contains(this.p);

Make sure to include:

Submit the memory diagram as task3-diagram.png (or another image filetype).