Announcements


2015-06-12 Final Post

posted Jun 11, 2015, 8:39 PM by Samuel Konstantinovich   [ updated Jun 11, 2015, 8:39 PM ]

Please fill out the Exit Survey:
(After it loads it should only take about 15-20 minutes to complete)



Remember your project must be completed by Monday 8am unless you have spoken to me prior to today. 
DO test your code completely after making any changes. 
Do NOT wait till Sunday to put any new features on the website... =)
**Do NOT edit/change your files after Monday 8am, or I will grade the previous version that you have posted. **

2015-06-05 Final Project Repo

posted Jun 5, 2015, 9:02 AM by Samuel Konstantinovich   [ updated Jun 5, 2015, 9:02 AM ]

Fill out this form, one per group:
http://goo.gl/forms/f70OaqVtwP

2015-05-26

posted May 26, 2015, 8:53 AM by Samuel Konstantinovich   [ updated May 27, 2015, 7:44 AM ]

Final Project Guidelines:
You need to have in your repository:
1 The Readme file that i can see when I first go to your repo.
The readme should include:
   -Team name, 
   -Project name / description
   -*Development Log (daily progress since y'all never commit with good messages) 
   -*Project plan/outline including your goals prioritized by importance and chronology (things to do + things already done)
   -*Links to the Demo versions, what they show about the state of your project, Directions on how to compile/run each version.

2 Stable "demo" versions, that show off what you did so far. This is part of your anti-procrastination grade!
 -*June 1, 
 -*June 8, 
 -*June 15 (final version)

3 Branches for each member of the team for when they are modifying the code/adding new features. Use your development branch when you start to mess with things and potentially break them.
*The main branch should always compile. 

*'ed things will affect your grade.

PROJECT DEMOS:
The week of June 8th will be project demos. Every group gets one 5-8 minute slot to demo their project and talk about the cool things they did. They will also talk about their goals to have done by the 15th.
Showing code isn't important, but explaining the algorithms, or how things worked in general is important.

2015-05-22 Processing Day 2

posted May 26, 2015, 8:48 AM by Samuel Konstantinovich   [ updated May 26, 2015, 9:20 AM ]

Processing Day 2: Menu and modes

int MODE;
float BIG_FACTOR;
float dx, dy;
float groupx, groupy;


void setup() {
  size(800, 600);
  background(100, 100, 100);
  groupx = 0;
  groupy = 0;
  dx = 1;
  dy = 1;
  MODE=1;
  BIG_FACTOR= 1.5;
}

void android(float x, float y, float scale) {
  color c = color(164, 199, 67); 
  fill(c);
  stroke(c);
  strokeWeight(3);//thin lines
  line(x - 25 / scale, y - 60 / scale, x - 32 / scale, y - 75 / scale);//antennae
  line(x + 25 / scale, y - 60 / scale, x + 32 / scale, y - 75 / scale);//antennae
  strokeWeight(23 / scale);  //thick lines
  line(x - 67 / scale, y - 10 / scale, x - 67 / scale, y + 40 / scale);//left arm
  line(x + 66 / scale, y - 10 / scale, x + 66 / scale, y + 40 / scale);//left arm
  line(x - 39 / scale, y + 60 / scale, x + 38 / scale, y + 60 / scale);//bottom of torso
  line(x - 20 / scale, y + 60 / scale, x - 20 / scale, y + 100 / scale);//left leg
  line(x + 20 / scale, y + 60 / scale, x + 20 / scale, y + 100 / scale);//right leg
  noStroke();
  arc(x, y - 23 / scale, 100 / scale, 90 / scale, PI, 2*PI);
  rect(x - 50 / scale, y-20 / scale, 100 / scale, 80 / scale);//torso
  fill(255);
  ellipse(x - 22 / scale, y - 43 / scale, 8 / scale, 8 / scale);
  ellipse(x + 22 / scale, y - 43 / scale, 8 / scale, 8 / scale);
}

void androids(float x, float y) {
  int spacing = (int)(200/BIG_FACTOR);
  for (int i = -10; i < 10; i++) {
    for (int j = -10; j < 10; j++) {
      android(x + i * spacing, y + j * spacing, BIG_FACTOR);
    }
  }
}

void moveAndroids() {

  groupx+=dx;
  groupy+=dy;
  if (groupx>width) {
    groupx=0;
  }
  if (groupy>height) {
    groupy=0;
  }
}

void displayMenu() {
  fill(0, 0, 0, 100);
  rect(50, 50, width-100, height-100);
  fill(255);
  text("Press + to increase androids' size", 100, 100);
  text("Press - to decrease androids' size", 100, 150);
  text("Press space to toggle these directions", 100, 200);
  text("Press 'A' to toggle gravity", 100, 250);
  text("Press esc to quit", 100, 300);
}

void keyPressed() {
  println(keyCode);
  if (keyCode==32 && MODE!=1) {
    MODE=1;
  } else if (keyCode==32 && MODE!=0) {
    MODE=0;
  }

  if (keyCode==61) {
    BIG_FACTOR /= 1.1;
  }

  if (keyCode==45) {
    BIG_FACTOR *= 1.1;
  }

  if (keyCode == 65 && MODE!= 2) {
    MODE = 2;
  } else if (keyCode == 65) {
    MODE = 0;
  }
}
void Aaaaaah() {
  dy = dy+.2;
  fill(255, 0, 0);
  text("AaaaaaaaahhhhhhhhhhhhhHH!", width/2-50, height/2);
}
void mouseClicked() {
  println(mouseX+","+mouseY);
}


void draw() {
  fill(255, 120);  
  rect(0, 0, width, height);
  androids(groupx, groupy);  


  if (MODE==1) {
    displayMenu();
  } else {
    moveAndroids();
  }
  if (MODE==2) {
    Aaaaaah();
  }
}

2015-05-18 Processing Day1

posted May 18, 2015, 6:44 PM by Samuel Konstantinovich   [ updated May 18, 2015, 6:55 PM ]

Sample code to follow:

Linux Bug:
KeyReleased is triggered repeatedly in java. This is a bug. 
Windows does not have this problem, I don't know if OSX does. 

////////////MAIN TAB////////////
Ball player;
boolean isUp, isSpace, isSpaceReleased;

void setup() {
  isSpaceReleased = true;
  size(200, 600);
  background(255);
  player = new Ball(width/2.0, 3*height/4.0);
}


void draw() {
  background(255);
  player.draw();
  fill(0);
  text(frameCount+"", 20, 20);
  processKeys();
}

public void processKeys() {
  if (isUp) {
    player.setY(player.getY()-2.0);
  }
  if (isSpace && isSpaceReleased) {
    isSpaceReleased = false
    //don't do this again until you release it
    player.randomColor();
  }
}

void keyReleased() {
  if (keyCode == 32) {//space
    isSpace = false;
    isSpaceReleased = true;
  }
  if (keyCode == 38) {//up
    isUp = false;
  }
}

void keyPressed() {
  if (keyCode == 32) {//space\
    isSpace = true;
  }
  if (keyCode == 38) {//up
    isUp = true;
  }
}

////////////Ball TAB////////////
public class Ball {
  private float x, y;
  public float r;
  private color c;
  public Ball(float x, float y) {
    r = 20.0;
    this.x = x;
    this.y = y;
    c = color(100, 100, 100);
  } 
  public void randomColor() {
    c = color(random(255), random(255), random(255));
  }

  public void draw() {
    stroke(0);
    fill(c);
    ellipse(x, y, r*2, r*2);
  }

  public float getX() {
    return x;
  }
  public float getY() {
    return y;
  }

  public void setX(float newx) {
    x = newx;
  }
  public void setY(float newy) {
    y = newy;
  }
}

2015-05-11 Heap

posted May 11, 2015, 11:56 AM by Samuel Konstantinovich   [ updated May 12, 2015, 4:38 AM ]

Goal: A heaping pile of datastructures. 

Homework (due Thursday in class)
MyHeap.java
A heap of int. 

Start with simple:

public MyHeap() -> creates a max heap
public MyHeap(boolean isMax) -> creates a max-heap when boolean is true, min-heap when the boolean is false
public String toString()
public int remove() -> remove the root and return the value  O(logn)
public void add(int) -> add the int to the heap  O(logn)
public int peek() -> return the value of the root but do not remove it.  O(1)


Don't use generics.

2015-05-05

posted May 5, 2015, 8:24 AM by Samuel Konstantinovich   [ updated May 5, 2015, 8:24 AM ]

Today in class, do as many multiple choice questions as you can. If the questions are incorrect, or the solutions (created by last year's students) are wrong, please comment!

175 java questions + solutions (not including AB questions)
https://docs.google.com/document/d/1Go_Z8_B_ZN2MxcnFAu3-5l6iR-_4nw7nQ5kt-5KUnqQ/edit?usp=sharing

2015-05-04 AP review

posted May 4, 2015, 7:54 AM by Samuel Konstantinovich   [ updated May 4, 2015, 9:30 AM ]

Download the attached 2014 AP Computer Science exam.

On paper complete questions 1 + 4 from the 2014 exam. Use substring() instead of charAt() to practice your substring()
At home complete the problems then go over the solutions 

Find solutions to see how you did:

Get the scoring guidelines at the collegeboard:

Alternate solutions that are annotated here:

2015-05-01 BST toString()

posted May 1, 2015, 9:20 AM by Samuel Konstantinovich   [ updated May 1, 2015, 9:26 AM ]

/**
* stolen from: Dennis Yatunin
* (no not really stolen from, donated by)
*/

public int getHeight(){
		return getHeight(root);
}

private int getHeight(BSTreeNode<T> r ){
		if(r == null){
				return 0;
		}else{
				//System.out.println("recursion height");
				return 1 + Math.max(getHeight(r.getLeft()),
					            getHeight(r.getRight()));
		}
}

private int maxLength() {
		// returns the minimum number of characters required
		// to print the data from any node in the tree
		if (root == null)
				return 0;
		return maxLength(root);
}

private int maxLength(BSTreeNode<T> curr) {
		int max = curr.toString().length();
		int temp;
		if (curr.getLeft() != null) {
				temp = maxLength(curr.getLeft());
				if (temp > max)
						max = temp;
		}
		if (curr.getRight() != null) {
				temp = maxLength(curr.getRight());
				if (temp > max)
						max = temp;
		}
		return max;
}

private String spaces(double n) {
		// returns a String of n spaces
		String result = "";
		for (int i = 0; i < n; i++)
				result += " ";
		return result;
}

/*
	getLevel will produce a String for each level of the tree.
	The resulting Strings will look like this:

	._______________________________
	._______________._______________
	._______._______._______._______
	.___.___.___.___.___.___.___.___
	._._._._._._._._._._._._._._._._

	toString will combine those Strings and provide an output that
	will look like this:

	_______________.
	_______._______________.
	___._______._______._______.
	_.___.___.___.___.___.___.___.
	._._._._._._._._._._._._._._._.
	In these diagrams, each dot represents wordLength characters,
	each underscore represents wordLength spaces, and, for any nodes
	that are null, the dots will be "replaced" by underscores.
*/

private String getLevel(BSTreeNode<T> curr, int currLevel, int targetLevel, int height, int wordLength) {
		if (currLevel == 1){
			return curr.toString() + 
                               spaces(wordLength - curr.toString().length()) +
			       spaces(wordLength * 
                                      Math.pow(2, height - targetLevel + 1) - 
                                      wordLength);
		}
		String result = "";
		if (curr.getLeft() != null){
			result += getLevel(curr.getLeft(), currLevel - 1, targetLevel, height, wordLength);
		}else{
			result += spaces(wordLength * Math.pow(2, height - targetLevel + currLevel - 1));
		}
		if (curr.getRight() != null){
			result += getLevel(curr.getRight(), currLevel - 1, targetLevel, height, wordLength);
		}else{ 
			result += spaces(wordLength * Math.pow(2, height - targetLevel + currLevel - 1));
		}
		return result;
}
		
public String toString() {
		if (root == null)
				return "";
		String result = "";
		int height = getHeight();
		int wordLength = maxLength();
		// add the every level of the tree except the last one
		for (int level = 1; level < height; level++){
			// remove extra spaces from the end of each level's String to prevent lines from
			// getting unnecessarily long and add spaces to the front of each level's String
			// to keep everything centered
			result += spaces(wordLength * Math.pow(2, height - level) - wordLength) +
				getLevel(root, level, level, height, wordLength).replaceFirst("\\s+$", "") +
				"\n";
		}
		// now add the last level (level = height)
		result += getLevel(root, height, height, height, wordLength).replaceFirst("\\s+$", "");
				
		return result;
}

2015-04-30 BST lab

posted Apr 30, 2015, 8:36 AM by Samuel Konstantinovich   [ updated Apr 30, 2015, 1:43 PM ]

//
//
//Your binary search tree Node skeleton file:


import java.io.*;
import java.util.*;

public class BSTreeNode<T extends Comparable> {

    private T data;
    private BSTreeNode<T> left;
    private BSTreeNode<T> right;

    public BSTreeNode( T d ) {
 
	data = d;
	left = right = null;
    }
    
    //accessors
    public T getData() {
	return data;
    }
    public BSTreeNode<T> getLeft() {
	return left;
    }
    public BSTreeNode<T> getRight() {
	return right;
    }

    //mutators
    public void setData( T d ) {
	data = d;
    }
    public void setLeft( BSTreeNode<T> l ) {
	left = l;
    }
    public void setRight( BSTreeNode<T> r ) {
	right = r;
    }
}



    NEW FILE


//
//
//Your binary search tree skeleton file:


import java.io.*;
import java.util.*;

public class BSTree <T extends Comparable> {

    private BSTreeNode<T> root;

    public BSTree() {
	root = null;
    }

    public boolean isEmpty() {
	return root == null;
    }
    public boolean isLeaf( BSTreeNode<T> t ) {
	return (t.getLeft() == null && t.getRight() == null);
    }

    /*======== public void add() ==========
      Inputs:   T c  
      Returns: 

      Wrapper for the recursive add method
      ====================*/
    public void add( T c ) {
	root = add( root, new BSTreeNode<T>(c) );
    }

    /*======== public BSTreeNode<T> add() ==========
      Inputs:  BSTreeNode<T> curr
               BSTreeNode<T> t 
      Returns: 

      Add t to the correct place in the tree rooted at curr.
      ====================*/
    private BSTreeNode<T> add(BSTreeNode<T> curr, BSTreeNode<T> t) {
	return null;
    }

    /*======== public void remove() ==========
      Inputs:   T c  
      Returns: 
      
      Wrapper for the recursive remove method
      ====================*/
    public void remove( T c ) {
	root = remove( root, c );
    }

    /*======== public BSTreeNode<T> remove() ==========
      Inputs:   BSTreeNode<T> curr
		T c
      Returns: 

      Should remove the value c from the tree rooted at
      curr, if it exists.
      ====================*/
    private BSTreeNode<T> remove( BSTreeNode<T> curr, T c ) {
	return null;
    }


    /*======== public void inOrder()) ==========
      Inputs:   
      Returns: 

      Wrapper for the recursive inOrder method
      ====================*/
    public void inOrder() {
	inOrderHelper( root );
	System.out.println();
    }

    /*======== public void inOrderHelper() ==========
      Inputs:   BSTreeNode<T> t  
      Returns: 
      
      Performs an in-order traversal for the tree with 
      root t.
      ====================*/
    public void inOrderHelper( BSTreeNode<T> t ) {
	if (t == null) 
	    return;
	inOrderHelper( t.getLeft() );
	System.out.print( t.getData() + " ");
	inOrderHelper( t.getRight() );
    }

   
    public static void main( String[] args ) {

    }

}


1-10 of 28