Rattytouille

Due Date: Saturday, September 14th, 11:59 pm EST


There is no late deadline for this project. That means anything submitted past the above date will receive no credit.

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

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

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →
Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

New Concepts Covered

  • Compiling and running Java programs
  • Print lines
  • Defining methods
  • Calling methods

Helpful Resources

Logistics

For this homework, you are going to be writing your first Java program! Be sure to refer to Lab 0 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 (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 to get the stencil from GitHub - refer to Lab 0 and the CS15 GitHub Guide 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, watch the project setup video, come to TA hours, or post on Ed.
  3. Use the command git clone <URL>
  4. 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.
    • 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

  1. 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!).
  2. 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

  1. After you compile your code successfully, move back to the cs15/src folder by typing cd .. (notice the two periods!).
  2. Then run your code by typing java rattytouille.App
  3. 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:

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

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

YOU MUST BE SAVING YOUR WORK! THIS IS SUPER IMPORTANT!

Refer to the CS15 GitHub guide 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 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!

Assignment

Question 0: Collaboration Policy and Important Docs

Read our Collaboration Policy. You will not be graded or receive credit for any assignment, including this one, unless you have read the Collaboration Policy and signed the form linked below.

[Write your answers in README]

  1. Sign the Collaboration Policy Agreement and fill out Collaboration Policy Quiz. 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.

Question 1

[Write your answers in README]

Go through the 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.

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:

public int add(int firstNum, int secondNum) {

return firstNum + secondNum;

}

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.

Note: you can ignore “public int” and “return” for now. We’ll see them in lecture later.

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:

Screen Shot 2024-06-16 at 11.32.15 PM

Note: Remember that "<>" is just a placeholder and String is a variable type that is just text.

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 BUT that doesn’t mean your code will work exactly as you want! 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, please write a header comment for this method. Please follow the CS15 Style Guide for instructions on formatting your header comment. Commenting your methods will help us understand your thought process and help you remember what you did!

Question 4

[Write your answers in README]

Now let’s go over this code from lecture:

//sambot is a Robot
samBot.moveForward(3);

Regarding what this code is doing, answer these three questions in the README using Java vocabulary 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.

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:

Screen Shot 2024-06-17 at 12.06.04 AM

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.

Question 6

[Write your answers in README]

At this point, what lines print out in the console?

Hint

You should have 6 lines total.

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

Chef kevin = new Chef(“Kevin”);

to

Chef kevin = null;

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:

Screen Shot 2024-06-17 at 12.16.22 AM

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).

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.


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
  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.

Please do not include any identifying information on your handin (name, login, Banner ID) as we grade anonymously. Including identifying information will result in a deduction from your assignment.