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...
  1. login to a lab system
  2. cd to your local copy of your repo OR clone it again (see lab01)
  3. git pull to get an up to date copy of the repo
  4. cd labs/lab02
  5. ls
  6. You should see class SumNums.java in your directory.
  7. Compile SumNums
  8. Run SumNums with different command line arguments $ java SumNums $ java SumNums this that $ java SumNums 1 2 3 4 $ java SumNums 1 2
  9. Add everything you have been working on to the index (git add --all .)
  10. Commit it (git commit -m 'SumNums starter code')
  11. Push it so that we can see it (git push)
  12. Note: Make sure you do everything inside the lab02 directory
For the rest of the lab, you are on your own. Feel free to ask your TA or classmates for help. Make sure you teach/learn. Just going through the motions is not learning!!! Oh yes, I know you probably aren't ready to write your own Java programs, but I think you can figure most of it out!!! Look at the sample code, your lecture notes.

Finishing SumNums: A first User Story

  1. 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
  2. For reference, see sum and sum2 in the Lab02 Non Object-Oriented (OO) summary NonOOSummary.java
  3. Make sure you add the public static int sumup(int s, int e) method.
  4. Compile and Run
  5. Add, Commit and push all of the files. The message should be 'SumUp completed'.

Counting to 10

Story Card: When the program is run, the system simply prints out the numbers from 1 to 10. Example: $ java CountTo10 1 2 3 4 5 6 7 8 9 10
  1. Create class CountTo10 (inside lab02). That is, create lab02/CountTo10.java
  2. Create a 'main' method and put your counting and printing code in there.
  3. Compile and run it.
  4. 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. Story Card: A user specifies a number n. The system responds with either "Prime" or "Not Prime". We expect that the user will supply a number. Examples: $ java PrimeTester 0 Not Prime $ java PrimeTester 1 Not Prime $ java PrimeTester 2 Prime $ java PrimeTester 3 Prime $ java PrimeTester 4 Not Prime
  1. Create class PrimeTester with a main method. Steal code from SumNums to get you started.
  2. 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); }
  3. 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: 1) When you git add, where are you adding to, and why? 2) When you git commit, where are the files going? Does the remote have a copy? 3) When you git push, which files are being pushed, and where? Does the remote have a copy? Add, Commit and push gitReview.txt. The message should be 'gitReview completed'.

Verifying that you have committed your work