Final Exam

Release: 8am Saturday June 4, 2022

Due: 8am Tuesday June 7, 2022

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 (this includes Discord). You can message us privately on Piazza, but the course staff will not give programming advice or answer most questions, including clarifications, 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. Please use good judgement and take this exam with integrity and honor.

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 appropriate Gradescope assignment for each part of the exam.

Starter code is available here:

https://github.com/ucsd-cse11-sp22/cse11-finalexam-starter

The starter code will contain 3 folders, each of which will be labeled and will contain starter code corresponding to that portion of the Final Exam.

The starter code has been marked with the following annotation:

// Task #.#: [Title]
// Your code here

You will only need to add code where you see this annotation.

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

All coding tasks will be autograded.

Make sure that your submission passes autograder for your code to be properly graded.

If you are having issues with getting the autograder to run successfully, you may find it helpful to consult the Developing with the Gradescope Autograder in Mind guide.

If your submission passes the autograder, then you should see output similar to:

Be aware that the Sanity check does not check for code correctness, but rather that your code compiles.

Your submission will be graded after the deadline. You should test thoroughly yourself to make sure your program works as expected.

Clarifications

Can I use a Java feature/library/method that we haven’t covered in class?

Yes, just make sure it doesn’t break the autograder. The course staff is not responsible for fixing any submissions that fail the autograder during or after the exam.

Can we write more methods than specified?

Yes, you can write additional helper methods.

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

Yes.

Final Exam - Part 1

This part of the final corresponds to Exam 1 material. A set of incomplete tests will be provided in Sanity.java.

You will submit the following files to the Final Exam - Part 1 Gradescope assignment:

Task 1 – Interest Calculation

In AccountTester.java, you will add three new classes - Duration, Account and AccountTester.

In the Duration class, you will add:

In the Account class, you will add:

Simple Interest = (Amount * Rate per year * Time (in years)) / 100

In the AccountTester class, you will add and save to a field:

To verify that your code is working correctly, use the run command and check whether the output on the command line is what you expect.

Task 2 – Memory Model

Task 2 Code

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

class Point {
    int x, y;
    Point(int x, int y) {
        this.x = x;
        this.y = y;
    }
}

Then add a class definition called Triangle with the following specifications:

Then add a class definition called Task2:

Task 2 Memory Diagram

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 Task2-diagram.png (or another similar image file type). Submit the code in Task2.java.

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 3 – Video

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

Your task:

An example of what your video should look like when doing this kind of explanation is here:

https://drive.google.com/file/d/117NfZaHXbHtMJZJmLRVeRy-1b9cY3jei/view?usp=sharing

Here is a tutorial for creating a screencast like this https://ucsd-cse11-sp22.github.io/assignments/pa2.html.

Here are some notes on how to improve your videos:

Final Exam - Part 2

This part of the final corresponds to Exam 2 material. A set of incomplete tests will be provided in Sanity.java.

You will submit the following files to the Final Exam - Part 2 Gradescope assignment:

Task 1 - Mode

In the class Mode in Mode.java, you will write a single method called mode that takes an int[] as argument and return an int. The int[] is a list of numbers from the range of 0 to 9 in any order, but one number is missing from this range. Your task is to find this missing number and return it.

If there is no missing number then you can just return -1. You can assume that all the numbers in this list are different, in other words, each number from 0 to 9 only appears once in the argument list. You can also assume that only one number from 0 to 9 is missing for any test cases.

Example: Input: [2,3,4,9,5,6,0,7,8] Expected output: 1

Task 2 - Even Numbers

In the class Even in Even.java, you will write a main method that will read a non-negative number from the command line, and will print (on a new line) each even digit from this number. If there is nothing passed to your program from the command line or if there are no even digits, print nothing, not even a new line.

Notes:

Example:

java Even 12346
2
4
6

Task 3 - findArea

In the file Area.java, we have provided code for the Shape interface and 4 classes that implement Shape. Your task will be to add a findArea() method to the Shape interface and implement it in all 4 classes. The 4 classes are: Square, Circle, Triangle and Trapezoid

For all the findArea() methods, please return a double that represents the area of the shape.

If you are unsure about the area formula for any shapes, you are free to google the formula.

Notes: Please be careful with the calculation since we are working with int and returning a double. I recommend converting everything to double before doing the calculation. For the area of the Circle, please use the pi value of 3.14 for calculation.

Video Task

Create a video of no more than 5 minutes:

Final Exam - Part 3

This part of the final corresponds to Exam 3 material. A set of incomplete tests will be provided in Sanity.java.

You will submit the following files to the Final Exam - Part 3 Gradescope assignment:

Task 1 - SumAt

Consider the following interface:

interface SumAt<T> {
    int getSum(T t);
}

In the class Sum, you will write a non-static generic method called sumAt which will take a generic type `List` as its first argument, a generic type `SumAt` object as its second argument. The third argument will be an 'int' representing an index in the list. The method will return a single 'int' representing the "sum of the element" in the list, at the index specified by the third argument, by using the corresponding SumAt() class.

If the index element in the list is null or if any of the arguments are null, return 0.

Task 2 - OccurrenceSum

In the class OccurrenceSum in OccurrenceSum.java, you will write a program that will take csv file names as command line arguments. Each csv consists of ‘word,value’ pairs separated by a new line. Words may appear multiple times in the csv and across csv files. Print out the word whose total value is the greatest across all data files along with the number sum of the total value. You should print out each pair of values in the form word, total_value. As an example, for java OccurrenceSum data_1.csv data_2.csv data_3.csv, your code should print occasion, 170. If there are ties, then print all the ties on a new line (in any order). If no csv file names are given or all csv files are empty, then print nothing, not even a new line. You are allowed to import and use Java libraries.

Video Task

Create a video of no more than 5 minutes: