# lab01 : Tools for java development

lab01 true Tools for java development Thu 09/29 04:00PM Wed 10/05 11:59PM

If you find typos or problems with the lab instructions, please report them on Piazza

# Overview of this lab

Here is an overview of the remaining steps in the lab:

1. If you didn’t already do it:
2. Visit https://github.ucsb.edu and login with your CSIL account, then logout immediately. This establishes your github.ucsb.edu account. BUT WE WILL NOT USE THAT ACCOUNT FURTHER IN THIS LAB.

3. Instead, login at https://github.com. After logging in, visit this link: https://github.com/UCSB-CS56-F16 You should have an invitation to join this organization. Please accept the invitation!

If you do not, please ask your mentor to invite you to the UCSB-CS56-F16 organization on github.

4. Now, create a private repo for lab01 under the UCSB-CS56-F16 organization on
• It should be called lab01_yourgithubid
• It should be private, not public.
• The owner should be the UCSB-CS56-F16 organization as the owner, not your own github id.
• detailed instructions here
5. Configure your CSIL account for git
6. At the shell prompt on any of the csil machines, type the following command:
ssh-keygen -f ~/.ssh/known_hosts -R csil.cs.ucsb.edu

• You need to do this because CSIL had new hardware installed over the summer, which caused the host key to change.
• If you get a “no such file or directory” error, then you can skip this step
7. Review a few basic facts about git, github.com and github.ucsb.edu
• detailed information here
• If you know how to do that, great.
• If not, there are detailed instructions here
9. Read through the Rational Tutorial.
• For any of the repos, you can fork the repo into your own github.com account. Here’s how:
• Go to the repo page, e.g. https://github.com/UCSB-CS56-pconrad/cs56-rational-ex01
• Click the “fork” button at the top right of the page
• If asked where to fork it, choose your own github.com account
• Congratulations: you now have a forked copy of the cs56-rational-ex01
• What do you do with it? Read on…
10. Clone the cs56-rational-ex01 repo that you forked to your cs56 account (or your personal computer).
11. Work through the eight examples shown so that you learn some of the basis material about how to work with Java:
• java, javac, ant
• build.xml files
• JUnit testing
• Copy the files from the https://github.com/UCSB-CS56-pconrad/cs56-rational-ex08 repo into the top level directory of your own lab01 repo.
• This means all of the files, including the directories. You may need cp -r for the directories. If you need a refresher on unix commands, ask a mentor, TA, or instructor for help.
• Commit an initial version of those files.
• For that, you’ll need the basic git workflow, explained here
• Once you have an initial version of the files, you are ready to start work.
• Note that to commit the lib subdirectory, you may need the -f flag, as in git add -f lib/*.jar
13. Follow the detailed instructions below to complete the assignment.

14. When you are finished, be sure you have done a “git push origin master” to push your changes to github. Then, you can downloaded a .zip version of your assignment from github, rename it to lab01.zip, and submit via submit.cs at this link: https://submit.cs.ucsb.edu/form/project/550/submission

15. Then, follow the additional instructions below to create javadoc for your project, publish it to a public repo (per the instructions) and post the URLs of your solutions to Gauchospace.

# Detailed Instructions

• Add both tests and correct implementations of these methods to the class.
• Note that for each method, you should add a reasonable number of tests. The exact number is left to you to determine, but it should be no less than three for each method.
method explanation
public static int lcm(int a, int b) returns least common multiple of a and b. See wikipedia discussion
public Rational plus(Rational r) returns sum of this number plus r
public static Rational sum(Rational a, Rational b) returns a+b
public Rational minus(Rational r) returns this number minus r
public static Rational difference(Rational a, Rational b) returns a-b
public Rational reciprocalOf() returns reciprocal (swap numerator and denominator). If numerator if zero, throws an instance of java.lang.ArithmeticException. To review exceptions, see cs56-rational-ex07
public Rational dividedBy(Rational r) returns this number divided by r
public static Rational quotient(Rational a, Rational b) returns a divided by b

Some hints to make things easier:

• (a - b) is equivalent to (a + (-1 * b))
• (a / b) is equivalent to (a * reciprocal(b))

So, don’t repeat yourself:

• Multiplication and gcd are already defined for you in the example code.
• You need lcm to find a common denominator to add two rationals, so define lcm before addition.
• The lcm can be defined in terms of gcd and absolute value—see wikipedia discussion. Absolute value is predefined public int Math.abs(int a)
• Define addition before subtraction, and then define subtraction in terms of addition and multiplication.
• Define reciprocal before division, then define division as multiplication by the reciprocal.

Signify that you are finished by committing code to a github repo that contains a modified version of ex08, with all of the following:

• a build.xml file (you shouldn't need to modify the example) Update: later instructions ask you to make a few modifications to the build.xml to update the javadoc, for example. Please do make these modifications.

• a src subdirectory containing Main.java, Rational.java, and RationalTest.java
• a lib subdirectory contining the jar file for JUnit
• a javadoc subdirectory in which you have produced the javadoc by running ant javadoc

Note that you will not be able to publish your javadoc online with the github pages technique (i.e. pushing to a gh-pages branch), because this only works with public repos, not with private ones. So, we’ve added some instructions below for publishing the javadoc to a separate public repo with the name lab01_javadoc_yourgithubid.

1. Create a public_repo with the name lab01_javadoc_yourgithubid under the https://github.com/UCSB-CS56-F16 organization with a README.md (it is not necessary to include a .gitignore).
2. cd into your ~/cs56 directory (or into whatever directory you cloned your lab01_yourgithubid repo). You want to clone your lab01_javadoc_yourgithubid repo into the same directory so that they are siblings, side-by-side in the same directory.
3. We will now add some lines into your build.xml that copy the generated javadoc from your private repo to the public repo, and we’ll set the default branch of the public repo to be gh-pages. That process is explained in detail here: Javadoc: publishing to github pages from private repo
4. Once you’ve followed the instructions in the link at step 3, your javadoc should be available online at a URL similar to the following one (but with your githubid instead of yourgithubid).
    https://UCSB-CS56-F16.github.io/lab01_javadoc_yourgithubid/javadoc/index.html


If you run into difficulties, ask your mentor/TA/instructor if in class, or ask on Piazza if outside of class.

# When you are finished

When you are finished, you’ll have:

Visit the lab01 assignment on Gauchospace to paste these URLs into the “online text” submission area for lab01.