teaching machines

Homework 0 – Goodbye, Pluto

June 4, 2019 by . Filed under cs1, fall 2019, specifications.

Your task in this homework—which is worth no Blugolds—is to set up your repository and IntelliJ IDEA project and to acclimate yourself to the SpecChecker grading tools.

GitLab

You are probably used to two kinds of systems for editing and managing files. Some tools are installed on your local machine and edit files stored on your computer or USB drives. Other tools are cloud-based and edit files stored on remote computers, perhaps through a web browser. This semester we’re using a tool called Git, which blends these two approaches.

Your project will reside remotely on computers managed by GitLab, but you will make edits on a local copy. At the end of each coding session, you push your local changes back up to GitLab. This hybrid system has several advantages:

A project has already been made for you and it is waiting for you on GitLab at this address:

https://gitlab.com/cs1_2019c/USERNAME

Visit this address, replacing USERNAME with your UWEC username, and you will find that you do not yet have permissions to access your project. Create an account using your UWEC email address on GitLab and then email (not Piazza) your instructor, who will add you to the project. (Having to wait on your instructor is clumsy. Maybe someday GitLab will make it easier to add individuals before they create accounts.) Your GitLab username can be whatever you want; your instructor doesn’t even need to know it. However, you must use your UWEC address. You can add other addresses later.

Once you have gained access, you will see a listing of all the files currently in your project, including .idea, speccheckers, .gitignore, and others.

Directory

Soon we will make a clone of the remote GitLab repository on your local computer. First, create a new, empty directory on your local computer in which to store the clone. I recommend naming it cs145 or cs148. Make note of the location. You may need it later. If you are on a university computer, select a directory on your H: drive. Never store anything on the C: drive, as it gets erased nightly.

Git

For our computer to synchronize the local clone with our remote GitLab repository, we need Git installed. Download and install it. The default settings are fine. You won’t need to open any of the Git tools directly, so you can forget about this application once you have a working setup.

Intellij IDEA

We now clone the GitLab repository on your local computer. Complete the following steps to get your local clone:

You only need to clone once per computer that you use. (If you use only university computers and your H: drive, you won’t need to clone ever again.) The next time you open IDEA, navigate to this existing project using Open or Open Recent.

We’re now ready to dive into the actual homework specification.

Requirements

Your solution must meet the following specification:

SpecChecker

Learning goes something like this:

  1. You do something.
  2. You receive feedback.

Your instructor doesn’t want you to spend a lot of time in stage 1 and only a little time in stage 2. So, he has provided a tool called a SpecChecker that you can run as often as you want to see how well you are meeting the homework requirements. This tool isn’t designed to fix your problems for you—only to make you aware of them. You will still have to think.

To run the SpecChecker for homework 0, find the green play button in IDEA’s toolbar. To its left is a dropdown menu. Select hw0 SpecChecker and click the play button. You should see output that includes the following text:

I couldn't find a class by the name of "hw0.Greeter". Check CamelCase, spelling, and that you created your class in the right package.

The SpecChecker is telling us that it can’t find a class that’s required for the homework. If you want the 0 Blugolds that this assignment is worth, you’d better add it.

Create a Package

Note that the requirements state that the Greeter class must be in package hw0. Right-click on the src folde and create a new package named hw0.

Packages are like directories. You will use them to organize your code for this course. Each homework will go in its own package.

Create a Class

With the directory in place, let’s add the Greeter class. Right-click on the hw0 package and select New / Java Class. Enter Greeter as the name. The file Greeter.java is placed inside the hw0 package and opened for editing. It contains the following text:

package hw0;

public class Greeter {

}

Run the SpecChecker again. You should see this output:

I couldn't find method main(String[]) in class hw0.Greeter. Have you written it? Does it have the right name? The right parameters?

Create Main

Though you have the required class, you do not have the required main method in that class. Let’s add it. Place your cursor so it’s on the blank line between the curly braces. Hit tab to indent one level. Clear indentation makes it easier to understand how your code is nested. Noticing patterns and structures is how you become a skilled software developer.

Now type the word psvm and hit Control-Space. Select the entry to add a main method that looks like this:

package hw0;

public class Greeter {
  public static void main(String[] args) {
    
  }
}

If your indentation doesn’t match the code above, hit Control-Alt-L or Command-Option-L to have IDEA automatically reformat your code.

Failure

Run the SpecChecker again. You should see this output:

When running Greeter.main, I did not see the expected output.
  Expected line 1: "Goodbye, Pluto!\n"
  But I didn't get line 1 from you at all.

The SpecChecker captures the output of your program and compares it to the expected output. Your program had no output, so it certainly did not match. Add a print statement to print Goodbye, Pluto... :(—which is not quite the required output. Run the SpecChecker again. You see the following output this time:

PROBLEM: 
When running Greeter.main, I did not see the expected output.
      This is what I expected: Goodbye, Pluto!\n
  This is what I actually got: Goodbye, Pluto... :(\n
                  Differences:               ^^^^^^^^

The carets/circumflexes highlight the differences between the expected and actual output.

Success

Fix your print statement so it does the right thing. Test it apart from the SpecChecker so that you understand the behavior of your own code. If you treat the SpecChecker like a crutch, using it to hobble from error to error, you will have a very discouraging semester.

To run your class on its own, right-click or two-finger-click on the Greeter.java editor window and select Run Greeter.main().

When you like the result, run the SpecChecker to verify that everything’s okay. Reselect it in the dropdown menu next to the play button.

When all functionality tests pass, you will be asked to confirm that you’ve used meaningful variable names and that you’ve properly submitted your work. After you confirm, you should see the following output:

High five. You have passed all tests. Now commit and push before the deadline.

Your code works! But you’re not done yet. You still need to get your code up to GitLab so your instructor can grade it.

Submission

To submit your work for grading:

A passing SpecChecker does not guarantee you credit. Your grade is conditioned on a few things: