Thursday, March 24, 2011

Scope

Today we went over the efficiency of the fibonacci code. Even though it's short, it's really in-efficient since it calls itself a lot with higher inputs (over 2 million for an input of 30!).

We also learned about the scope of a program. Basically it's the perspective of the currently running code, or where your code searches for values. The rest of it pretty much went over my head.
The last thing we learned was that in java, arrays can be modified, but we can't immediately swap the values of two arrays.

P.S. - As we all know, we still have to do this weeks homework(i'm no exeption..) so get on it!!

Fibonacci

In class we learned that when you call the method reduce it changes the value of the array and the count but not the value of the len.

We also learned the fibonacci code and we did test preparation.

In the fibonacci code when using blue jay the computer recalculates the whole sequence to get the next value of the fibonacci code.

They add the first two index's to get the next index then recalculates all the index's to get the next sequence of the set.

Tuesday, March 22, 2011

Recursion and Palindromes

Today was a very confusing day for me in class at first.

Today in class we focused on continuing our lesson with recursion and palindromes. To take a problem and repeatedly reduce it to simpler problems is what is known as recursion.

The example we did in class today was our do now. It dealt with coming up with a recursion to tackle the problem of how many ears x amount of bunnies would have if each bunny has two ears. At first I was confused about this and wondered how I would tackle it. But I remembered that we did a recursion problem on Thursday and looked backed on it. This helped greatly which I encourage everyone to do. Look on pass examples.
Remember these three rules to be golden:
1.Find out how to take just one step.
2.Break each journey down into one step plus a smaller journey.
3.Know when to stop.
When you are learning to walk you must learn how to take your first step. When you set a goal to get somewhere as a child every step u take breaks your journey into a smaller step and less of a distance to cover. And when you reach where you are going you stop. Who wants to hit themselves walking into a table.


Towards the middle of the class we started tackling palindromes.
A man, a plan, a canal, Panama!
Read it backwards and yes its cool. This is what is known as a palindrome.
Our example Mr. Jacoby walked us through was to see how to find a palindrome of a string object. The link to the notes which can be found here shows the problem of seeing how we can find palindrome with the first three letters of the word hello. I found this very confusing and I am still eluded by the coding of this. But in essence what I grasp was a piece of code that checked if the letter was the same spelled forward and backward. For example BOB.
The last thing we tackle in class was the Maze. Or as i call it how can programmers do this because its amazing. A code that works it way through a maze. Although we didn't have a chance to go through it, Mr Jacoby showed us how it worked. The link provided shows us how the object going through the maze checks the first direction north and checks all directions if it can go.
This is the end of my first blog EVER. Hope I did alright and you guys find this informative.


recursion

just trying to blog

Well today was an interesting day because with that snowy rain and thats it 4 the day. this is my 1st time doin this so excuse me 4 messing up with anything.

What we learned in class today was about recursion, but it was at the last 10 minutes of class because all of us were doing the jumper project. From Mr. Jacoby recursion is a strategy for solving problems by
repeatedly reducing them to simpler problems.

For example: factorials
5! = 5 x 4!
4! = 4 x 3!
3! = 3 x 2!
2! = 2 x 1!
So from what i got the lower u go the more u can understand what is the answer.
Also that the repitition of it would eventually end it up being easier to do by that every time it recur it would repeat and then the simplest form and then from there go forwards then u should be able to get your answer.

Recursive problems are broken down into two cases

line 1. The base case: the simplest case where no computation is necessary.
line 2. The recursive case: everything else - brings us to closer to the base case. It simplifies or reduces the problem.

                        public int factorial(int n) {
line 1:                           if (n == 0) return 1;
line 2:                           return n * factorial(n ‐ 1);
                        }


All loops can be written recursively though its not a good idea! 

Tuesday, March 15, 2011

INTERFACES!!!

So today we learned about interfaces. We started off class with the do now, which was to explain how you "drive a car." The people who participated explain more in details what the driver does and not explaining about the kind of car. I really didn't get what he meant by that, but since there's different kind of cars they word differently? O.o
Interfaces is an area between 2 systems, where they interact with each other. This ties in with the do now because to drive a car you need two things, a driver and a car of course. They both work together, sorta,to make the car move.


Benefits of Interfaces
- each system works only on its itself and doesn't care about other systems
- they're all independent so its easier to use and more flexible, whatever that means.
There are certain things that interfaces can and can not do, which is all on the website so I won't bother re-writing it.
check it out!!!!! -----------> http://web.aprchs.net/jacoby/mj2x_2011
Another thing I can sorta explain more on is comparing interfaces.
ComparableInterface
It "marks" classes that are comparable, this means you can decide to sort objects in whichever way you want.
EX.
public int compareTo(T obj)
This is going to compare T to an object but using int O.o yea idk
the way I worte it is -int/<, 0/= and +int/>



ok, well im done now. hopefully I didn't confuse anybody! :)
and there's tutoring 4th & 8th for those who need help! be there or be square xD

Monday, March 14, 2011

computer science 3/14/11

HAPPY PI DAY :D


Today's lesson in APCS was based on the pi day contest that the whole school goes through held by all of our known math teacher's Levy, Jacoby, Reisman, and others.
From our class, Omar managed to memorize 93 digits of pi (for what I dont know -__- lolz).

We also installed Eclipse, which like Blue Jay, is another coding "environment" for java. To install Eclipse, all you have to do is unpack the zip file download in the directory you want. When you unzip the file, it creates a subdirectory called "eclipse", with other subdirectories under that.

We got our tests back today, and you're like me who failed, you shouldn't worry about it to much because Jacoby curved the grade. So, take the grade you got on your test and find the square root of that and times it by 10, and that is your grade. Still failed...well try harder next time. =D
teachers Pictures, Images and Photos

Tuesday, March 8, 2011

Test Review 2 plus some Blogspot fail

Well i started about, um an hours ago, and i was trying to post cause it was my turn. So basically i ended using Fern's account to post what i thought i learned today. -SANTIAGO!!!

Firstly, today was super brief (lucky me) and we were refreshed on how an ArrayList works.
for example in ArrayList named List... Do you know what
List.add(x) means?

Well cause ArrayLists are more "Complex" than regular arrays so they have many different codes that remove and add variables to the Array.

Of wait getting ahead of myself now :)
List.add(x) meant that in the ArrayList of List , x was added/implemented to the end of the list. Although Mr.Jacoby didnt further explain this, to the end of the ArrayList did not mean it would literally go to the "end" but to the next space after a variable, if there was no variable inputted and x was the first, then it would be in the first.

Seems vague but most things are.

We were also refreshed on how to add a variable to an index in the ArrayList the code would be the same, a code demonstration would work out better...

List.add(1,5) <=This implements the second indeces, as we have to start counting by one, with the variable 5.

One thing what we have to keep in mind is that when an index is already being used and you add another variable to that indeces using this code, the remainder is shifted up the ArrayList.
so...
List{5,7,4,1}

List.add(1,3) <=the ArrayList will automatically shift the 7,4,1 up and the new array will be List{5,3,7,4,1}.

I NEED to finish off as I'm scared my blog will, or is taking up the webspace xD.
Extra notes>>>>>>>[ ] brackets means what you're declaring is an array,and ArrayList get larger by copying their current variables into a larger arraylist so the ArrayList space is endless and I'm guessing this wasn't so brief after all...-SANTIAGO

Monday, March 7, 2011

Look at that, test review (And random Tidbits of stuff from Fern :D )

Happy Monday guys (Even though its almost Tuesday, being that its 10pm already)
Well today in class, we really only did test review and some GridWorld code for DancingBug
While going through the DancingBug code, one important thing was brought up (In my opinion) which I would like to bring up again:
ARRAYS ARE NOT EASILY UPDATED IN FOR EACH LOOPS!
(Can be done according to Mr. Jacoby, but is somewhat difficult)

Okay, done with Dancing Bug (Free flowing thought: Does anyone else notice how useless the ay in okay actually is? If its not there, it still sounds the same)

Now on to our test review.

Personally, I believed his test was difficult, but thats what our test reviews are for right?

In class, for our test review, we went over all the questions, but discussed questions 1, 6, 8 and all after (Made me notice how bad I did :p )

Questions 2,3,4,5, and 7 were all discussed "Carousel Style" By our own Julio, Omar, Shakira, and Alfredo (Good Job on getting you respective questions right guys)

The interesting question though, was number 11, which had a bug
It asked what would happen when (arr[i] > 0) instead of when (arr[i] <= 0)
(Or was it (arr[i] <= 0)? See now I don't remember)
We were all given credit though, and those who gave a reason as to why it was buggy/incorrect were given bonus points

To end this blog post, I have two announcements to make, which should be known, since we were already told in class, BUT:
1. To those who want to expand on Omar's blog post about REACH on Saturday, e-mail or speak to Mr. Jacoby
2. Do your CodingBat assignments. Not only do they count as homework, they are a great way to study for our UPCOMING EXAM ON THURSDAY!

Thats all, and a random quote for you guys:

Remember, even a blind squirrel is right twice a day (Still don't know what this means)

Have a good day folks (:







Sunday, March 6, 2011

REACH Session #2

During our second session with Mr.Marques we reviewed Arrays, ArrayLists, Inheritance, Polymorphism, and Recursion.
Everything else is something that you should know from class except for recursion and some polymorphism.

For most examples, the teacher uses Mario Kart to explain object-oriented programming.
You can think of the world as the racetrack and the players as the objects.




When you select your player in the game that player is created and you then play the game.
This is analogous to constructing an object through a client method. Once you created it, you can use it (you can play with it).







All of the players have different cars. Mario has a red car, Peach has a chariot hybrid, Donkey Kong has a car made out of trees etc. They are all still vehicles (an abstract class, there aren't really any vehicles! they must be a car or truck etc)and share the same methods. When you push the accelerate button on your console as Peach, you move forward. The same happens when you're Bowser but you move a lot slower. The vehicle interface may have a go() method that is overridden by classes that implement it since they all act a bit different when they move.
This is called polymorphism. Classes have the same method but use it differently.


This can look something like this:

public interface Vehicle {
void go();
}

public class MariosCar implements Vehicle {
public void go() {
/* goes at 50 mph*/
}
}

public class BowsersCar implements Vehicle {
public void go() {
/* goes at 10 mph*/
}
}

We also learned recursion which is, according to Mr.Marques, the hardest topic in CS.
He gave us an example of writing factorials like this:

public int factorial(int n) {
if (n==1) { return 1; } //this is the base case
else {
return n* factorial(n-1);
}
}

It's a complicated topic but easier if you trace it as you go.

He also gave us practice problems to do at home and sent extra copies for those who missed the session.
The next REACH session is on 4/30, by then you should have reviewed everything and come to him with questions.
Remember to use the barron's review book! he strongly recommends it!

Friday, March 4, 2011

Polymorphism and abstract classes

Thursday's lesson was a bit easy to comprehend. Mr. Jacoby taught us a brief concept of polymorphism and abstract classes. Polymorphism is the ability of the Java virtual machine to determine at runtime which version of a method should be used based on the actual class of the object (instead of the declared type of the variable). In other words, it is the ability of a reference variable to change behavior according to the object instance it is holding. The java virtual machine determines the proper method to call the object. The example we did in class was:

Animal class declares speck: it says "hi".
Dog class extends animal, it overrides speck: it says "woof".
Cow class extends animal, it overrides speck: it says "wassup?".

public void talkToAnimal(Animal a) {
a.speak();

}


a will be an object. The object can be Animal, Dog, or Cow. So if the object is cow, it will therefore call out "wassup?" If the Java virtual machine did not know the object, it wouldn't have done anything.

.....

An abstract class declares fields and abstract methods so that its subclasses can use them, but it represents an abstract idea that can't itself be instantiated. An abstract class need concrete subclasses to implement abstract methods. Concrete subclasses are specific. For example, an abstract class would be Car and a concrete subclass would be Move.


- I tried to explain as best as i could and i hope this helped.


Be sure to do Homework 18 (due Monday): GridWorld pg. 15 # 4 (dancing bug!!)

Reminder: We have REACH tomorrow!!....Note: The GridWorld assignment will be bonus for students who attend REACH.




Wednesday, March 2, 2011

Inheritance and GridWorld Actors

Today we reviewed the basic concepts of inheritance and some of the actors in the GridWorld program.

An inheritance diagram is a lot like a family tree with ParentClasses (SuperClasses) and ChildClasses(SubClasses)
An example is a Car SuperClass with SubClasses RaceCar and Truck which are different types of cars (duh!)
This example is shown here:
The arrow from the SubClass to the SuperClass basically means "is a".
So you would read RaceCar is a Car and Truck is a Car.
You wouldn't say Car is a RaceCar because a Car isn't necessarily always a RaceCar (you're parents don't drive race cars!)
As a kid would from it's parent, the subclasses inherit the characteristics of the superclass (methods). However, if a subclass has a method with the same name as a method in its superclass it overrides the superclass' method completely for that specific subclass.

The actors that we've learned about in GridWorld have been the bug, flower, and rock.
They behave much like they do in real life:
rock- does nothing
flower- becomes darker
bug- moves around (takes a step in the direction of it's antennae unless there is something in the way such as a rock or border in which case it turns 45 degrees to the right)
We also learned about different variations of the bug class such as BoxBug, CircleBug, SpiralBug, and ZBug which is due tomorrow.

If you're having trouble understanding inheritance look inside chapter 3 of your barron's review book, it explains things nicely.

Monday, February 28, 2011

Grid World

Okay class, Today's lesson was pretty simple:
1) By now everyone should have installed Grid World on their computers in school( and at home). For those of you who have already installed it, i hope you took the initiative to observe and experiment with GridWorld. I hope that you took note of the actors(bug, flower, or rock) and played around with the methods that you can invoke on the actors.

Mr. Jacoby also taught us a little about subClasses and parentClasses and childClasses. If you need extra help with them you can turn to chapter 13 of our java concepts test book where you will find everything you need to know about constructing subClasses.


* Don't forget the homework that is due on Wednesday
Read from pages 10-12 and answer exercise questions 1 and 2 on page 13.
** For those of you who did not complete the homework that was given over the break due to installation problems I hope what we did in class has helped and you will be able to complete it as soon as possible.

Wednesday, February 16, 2011

TEST REVIEW!!!!

Today in class we studied for the test tomorrow. We didn't really learn anything new from before execpt arrays & array list. It helped a lot I understood it way more & I should do good on this test.

For Array :
Creating,Acessing, & Updating
Algorithms (search,copy,etc.)

For ArrayLists :
Creating,Acessing, & Updating
Algorithms (search,copy,etc.)

Minor topics :
Wrapper Classes ( Integer,Double,Long)
Generic Types(ArrayList)

Many simple stuff but if you study today & stay focused you should do good on the test. So I am going to keep studying. GOOD LUCK TOMORROW :]

Tuesday, February 15, 2011

Programming with a side of Cow Munchies.

Hey there fellow classmates! :D
What we did today was continue on our lovely Cow Pie game, in which you..er..hunt a cow's sweet droppings for the day. The game is kind of like a super simple version of mind sweeper, all you have to do is guess a row and column, and hopefully, in this case, you find Winne the "Pooh" . Also, some of us, including me >.<, had a little trouble with the Random class, so here's how to do it: (you can also look online at http://web.aprchs.net/jacoby/mj2x_2011).

1) Import the the Random class, java.util.Random
2) Construct a new Random generator, Random generator = new Random();
3) make number generators for int pieRow & pieCol,
int pieRow=generator.nextInt(ROWS);

same for pieCol, just use COLS.

The link to the code is at the bottom of the blog. Us super and awesomely smart children have to revise certain parts of the "Hunt Cow Pie" code the J - Man left for us, which is due tomorrow. So have fun finishing the rest of the code, and goodnight!

link to code:
http://web.aprchs.net/jacoby/mj2x_2011/feb14huntthevalentinescowpie

P.S. Don't forget to vote in the poll so we can decide which pd. to use it! //...vote for pd. 7 >:D, jk
link to poll --> http://web.aprchs.net/jacoby/mj2x_2011/newpollcomputerlabtime

P.S.S Remember to study for the exam on, Thursday! <(^_^)>

Monday Blog Report!

Monday was a very productive day! We started off with a do now, in which we had to return true if the number One is greater than the number of 4 's. I felt the class understood the problem to a certain extent, Ive realize that many people enjoy the Do Now,but many students in the class need a further breakdown to understand and write the code themselves.
After the Do Now we proceeded to work on CowPie program generating ideas of how to form the program i.e. the methods needed and if constructors would need to be present in this program.

Methods
________
initializeBoard();
hideThePie();
giveHint(int guessRow,in guessCol)
toString()

Also, Do not forget to fill out the survey below for the chance to win a very enticing chance to have the Computer Lab open during your period!!!!!!!!!!!!!!. See Below For More Information

|
|
|
|
|
V

Friday, February 11, 2011

(February 10, 2011 ) APCS Class

Hello, APCS Students. Today we have recieved the Books for REACH, make sure you take them with you Saturday morning. Today's lesson (do now) we briefly and smoothly went over using loops to edit our (tic-tac-toe program). We found out which loop is better to use when you know how many times(the program) will go over the loop = for loops. For loops that can have an unknown amount = while loop. We also continued working with Arrays to expand our knowledge on creating Boards. In the upcoming monday we need to do and finish a code (Hunt the Cowpie , Yuck! ) this game will set random points on where the CowPie(or as we would like to call it . Cow Dong) is located. It'll have the user input a set of points being Rows and Columns and ask for guesses. The assignment to me is understandable. Since the code will be nearly done for us, and work in class together we will just have to add a few methods and functions (this is where the Challenge comes). EVERYONE should start fiddling around and add on to the code.

Important Notice from Mr. Jacoby, Change of plans : we will be working on the code Monday!!!

Read Chapters 1 and 6 in our new Barron's review guides.
Both chapters: Complete all ODD problems the end-of-chapter multiple choice review section.

Don't forget: REACH Saturday morning @ Baruch College, 8:30 am!!

Wednesday, February 9, 2011

Today's Do Now:
1. Download the files TicTacToe.java and TicTacToeTester.java from the class website.

2. Add a Method to TicTacToe that counts the number of empty board locations.

Solution :

(Note: The new method must not be typed with in another method)
/**
* What this Method does is it counts the empty board locations, by declaring a new
* variable called count set to equal zero, and as the program advances it moves
* along the empty spaces and increases the value of count as it passes these empty
* spaces but if the space is occupied the value of count stays the same until it
* the method comes across a another empty board space.
*
*/
public int countEmptySpaces()
{
int count = 0
for ( int row = 0; row < ROWS; row++) {
for (int col = 0; col < COLUMNS; col++; }
if (board[row][col].equals(" ")) { count++; }
}
}
return count;
}

02/08/2011

Today's Do Now:
Give an array of ints length 3, return a new array with the elements in reverse, order, so {1, 2, 3} becomes {3, 2, 1}

reverse3({1, 2, 3}) --> {3, 2, 1}
reverse3({5, 11, 9}) --> {9, 11, 5}
reverse3({7, 0, 0}) --> {0,0,7}

public int[] reverse3(int[] nums) {
int[] reversed = new int[3];
for ( int i = 0; i < nums.length; i++) {
reversed[i] = nums[2-i];
}

OR

reversed[0] = nums[2];
reversed[1] = nums[1];
reversed[2] = nums[0];


Then we went over to the Final exam, the last question before the bonus (#15)
(refer to mj2x-05-reviewFinal.pdf )

solution:

public static void printInvite( String name, String gift) {
System.out.println("Dear" + name);
System.out.println("Thanks for the" +gift+ "you...");
System.out.println("I really hope...");
System.out.println("Love, me.");
}
public static void printInvitations() {
printInvitation("Abuelita", "socks");
printInvitation("Uncle George", "rocks");
}

Bonus Question:
int pow;
for (int pow = 0; Math.pow(2,pow) < n; pow++)
{}
pow--; //*at this point is the largest power of 2 while less than n
String results = "1";


Then we went over the previous homework assignment: mj2x-03-arrayLists-p9.pdf
(The answers should be posted on the website)

R8.16
(a) do a "for" loop. You can return false when they do not match but you can't return true until the very end
(b) a "for" loop in which you send the values of one array to the other.
(c) go to every single element and send it equal to 0
(d) use list.clear OR while list.length > 0, remove all elements

R.17 True or false?
1- True
2- True
3- False *subscripts and indices mean the same thing*
4- True
5- True
6- false
7- True
8- False

http://download.oracle.com/javase/tutorial/java/nutsandbolts/arrays.html

Brief introduction to Two-Dimensional Arrays (refer to Today's SMARTboard notes)

Why do we want to use them? Let's say we wanted to make a program to play a tic-tac toe game
Computer scientists would visualize this as being an array in two directions: rows and columns
You would start at 0 on both sides. It's like playing that 80s game Battleship
If you wanted to talk about a specific spot, you would say (0,1)
-->board[0][1]
How would you actually DECLARE these things?

Declaring a 2D Array

int[][] board = new int [3 which is the size of the rows][3 which is the size of the columns];
To know what's an X and O
final int X = 1;
final int O = 2;
final int EMPTY = 0;

You'll need 2 loops for this dimension, going row by row. Similar to what we did for the TimesTables assignment

for(int row = 0; row < 3; row++){
(int col = 0; col <3; col++){
if(board[row][col]==EMPTY)
System.out.print(" ");
else if (board[row][col]==X)
System.out.print("O")
}
}

System.out.println();
}

The HW is due on Thursday. Refer to website. It's going to be about Tic-Tac-Toe
We'll have time in class to do them Wednesday as well.
Bye!

Monday, February 7, 2011

Aim5: Review blog, final exams, & HW

Today we reviewed our new class blog. This blog is mainly about the students summarizing what they had learned that day. Mr. Jacoby will be sending you invites to the class blog using the emails that you had submitted on survey. Every Monday a schedule will be released showing who will be responsible for posting on the blog for that week. We also reviewed our final exams. Congrats to Jonathan for getting the highest score. If you want to see the corrections for the finals and today's lesson click here. That's pretty much it for today.

Julio

Friday, February 4, 2011

Welcome to the AP Computer Science blog!

Welcome everyone. This will be your blog, a daily summary of what you learned in class (and/or what confused you). The more work you put into it, the more useful it will be for you and your classmates, and the cooler it will look. Participation is voluntary, but if you volunteer to do it, please be diligent and make sure you post useful information.

Guidelines
  • Start by looking back at your notes and trying to remember what were the BIG ideas of the class.
  • Try to write in a conversational tone, using your own words, so that people who missed class can learn from your post.
  • If there was a common mistake addressed in class, that would also be useful to mention.
  • Feel free to copy and paste pictures from the class notes that I post on the class website.
  • Please use the "preview" button before you publish your post :)
Remember that you're writing in HTML, so if you need help, try googling "HTML help".  When posting code, you should switch to the pure HTML editor and use proper tags before (<pre>) and after (</pre>) your code.  This way it will look all nice and indented.  For example:
for (Student s : apcsStudents) {
  if (s.isVolunteerBlogger()) {
    s.writeBlogPost();
  }
}

Good luck, and ask for help if you need it!

Mr. Jacoby