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.
Silly Premise
New Concepts Covered
Helpful Resources
Installing Stencil Code
Compiling and Running Your Code
Help! I’m in the wrong directory!
Saving Your Work on GitHub
Question 0
Question 1
Question 2
Question 3
Question 4
Question 5
Question 6
Question 7
Question 8
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
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.
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:
src/
folder using the cd
command to move and the pwd
command (Mac/Linux) or cd
(Windows) to check which directory you’re in.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.git clone <URL>
rattytouille-<yourGitHubLogin>
to just rattytouille
. You will have issues running your code until you make the change.Moving into rattytouille
Directory
cd rattytouille
to navigate to the folder where this homework is stored. Remember the cd
command means “change directory”.
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
cs15/src/rattytouille
directory (use the command pwd
for Mac/Linux or cd
for Windows if you’re not sure!).javac *.java
in your terminal.
App.class
and Chef.class
will appear in your directory. You can confirm this by again typing ls
/ dir
in your terminal.Running Code
cs15/src
folder by typing cd ..
(notice the two periods!).java rattytouille.App
Here’s an example of all the steps to compiling and running your code on a Mac:
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:
pwd
(Mac/Linux) / cd
(Windows) command.cs15/src/rattytouille
to compile code and cs15/src
to run code (as described above).cs15
you want to be in cs15/src/rattytouille
, you want to move through src/rattytouille
.cs15/src/rattytouille
but want to be in cs15/src
, you want to move backwards out of rattytouille
.cd src/rattytouille
cd ..
Still confused? Post on Ed or come to Conceptual Hours!
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:
rattytouille
directory (the same folder where you compile your code!)git add -A
git commit -m “<some descriptive message>”
git push
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!
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]
[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:
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.
[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.
[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:
Note: Remember that "<>" is just a placeholder and String
is a variable type that is just text.
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!
[Write your answers in README]
Now let’s go over this code from lecture:
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.
[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:
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.
[Write your answers in README]
At this point, what lines print out in the console?
You should have 6 lines total.
[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”);
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:
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).
[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.
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:
rattytouille
folder as if you were about to compile your coderm *.class
(del *.class
for Windows).class
files that are created when compiling so that your submission only includes .java
code files.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.