Release: 5pm Wednesday November 3, 2021

Due: 9am Friday November 5, 2021

Note that this is released after class Wednesday, and is due before class, not due in the evening.

This page details a take-home exam that you will complete over the next few days. You can’t communicate with anyone about the content of the assignment until you receive your grade. You can message us privately on Piazza, but the course staff will not give programming advice or answer most questions about the problems. If you have technical trouble creating a screencast (detailed below) feel free to reach out for assistance.

Do not use any online service other than Piazza to ask questions about the assignment. Do not search for, solicit, or use solutions to the problems that you find elsewhere for the exam. These are all violations of academic integrity that students have committed on exams like this in the past.

You can make use of any course notes, online resources about Java and its libraries, Java tools, and so on to complete the exam, including re-using code from class notes.

You can review the grading policy for exams in the syllabus. You will complete the programming task below and submit your work to the Exam2 Gradescope assignment.

Starter code is available here:

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

Submission checklist (see long descriptions below for full details):

Make sure to look at your Gradescope submission after submitting to see if all the required files are there.

If you have a problem uploading your video to Gradescope, you can upload it here https://docs.google.com/forms/d/e/1FAIpQLSeK0_OQpd0ufiNqmeh0HlQ6Aci3WUFp8bthczJkfIxeeQxLCA/viewform. Do this only if, for some reason, you get an error (usually due to file size) when uploading to Gradescope.

Clarifications

Can we write more methods than specified?

Yes, you can write additional methods (we call them helper methods sometimes) if it helps you complete the task.

What is the WordFilter method?

The original version of the WordFilter task referred to a WordFilter method. It should have said class, and is fixed below.

Where should Tweet tests go?

The original starter file Tweets.java asked you to write tweet tests in ArrayExamples; this is wrong, and should have said TweetExamples. The comment in the file has been fixed.

Can I use X feature of Java in my code?

Same answer as in exam1

Can I use previous code that I wrote for a PA in my exam?

Yes.

What does thread mean for Tweets?

Use the definition in PA4

Task 1 – Arrays

In the ExamplesArrays class, you will use the design recipe to write several methods.

There are no specific test requirements for these methods other than the one listed in the video below; we will test them to ensure they are correct and you should test them thoroughly enough to be confident in their correctness.

Here are some tests to get you started that you can use as you like (and to help make sure we agree on how these methods work).

	void testAverageWithoutLowest(Tester t) {
		double[] unique = {1.0,2.0,3.0};
		t.checkExpect(averageWithoutLowest(unique), 2.5);
	};
	void testRegionsWithPoint(Tester t) {
		Region[] regions = {new CircleRegion(new Point(0, 0), 5), new CircleRegion(new Point(0, 0), 10)};
		Region[] result = {new CircleRegion(new Point(0, 0), 10)};
		t.checkExpect(regionsWithPoint(regions, new Point(9, 0)), result);
	};
	void testSumOfPairs(Tester t) {
		Pair[] pairs = {new Pair(1, 2), new Pair(3, 4)};
		int[] result = {3, 7};
		t.checkExpect(sumOfPairs(pairs), result);
	};

Task 2 – Interfaces

We’ve provided code for Tweet, ReplyTweet, and TextTweet and several related classes that we’ve used for PAs in Tweets.java.

Your task is to add two methods to the interface and all implementing classes:

There are no specific test requirements for these methods other than the one listed in the video below; we will test them to ensure they are correct and you should test them thoroughly enough to be confident in their correctness.

Here are a few tests to get you started (and make sure we all agree how this should work):

class ExamplesTweets {
  User joe = new User("joepolitz", "Joe Gibbs Politz");
  User greg = new User("gregory_miranda", "Greg Miranda");
  Tweet t1 = new TextTweet(this.joe, "Java 17 has a cool feature called records", 77);
  Tweet t2 = new ReplyTweet(this.greg, "Hmm I wonder if we could use it for CSE11", 12, this.t1);

  void testLongestTweetInThread(Tester t) {
    t.checkExpect(this.t2.lengthOfLongestTweetInThread(), 41);
  }

  void testAuthorPostedInThread(Tester t) {
    t.checkExpect(this.t1.timesAuthorPostedInThread(joe), 1);
    t.checkExpect(this.t1.timesAuthorPostedInThread(greg), 0);
  }
}

Task 3 – Main and Command-Line Arguments

Your task is to write a program WordFilter.java that has a WordFilter class with a main method with the following behavior:

$ javac WordFilter.java
$ java WordFilter an apple banana panama orangutan pizza
banana
panama
orangutan
$ java WordFilter not-a-substring apple banana panama
0 words contained "not-a-substring"
$ java WordFilter app apple banana app panama orangutan pizza
apple
app
$ java WordFilter
Provide at least one command-line argument
$ java WordFilter something
0 words contained "something"

That is, it treats the first command-line argument specially – it searches for that word in the other words after it the command-line, and prints those words out, one on each line. If there are no words found, it prints the message 0 words contained "str" where str is the search term. If no command-line arguments are provided, it prints Provide at least one command-line argument

There are no requirements on writing specific tests for this program, but include a WordFilter-transcript.txt to help us understand what you did (we won’t grade it, but it helps us know what happened if something goes wrong).

Video Task

You will record a short video of no more than 6 minutes. Include:

Study

We are conducting a study related to remote exams. The details are embedded below; if you choose not to opt out your exam submission may be used as part of a research project.