CS 348: Intro Assignment

Table of Contents

1 Submit initial survey form

Fill out this introductory survey. Thanks!

What to turn in: Make sure you submit your responses to the above form.

2 Log into a department computer

Stop by CMC 102, 304, or 306 to verify that we've correctly set up an account for you on the department Macs. You should do this even if you intend to use your own computer, because you will need to test your assignments on the department computers, and we may also do some in-class labs where you would need to log in. Our setup in the CS department is a little different than elsewhere on campus, so even if you've logged into other machines elsewhere on campus, double check and make sure you can log into our department machines. If you have any problems, see our department system administrator Mike Tie in CMC 305 who will be happy to get you going.

What to turn in: In the submission box in Moodle for this assignment, tell me that you've successfully logged in by saying something like "I have successfully logged into a department lab computer."

3 Submit the startup assignment

We'll be using a Java programming workflow that may be new to some of you, so this is a simple one-liner programming assignment whose goal is to get you set up. You can do this assignment on a lab computer or your own, though you may need to install some software if you wish to use your own computer. You may have questions or difficulties as you try to set things up. That's ok; the purpose of doing this early is to help you get started. If you're having trouble making things work, you can check in with me or with Mike Tie in CMC 305. Mike in particular is a whiz at helping people get things working, so you should definitely feel free to stop by his office and ask for help if he's around.

3.1 Install software (if using your own computer)

First, make sure that you are running an appropriate release of the Java JDK. More precisely, we'll be using Java 8 for this course, which is the most recent LTS (Long Term Support) version. Newer versions of Java will likely work, but I haven't tested them; regardless, it is always your responsibility to make sure that your submissions work on the lab computers.

I'll be distributing Java projects for you to work on in two simultaneous formats: command-line, and using the IntelliJ IDEA programming environment. You can choose which way you'd rather work.

3.1.1 IntelliJ IDEA option

If you wish to use IntelliJ IDEA, make sure to install the IntelliJ IDEA Community Edition. You can find versions for all of the major operating systems. Download and install on your computer. If you installed it a while back for another course, make sure you're running a recent version of it.

3.1.2 Command-line option

You'll need to make sure that you have a text editor of your choice installed for Java programming. You'll also need to install Maven, which is a Java software building tool, and Git, which is a software versioning tool.

  • If you're using a Mac, you'll need to install Maven directly. You can download it from the Maven website. You'll then need to add the bin directory from within Maven (after you have uncompressed it) to your path. Here are some more instructions on how to modify your path on a Mac. Likewise, here are instructions for installing Git on a Mac.
  • If you are using Windows, my recommendation is to use the Windows Subsystem for Linux. Here are instructions on how to install WSL. I'd recommend choosing the Ubuntu distribution; that seems to be the one that is most popular and thus best supported. Once that is done, setting up Maven and Git is easy. Open up a bash prompt, and issue the following commands:
sudo apt update
sudo apt install openjdk-8-jdk
sudo apt install maven
sudo apt install git
  • If you are using Linux, see the above instructions for Windows. If you're using Ubuntu or another Debian-based distribution, the same commands should work.
  • For all of the above, test if you have Maven installed correctly. Close your terminal window, open a new one, and type mvn -v at the prompt. If you get versioning info for Maven, you've successfully gotten it set up.

3.2 Alternative to own computer: set up software on a lab computer.

Happily, nearly everything you need is already set up in the department labs (when booted to OS X). However, there are two things you'll still need to manually set up.

  • If you wish to use IntelliJ, it is available directly on each Mac from within /Applications. However, we're using the paid version of IntelliJ within the department, which means if you haven't used it before you'll be prompted to enter in a license server. If you are asked to enter a license server, enter in http://license.ads.carleton.edu:8080.
  • If you wish to use Maven, it is installed on the department systems, but it isn't automatically in your path. You'll need to open up a terminal window on one of the department computers, and edit the file .bash_profile. At the bottom of it, add the following line:
export PATH="$PATH:/usr/local/apache-maven-3.5.3/bin"

Then close your terminal window, open a new one, and type mvn -v at the prompt. If you get versioning info for Maven, you've successfully gotten it set up.

Git should already be installed on the department computers, so you'll have no work to do.

3.3 Clone the assignment

Get a repository set up on GitHub for your project by visiting this GitHub classroom link, and agree to accept the assignment. (It may prompt you to login to GitHub; it may also ask you to grant some permissions.) It will then create a repository for this assignment on GitHub, with some starting code, and give you a link to that repository. Click on that link. This should then take you to your GitHub repository page for the assignment. Find the green button on the right of the screen labeled "Clone or download". Copy to your clipboard the HTTPS address that appears. (If you are knowledgeable about using SSH, feel free to use that instead if you prefer.)

If you are using IntelliJ, start it up. You'll need to create a new project from version control. If you are looking at the "Welcome to Intellij IDEA" screen (which pops up if you have no other projects open), choose "Check out from Version Control", and then choose "Git". Alternatively, if you are looking at an already open project that you've previously worked on, go to the "File" menu, choose "New", "Project from Version Control", and then "Git". In either case, when prompted, paste into the URL box the HTTPS address that you copied from GitHub. You'll be prompted for your GitHub username and password; type them in. Answer "Yes" if prompted to open the file. A box may pop up in the bottom right of the screen telling you that "Maven projects need to be imported"; click "Enable Auto-Import" if you see the box pop up.

Alternatively, if you are working at the command line, navigate to a directory where you want your project to live, then issue the following command:

git clone [paste in the HTTPS URL that you copied from GitHub]

You may be prompted for your GitHub username and password. This should hopefully clone the project locally for you; you can then open up files within using your own text editor.

3.4 Look over the assignment and run the test

There are two files that you should look at.

The first file is src/main/java/Startup.java, which contains a class with a single method called increment. The purpose of this method is to take an integer parameter, and add 1 to it. The method is currently buggy and always returns 0.

The second file of interest is src/test/java/StartupTest.java. This is code that tests the increment method in Startup, by using the JUnit testing framework. The test code has one line which tests if calling increment with a parameter of 0 returns a value of 1.

Currently, the test should fail because the code is buggy. It's still worthwhile to run the test first before you fix the code to see what a failed test looks like.

  • If you are using IntelliJ, right click the src/test/java folder, and select Run All Tests (it should be about halfway down the context menu).
  • If you are at the command line, make sure that you are at the top level of the project (i.e., in the startup directory, not any of the subdirectories), and type mvn test at the command prompt.

In either case you should see some sort of failure message indicating that the test failed. In particular, you should be able to see it indicate somewhere that it expected a value of 1, but saw an actual value of 0.

3.5 Fix the code

Go into the src/main/java/Startup.java file, and fix the method. This step is not intended to be hard.

Once you've done that, rerun the test. If you got the fix done correctly, the test should now pass.

3.6 Submit your work

Submit your work to GitHub when you are done:

  • If you are using IntelliJ, go to the "VCS" menu, and select "Commit…". In the box labeled "Commit Message," type the words "finished" so that we know that this is the commit you want us to grade. Uncheck the box labeled "Perform code analysis." Then go to the "VCS" menu, choose "Git" (about halfway down), then choose "Push". In the dialog that pops up, again click "Push". You may be prompted for your GitHub username/password; enter it if need be.
  • If you are using the command line, make sure that you are in the startup directory, then issue the commands
git commit -am "finished"
git push

You may be prompted for your GitHub username/password; enter it if need be.

Note that you should not be submitting new Java files that I haven't provided. We'll be taking your Startup.java file and testing it against our own test code. Therefore, it is critical that you make sure you don't modify the test code in some way so that your code won't work with our tests. You are welcome to add your own additional tests if you like.

3.7 Verify that your code was submitted correctly

Visit GitHub, make sure that you are logged into your account, and find the webpage for your repository for this assignment. The repository should be titled startup-username, where username is your GitHub username. Make sure that the code that you see there is in fact what you intended to submit.