Lab 2 Non OO Java and git
All work to be added, committed and pushed to the remote by 11:59PM on Sunday.IMPORTANT: While you are in the lab, login in to a lab desktop, bring up chrome and visit this attendance app This will register your attendance in the lab. Make sure you have, at some point during the lab, logged in directly on a lab system (using the lab keyboard, monitor and mouse, no ssh!!).
SumNums starter code
Follow along with your TA to do the following...- login to a lab system
- cd to your local copy of your repo OR clone it again (see lab01)
-
git pullto get an up to date copy of the repo -
cd labs/lab02 -
ls - You should see class SumNums.java in your directory.
- Compile SumNums
- Run SumNums with different command line arguments
$ java SumNums $ java SumNums this that $ java SumNums 1 2 3 4 $ java SumNums 1 2 - Add everything you have been working on to the index (
git add --all .) - Commit it (
git commit -m 'SumNums starter code') - Push it so that we can see it (
git push) - Note: Make sure you do everything inside the lab02 directory
Finishing SumNums: A first User Story
- You will complete the following User Story (see class SumNums)...
Story Card: A user specifies a starting and ending number. The ending number at least as big as the starting. The system responds with the sum of all of the numbers between and including the starting and ending numbers. We expect that the user will always supply integers. Examples: $ javac SumNums.java $ java SumNums Usage: java SumNums STARTNUM ENDNUM $ java SumNums 2 Usage: java SumNums STARTNUM ENDNUM $ java SumNums 2 3 The sum from 2 to 3 is: 5 $ java SumNums 2 17 The sum from 2 to 17 is: 152 $ java SumNums 1 10 The sum from 1 to 10 is: 55 - For reference, see
sumandsum2in the Lab02 Non Object-Oriented (OO) summary NonOOSummary.java - Make sure you add the
public static int sumup(int s, int e)method. - Compile and Run
- Add, Commit and push all of the files. The message should be 'SumUp completed'.
Counting to 10
- Create class CountTo10 (inside lab02). That is, create lab02/CountTo10.java
- Create a 'main' method and put your counting and printing code in there.
- Compile and run it.
- Add, Commit and push all of the files. The message should be 'CountTo10 completed'.
Prime Numbers
Remember that an integer greater than 1 is prime if its only divisors are one and itself. So 2, 3, 5 and 101 are prime, while -7, 0 and 12 are not.- Create class PrimeTester with a
mainmethod. Steal code from SumNums to get you started. - Write an
isPrime(n)static method which returns true if n is prime and false otherwise. Use this in your main to help you complete your task. Note: In Java you can find the remainder on division of p by q by using p%q (this is p mod q).if(p%q==0){ System.out.println(p+" is divisible by "+q); } - Add, Commit and push all of the files. The message should be 'PrimeTester completed'.
Git Review
Create lab02/gitReview.txt and answer the following questions:Verifying that you have committed your work
- Open a terminal window
- Make sure you are not inside repo_$USER
- Make a new directory,
mkdir checkingLab02 - cd into
checkingLab02 - clone your repo
- Check that all of your lab02 files are there, this includes all .java and .class files, gitReview.txt.