# Rattytouille
:::danger
<b>Due Date: Saturday, September 14th, 11:59 pm EST</b>
:::
---
**<font color="#ff0000">There is no late deadline for this project. That means anything submitted past the above date will receive no credit.</font>**
:::success
**Note:** You must complete Lab 0 before working on this assignment. Come to TA Hours if you’re having issues with Lab 0.
**Also note:** You should only edit the App, Chef, and README files inside IntelliJ, *not* in GitHub on an internet browser. GitHub just exists as a backup.
:::
# Assignment Roadmap
:::info
[Silly Premise](#Silly-Premise)\
[New Concepts Covered](#New-Concepts-Covered)\
[Helpful Resources](#Helpful-Resources)
### **[LOGISTICS](#Logistics)**
[Installing Stencil Code](#Installing-Stencil-Code)\
[Compiling and Running Your Code](#Compiling-and-Running-Your-Code)\
[Help! I’m in the wrong directory!](#Help-I’m-in-the-wrong-directory)\
[Saving Your Work on GitHub](#Saving-Your-Work-on-GitHub)
### **[STYLE](#Style)**
### **[ASSIGNMENT](#assignment-1)**
[Question 0](#Question-0)\
[Question 1](#Question-1)\
[Question 2](#Question-2)\
[Question 3](#Question-3)\
[Question 4](#Question-4)\
[Question 5](#Question-5)\
[Question 6](#Question-6)\
[Question 7](#Question-7)\
[Question 8](#Question-8)
### **[HANDING IN](#HANDIN)**
:::
## Silly Premise
Prince Zuko and Uncle Iroh have ended up in the Earth Nation. They are working hard on running their tea shop, the Jasmine Dragon. Help them serve the people of Ba Sing Se in Rattytouille!
Reference: Avatar the Last Airbender, Nickelodeon
<img style="display: inline-block; margin: auto; padding-top: 10px;" src="https://hackmd.io/_uploads/SyhrexGnA.png" alt="Rattytouille Image" width="50%">
<img style="display: flex; float: right; margin: auto; padding-top: 10px;" src="https://hackmd.io/_uploads/HywNMxM2R.png" alt="Rattytouille Image" width="40%">
## New Concepts Covered
* Compiling and running Java programs
* Print lines
* Defining methods
* Calling methods
## Helpful Resources
* This handout!
* [Calling + Defining Methods Lecture](https://cs.brown.edu/courses/cs015/lecture/pdf/CS15.Lecture_2_Calling_And_Defining_Methods.9.10.24.pdf)
* [CS15 Project Setup Video](https://www.youtube.com/watch?v=qjBdrj-ivbY&t=96s)
* [How to Master the Terminal Guide](https://docs.google.com/document/d/1PDKcm9M3ht2YESN5RLcKLiOFAx2poZXaiygtcI2o2Gc/edit#heading=h.t4j70xsw0k52)
* [CS15 Style Guide](https://docs.google.com/document/d/1olSJxbrhuIystA_kVbmKu4V8JfN7HE-eDzM5blkoeFw/edit#heading=h.b1nvuu1nggmv)
* [CS15 GitHub Guide](https://docs.google.com/document/d/1tSxfUIn-Ro6Pr1X4y21BbYKdsiK-nlWW3pGDfyh7SQ8/edit)
* [Conceptual TA Hours Calendar](https://cs.brown.edu/courses/csci0150/)
* [Edstem](https://edstem.org/us/courses/63887/discussion/)
# **Logistics**
For this homework, you are going to be writing your first Java program! Be sure to refer to [Lab 0](https://hackmd.io/@Fall2024-CS15/SJvApybhR) for help navigating the Terminal.
Half of this assignment will be coding, and the other half will be written. We have provided a **`README`** template for you to put your written answers inside. It will be turned in along with the rest of your files.
## **Installing Stencil Code** ##
**We strongly recommend that you watch the CS15 Project Setup video [here](https://youtu.be/qjBdrj-ivbY?t=96)** (starting at 1:37) that guides you through the process of installing stencil code, compiling and running the project, and saving your work in GitHub. Note that if you've already run the setup script mentioned in the video, you don't need to follow that step again.
Click **[here](https://classroom.github.com/a/jwfHy3Xn)** to get the stencil from GitHub - refer to **[Lab 0](https://hackmd.io/@Fall2024-CS15/SJvApybhR)** and the **[CS15 GitHub Guide](https://docs.google.com/document/d/1tSxfUIn-Ro6Pr1X4y21BbYKdsiK-nlWW3pGDfyh7SQ8/edit)** for help with GitHub and GitHub Classroom, but here is a summary:
1. Once you have the URL of your personal GitHub repository, open the IntelliJ terminal.
2. Move into the **`src/`** folder using the **`cd`** command to move and the **`pwd`** command (Mac/Linux) or **`cd`** (Windows) to check which directory you’re in.\
a. It’s **very** important that you’re in the **`src/`** folder before the next step - if you’re confused, check out [how to get to the right directory](#Help-I’m-in-the-wrong-directory), watch the project setup video, come to TA hours, or post on Ed.
4. Use the command **`git clone <URL>`**
5. You’ll need to rename the folder from **`rattytouille-<yourGitHubLogin>`** to just **`rattytouille`**. You will have issues running your code until you make the change.
## **Compiling and Running Your Code**
**Moving into `rattytouille` Directory**
1. In the IntelliJ terminal, type **`cd rattytouille`** to navigate to the folder where this homework is stored. Remember the **`cd`** command means “change directory”.
- If you get an error message, look at [how to get to the right directory](#Help-I’m-in-the-wrong-directory).
- In the terminal, Type **`ls`** for Mac/Linux or **`dir`** for Windows to see a list(ls) of the files in the folder. You should see three files: **`App.java`**, **`Chef.java`**, and **`README`**.
**Compiling Code**
2. Make sure you’re in the **`cs15/src/rattytouille`** directory (use the command **`pwd`** for Mac/Linux or **`cd`** for Windows if you’re not sure!).
3. To compile your code, type **`javac *.java`** in your terminal.
- If your code compiled successfully, nothing will print in your terminal. New files called **`App.class`** and **`Chef.class`** will appear in your directory. You can confirm this by again typing **`ls` / `dir`** in your terminal.
**Running Code**
4. After you compile your code successfully, move back to the **`cs15/src`** folder by typing **`cd ..`** (notice the two periods!).
5. Then run your code by typing **`java rattytouille.App`**
6. Each time you want to recompile and run your code, repeat these steps starting at step 1. If you've made any changes to your code, you'll have to recompile in order to see them.
**Here’s an example of all the steps to compiling and running your code on a Mac:**
<img style="display: block; margin: auto; padding-top: 15px;" src=https://hackmd.io/_uploads/HJUNH2z2C.jpg width=900px>
## **Help! I’m in the wrong directory!**
If you’re ever having trouble or confused about what directory you’re in while trying to compile or run your code, here’s what to do:
1. Determine which directory you are in, using the **`pwd`** (Mac/Linux) / **`cd`** (Windows) command.
2. Determine which directory you *want to be* in. For example, **`cs15/src/rattytouille`** to ++compile code++ and **`cs15/src`** to ++run code++ (as described above).
3. Figure out which directories you need to go through to get to where you want.
- Example 1: If you’re in **`cs15`** you want to be in **`cs15/src/rattytouille`**, you want to move through **`src/rattytouille`**.
Example 2: If you’re in **`cs15/src/rattytouille`** but want to be in **`cs15/src`**, you want to move backwards out of **`rattytouille`**.
4. Use the cd command to move where you need to go.
- Example 1: **`cd src/rattytouille`**
- Example 2: To move backwards one directory, **`cd ..`**
**Still confused? Post on Ed or come to Conceptual Hours!**
## **Saving Your Work on GitHub**
**<font color=#F62217>YOU MUST BE SAVING YOUR WORK! THIS IS SUPER IMPORTANT!</font>**
Refer to the [CS15 GitHub guide](https://docs.google.com/document/d/1tSxfUIn-Ro6Pr1X4y21BbYKdsiK-nlWW3pGDfyh7SQ8/edit) for more detailed instructions on how to save snapshots of your work to GitHub. We recommend doing this around once an hour to make sure you’re maintaining a copy of your code. Here is a summary:
1. Move into the **`rattytouille`** directory (the same folder where you compile your code!)
2. **`git add -A`**
3. **`git commit -m “<some descriptive message>”`**
4. **`git push`**
5. Repeat!
# **Style**
Skim through the [CS15 Style Guide](https://docs.google.com/document/d/1olSJxbrhuIystA_kVbmKu4V8JfN7HE-eDzM5blkoeFw/edit#heading=h.b1nvuu1nggmv) found on the website. This document details the specific style guidelines along which your code will be graded throughout the semester. Most of the information is not relevant yet but will become relevant as you write more of your own code on the assignments.
For this assignment, the only “style” element on which you’ll be graded is deleting **"`TODO`"** comments in the code. In Computer Science, we often write **`TODO`** comments to point out what work still needs to be done. Once it’s done, you should remove the **`TODO`** comments. Be sure to delete all the **`TODO`** comments in your **`.java`** code files before submitting — you’ll lose points if the **`TODOs`** are left in your submission!
# <a id="assignment-1"></a>**Assignment**
#### <a id="Question-0"></a> **Question 0:** Collaboration Policy and Important Docs
Read our [Collaboration Policy](https://docs.google.com/document/d/10rbbd0Y6s1JUzPe8VmoWcL_Mz26XczX-i7p2LUFa9vc/edit#heading=h.o0nwon5qvcc7). **You will not be graded or receive credit for any assignment,** including this one, **<font color="#ff0000">unless you have read the Collaboration Policy and signed the form linked below.</font>**
**[Write your answers in README]**
1. Sign the [Collaboration Policy Agreement](https://docs.google.com/forms/d/e/1FAIpQLSeyB7D3iHbjzfqZzMiEHh_zAOwGwzxkd4L4Vmib9AXPrM9dAA/viewform) and fill out [Collaboration Policy Quiz](https://docs.google.com/forms/d/1lWirTu3NyPm2A2tILwXveM0nkrJSDHA_PHnnkbEL7H4/viewform?edit_requested=true). **Additionally, you are bound by this contract for this and all future assignments. We will not be able to grade any of your assignments until you fill out this form.**
2. In a paragraph, summarize the CS15 collaboration policy as you understand it, making sure to cover the policies on homework, lab and design sections, conceptual hours, and course material. In addition, give your own rationale for this CS15-specific collaboration policy.
#### <a id="Question-1"></a> **Question 1**
**[Write your answers in README]**
Go through the [Compiling and Running Your Code](#Compiling-and-Running-Your-Code) steps above. The first time you compile and run code is very confusing, so don’t be flustered if you get stuck.
After running the code by typing **`java rattytouille.App`**, you should see three lines of text printed in your console:
```
Welcome to Rattytouille!
A new Chef named Kevin has been made.
Washing hands, putting on an apron, and prepping the kitchen...
```
For each line, search through **`App.java`** and **`Chef.java`** to **write down the name of the method within which each of the above lines is printed out.**
The **`System.out.println()`** command prints out text into your terminal. This is a great way of confirming your program has reached a certain point in the code, and will become one of your best friends throughout the course. While the **`System.out.println()`** method is the method that literally prints the text into the terminal, in this case we are looking for the method in which **`System.out.println()`** is called.
#### <a id="Question-2"></a> **Question 2**
**[Write your answers in README]**
Head over to the **`Chef`** class. Right now, a **`Chef`** can only really **`getReady()`**, which isn’t too helpful for us. We also want them to be able to make food! We’ll write a method to do that soon, but first let’s recap method definitions.
Examine the following method:
:::info
*public int <font color=#B666D2>add</font>*(int <font color=#FDBD01>firstNum</font>, int <font color=#FDBD01>secondNum</font>) {
<font color=#F67280 style="padding-left: 25px">return firstNum + secondNum;</font>
}
:::
In the README, **match the purple, yellow, and red colored terms from the above** code with the terms *method name, method definition/body,* and *parameter name*, according to their purpose.
:::info
Note: you can ignore “*public int*” and “*return*” for now. We’ll see them in lecture later.
:::
#### <a id="Question-3"></a> **Question 3**
**[Code your answers in Chef.java]**
Great! Onwards to writing our first Java method!
Write a public method in **`Chef.java`** named **`makeFood()`**. It should take in a single parameter, a String named **`foodToMake`**. When **`makeFood()`** is called later on in the assignment, **it will print out the following line**:

:::info
Note: Remember that "<>" is just a placeholder and **`String`** is a variable type that is just text.
:::
:::spoiler **Hint**
Take a look at how we use strings in **`Chef’s createChef`** method
:::
**To clarify, here we just ask you to define the method, not execute/call it. (That comes later!) When you run the program, nothing should change in your console output.**
Speaking of which, now is actually a good time to compile your program again **(`javac *.java`)** right after *saving your file*. Make sure you don’t get any errors that came from your recent code addition. This is called incremental programming, and it’s very important to do this as much as possible to make sure you catch bugs early on. Remember that it’s always a good sign if you get no errors when compiling your code <u>**BUT that doesn’t mean your code will work exactly as you want!**</u> Be sure to run it as well to check for the correct result (which will be the same output as before, for now).
In addition, <u>**please write a header comment**</u> for this method. Please follow the [CS15 Style Guide](https://docs.google.com/document/d/1olSJxbrhuIystA_kVbmKu4V8JfN7HE-eDzM5blkoeFw/edit#heading=h.b1nvuu1nggmv) for instructions on formatting your header comment. Commenting your methods will help us understand your thought process and help you remember what you did!
#### <a id="Question-4"></a> **Question 4**
**[Write your answers in README]**
Now let’s go over this code from [lecture](https://cs.brown.edu/courses/cs015/lecture/pdf/CS15.Lecture_2_Calling_And_Defining_Methods.9.10.24.pdf):
```
//sambot is a Robot
samBot.moveForward(3);
```
**Regarding what this code is doing, answer these three questions in the README using <u>Java vocabulary</u> from the lecture:**\
a) What is **`samBot`** in relation to **`moveForward`**?\
b) What is **`moveForward`** in relation to **`samBot`**?\
c) What is **`3`** in relation to **`moveForward`**?
Yay! Now you’re ready to call the method you just wrote.
#### <a id="Question-5"></a> **Question 5**
**[Code your answers in App.java]**
Earlier we made a **`Chef`** named **`Kevin`** and he hasn’t really done much yet. **In `App.java`, call our `makeFood` method on `kevin`, and have him make chili.** In other words, when you compile and run your program, the following lines should print out:

:::info
Note: When calling the method, you should not make a method “static”. If IntelliJ suggests that you make a “static” method, something else is not quite right. Make sure you’re calling the method on an **instance**.
:::
What if we want more than one **`Chef`**? **After `kevin` makes chili, create another `Chef` named `Jim`. Save the new instance as `jim`.**
**During Thursday’s lecture, you’ll learn more about creating instances, but you can use the existing code (that creates our `Chef` named `kevin`) as a guide.**
#### <a id="Question-6"></a> **Question 6**
**[Write your answers in README]**
At this point, **what lines print out in the console?**
:::spoiler **Hint**
You should have 6 lines total.
:::
#### <a id="Question-7"></a> **Question 7**
**[Write your answer in README]**
It’s important to know that just because your code compiles without errors does NOT mean that your code is perfect and bug-free! To show this, in **`App.java`**, change the line that instantiates our chef kevin from
**<div style="text-align: center;"> `Chef kevin = new Chef(“Kevin”);`</div>**
<div style="text-align: center;">to</div>
**<div style="text-align: center;">`Chef kevin = null;`</div>**
In Java, “null” is a special value that means the variable doesn’t reference anything.
With this change, go ahead and recompile and rerun your code. When you try to run the code it won’t finish running! Instead it will give you a **runtime error**. Unlike **compile time errors**, runtime errors aren’t caught in the syntax of Java, so they’ll print an error message to the terminal. Your terminal should look similar to this:

Fill in the blank with your answer in the **`README`**.
**Important:** Once you’ve finished this question, be sure to return the changed line of code to its original text (which you can see above).
#### <a id="Question-8"></a> **Question 8**
**[Code your answers in App.java]**
Jim wants to outshine Kevin with his cooking skills to win over Jeff. You can decide what food he makes, but call the **`makeFood`** method on **`jim`**!
Compile and run your program now. Does the console say what you expect it to say? If not, look over the code again and follow it from method to method to see where each line is coming from.
___
# <a id="HANDIN"></a>Handing In
This assignment must be submitted no later than **11:59pm EST on Saturday, September 14th**. ++There is no late handin for this assignment.++
To hand in your assignment, follow these steps:
1. In a terminal, move into the **`rattytouille`** folder as if you were about to compile your code
2. Type the command **`rm *.class`** (**`del *.class`** for Windows)\
a. This will remove the **`.class`** files that are created when compiling so that your submission only includes **`.java`** code files.
3. [Add, commit, and push your code to GitHub](#Saving-Your-Work-on-GitHub)
4. In the submission for **Rattytouille** on Gradescope, click on Github
5. Select your **Rattytouille** repository and the **main** branch
6. Upload!
You can submit as many times as you want prior to the deadline, and only your most recent handin will be graded. If you handin before the deadline and again after the deadline, the submission *will* be counted as late.
**<font color=#F62217> Please do not include any identifying information on your handin (name, login, Banner ID) as we grade anonymously.</font> Including identifying information will result in a deduction from your assignment.**