Skip to main content

Homework 0: Hello World & Errors

Due: 2024-02-01 23:59:00EDT

Write a program, Fortune.java, which prints a fortune like the ones typically found in fortune cookies. Use the program as a starting point.

1.  // Name:
2.  // Date:
3.  // Description: Print a fortune to the console
4. 
5.  public class Fortune {
6. 
7.    public static void main(String[] args) {
8.      System.out.println("Hello World!"); // todo: your message here
9.    }
10. } 

You can download Fortune.java from the course website using the following command:

wget https://bmc-cs-113.github.io/hws/hw00/Fortune.java

Make sure to first cd (move) into the hw00 directory that you made in Lab00. You can do so by running:

$ cd cs113/
$ cd homeworks/
$ cd hw00/

Run pwd to confirm that you are in your hw00/ directory. Then run the wget command from above.

Below is an example of compiling and running the program in the command line:

$ javac Fortune.java
$ java Fortune
A journey of a thousand miles begins with a single step.

Dont forget: make sure to fill in the header in Fortune.java.

Error Messages (10 points)

Programming is very similar to writing. A first draft is always messy. Its no different when programming, you’ll make plenty of mistakes when first writing any program. A nice thing about programming is that the compiler is your friend who will tell you the mistakes that you’ve made. First delete the binary file (Fortune.class) that was created when you compiled Fortune.java.

In this part of the assignment, we are going to make some mistakes on purpose. For each of the following changes 1) copy the error message you see when compiling the program and 2) a simple explanation of what you think that message might mean. If the program compiles, try running it.

Save your answers in a new file called ERRORS.txt. After making each edit listed below, revert the edit so that the file is the same as when you ended the last part of this assignment.

  1. Remove the ; at the end of line 8.
  2. Change Fortune in line 5 to fortune.
  3. Change main to blah in line 7.
  4. Remove the } in line 10.
  5. Remove the } in line 9.
  6. Create your own error (describe the change in ERRORS.txt)

What is Computer Science? (5 points)

Read Computer Science: Not about Computers, Not Science.

In a new file called HW00_READING.txt answer the following questions:

  1. According to the author, if computer science is not about computers, then what is it about?
  2. In your own words, what is an algorithm.
  3. According to the author, why is computer science not a science?
  4. The author writes that he “often find[s] that eager undergraduates are either excited about something that is not CS, or stems from an advanced topic that definitely is CS.” Are there any things that you are excited about that you thought is CS but might not fit under the author’s definition of CS? Alternatively, are there any advanced topics that excited that you now think are definitely CS based on the author’s definition.
  5. Feel free to provide any additional feedback.

Submitting

Submit the following files to the assignment called HW00 on Gradescope:

  1. Fortune.java
  2. ERRORS.txt
  3. HW00_READING.txt

Make sure to name these files exactly what we specify here. Otherwise, our autograders might not work and we might have to take points off. DO NOT submit a .docx or .pdf file.

Copying the files

You will likely want to submit the files from your own laptop/computer. To copy the files from goldengate to your own machine, open up a terminal on your own computer. If you have a mac or linux, you can use the Terminal application, if you have a windows you can use the Powershell app.

Run the following command:

$ scp -r <username>@goldengate.cs.brynmawr.edu:/home/<username>/cs113/homeworks/hw00/ .

Make sure to replace <username> with your username. scp is a command to secure-copy files from one server to another. In this case, from goldengate to your own machine.