CSE 11 Programming Assignment 1

Due Dates: Tuesday, October 5, 10:00PM Pacific Time

Learning Goals

FAQs

Permission denied issue while trying to run lecture code (Mac/Linux)

If you are working on Mac or Linux machines and you want to run the lecture code (or PA1) by using the run script, you might encounter an error that says

-bash: ./run: Permission denied

To solve this issue, run the following command first:

chmod +x run

before running the command ./run FirstExample.

Collaboration

Different assignments in this course have different collaboration policies.

On this assignment, you can collaborate with anyone in the course, including sharing code. Feel free to offer help to other students, converse about the *assignment, and so on.

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.

Part 1- Setting Up

If you get stuck at any point, do any one of the following:

Running Code

Download the starter code for this assignment by downloading this repository using the “Download ZIP” button: https://github.com/ucsd-cse11-f21/cse11-pa1-starter

PA1 download

Unzip the directory you downloaded, and open it in Visual Studio Code.

Create a new file named FirstExample.java, and put the following code into that file (you can copy-paste):

class FirstExample {
  int theNumberFive = 5;
}

Open the terminal, then run your program using ./run FirstExample (Mac, Lab) or .\run.bat FirstExample (Windows). Finally, take a screenshot of your terminal (including the commands you ran to compile and run the code).

Then, make a copy of the writeup template, answer the questions (including your screenshot).

Part 2 - Writing Methods

(Several of these examples are borrowed from How to Design Programs, and its Supplemental Material)

Problem 1: Perimeter

Develop a method named perimeter that when given the width and height of a rectangle will return its perimeter.

The rubric we will use to grade this method is:

Problem 2: Border Area

Develop a method named borderArea that given a width and height describing a rectangle, and another width and height describing a rectangle cut out of the center of the other, returns the area of the region between them. For example, the blue area in this shape:

Q2_example

Problem 3: Converter

Implementation

Develop a method (with a name of your choice!) that takes one int parameter, converts it to another int value, and returns the new int value. For example, your function could convert:

Write a comment for your method, describing what it does and what parameter it takes. If you use any outside sources for the conversion, be sure to cite those in the comment as well.

Testing

Call your method on at least 2 different examples. Compare each result against a reference converter (Many search engines have built-in converters, or you can use a calculator) and add a comment above the function call to discuss differences (if any) that you get between your program and the reference.

Problem 4: Combiner

Implementation

Develop a method (with a name of your choice!) that takes at least two int parameters, combines them to another int value, and returns the new int value. For example, your function could combine:

Write a comment for your method, describing what it does and what parameters it takes. If you use any outside sources, be sure to cite those in the comment as well.

Testing

Call your method on at least 2 different examples. Can you call your method with arguments that run, but produce an incorrect output? Call your method with at least one such pair of arguments, and add a comment above it explaining why the output is incorrect. If you cannot find such a pair of arguments, write a comment explaining why you believe no such input exists.

Submission

Your submission will be in a few parts.

  1. A PDF writeup demonstrating your setup. You can find a template for the writeup here. You will submit a PDF you create by filling in and downloading this document as PDF. Please submit your writeup to the PA1 PDF assignment.
  2. A code submission of your program with the methods you wrote for part two, at PA1 code gradescope assignment. You should select and upload the files DesignRecipeExamples.java and transcript.txt

Grading

To get your work graded, come to any remote help hours session after submitting both Gradescope assignments. A tutor will grade and give you feedback on your work during the session, and tell you anything you need to fix to get full credit. (If you just submit to Gradescope and don’t come to a remote help session to get your work checked off, we will still grade your work, but you’ll miss out on the opportunity for feedback).

You can read about the process we use for this grading.

To earn a 2:

To earn a 1, submit something but miss any of the requirements listed above for earning a 2.