2016-02-04 HW01 *FIX*

posted Feb 4, 2016, 7:10 AM by Samuel Konstantinovich   [ updated Feb 6, 2016, 6:17 AM ]
Goal: Basic Recursion + Getting stuff done!

Lab + Homework:
Deadline is Tuesday 6am.

I will grade and post results Sunday. 
No late submissions will be graded.

Lab: Discussion and working on Recursion2 problems.

Homework:
1.0 
Make a new github repo for this semester's homework.  MKS22X-HW or something similar. 
You will make a new folder on the TOP LEVEL OF YOUR REPO* for each homework starting with a 2 digit homework number. *Do not make a folder and put all of your homework assignments into it. The repo IS your "folder".

-MKS22X
--01Blah
--02Bla2
etc.

Submit your repo here:  

These are examples of directory names for this homework: 
Good       //simple
01recursion

OK!         //added a capital letter but its fine
01Recursion

Meh...     //reference to the goal on the board, but not a great name 
01Miracles

Bad!       //Reference to a song, while awesome if you make cool esoteric references, it is a terrible name for your homework folder. 
01HowDoMagnetsWork




You are writing a class called Recursion for grading purposes this must be exact.
IMPORTANT NOTE: The methods will NOT be static. I will instantiate a Recursion object to test your code.  

1.1 You are adding a method to return your name: format: "Last,First" as it appears on your school documentation.
public String name();

1.2 You are solving 1 problem recursively:

The following method will throw an IllegalArgumentException when n < 0. 

sqrt**   

public double sqrt(double n);


Now to think a little:
There is a formula to calculate square root
Guess any number for the sqrt of n. (like n/2, or even 1)

n = 100
guess = 1

Make a better guess this way: 
guess =  ( n / guess + guess) / 2

guess = 50.5

(then do it again, then do it again)
guess = 26.24009900990099
guess = 15.025530119986813
guess = 10.840434673026925
guess = 10.032578510960604
guess = 10.000052895642693
...
Notice how fast this converges on the correct value (10).

** You MUST make a helper function, because you have to keep track of both n, and your guess in the recursion. This means that you need a function with two parameters, even though the sqrt function only takes 1 parameter.


1.3 Make your code compliant with this interface so that when I test it, you will be sure that it works properly. This is a great way to test if you followed directions. 

//if you ignored any directions above(including the 1st part about non-static)
//Then this will cause tons of errors for you!
public interface hw01{
public String name();
public double sqrt(double n);
}


2. Need to study longer? (You are doing it wrong)
Let me end with a link to a video about how to study for less time and get more out of it. Even if you only watch the first 5-10 minutes you will be much smarter.
You can watch as little or as much of this video as you want, I won't ever check... but you won't increase your GPA either.  If  this video helps you do better please let me know!
This pairs nicely with every article about sleeping more to remember things better...
Comments