Courses‎ > ‎AP Computer Science 2‎ > ‎

Konstantinovich

2017-06-12 Final Homework.

posted Jun 12, 2017, 6:06 AM by Samuel Konstantinovich

Final Homework:
REQUIRED Final Project Exit Survey:

2017-06-07

posted Jun 7, 2017, 7:22 PM by Samuel Konstantinovich

1. Make sure the only println statement in your mazeSolver is activated when animate is turned on.
OTHERWISE, there should be NO PRINT STATEMENTS.

//If you run this there should be NO OUTPUT AT ALL:
MazeSolver s = new MazeSolver()
s.solve(1)
String ans = s.toString();


2. Make sure your MazeSolver.java has:
 
public MazeSolver(String filename, boolean animate){
   /* You wrote this */
}

public void solve(int mode){
   /* You wrote this */
}

//The rest are all one liners so I included them:

public MazeSolver(String filename){
    this(filename,false);
}

public void solve(){
    solve(1);
}


 public String toString(){
   return maze.toString(); //maze instance variable is maze in this case
 }

 public String toString(int n){
    return maze.toString(n); //maze instance variable is maze in this case
 }

  

2017-06-05

posted Jun 5, 2017, 6:50 AM by Samuel Konstantinovich

Final Project Repo Form: (Absolutely required)
https://goo.gl/forms/5QWyZFinWV25PzBy2

Optional bits:

Summer Program Mentor Applications:

What:
CSTUY* is running a summer program to teach programming to students who do not have the same quality of CS education as you do at Stuyvesant. You would help the inexperienced students in a mentoring capacity (primary goal) and work on your own (semi-guided) projects in a positive workspace. We would most likely be using processing to teach basic programming concepts.
*A non-profit organization some of the CS teachers belong to.

Where: 
The program will be run out of LIU (2 stops south from Stuy on the 2 train) 
When:
July 5th - 27th, 9am-2pm (M-Th only)

If you are interested in the following program please apply here:


2017-05-31 Lab results

posted May 31, 2017, 7:05 AM by Samuel Konstantinovich   [ updated May 31, 2017, 7:35 AM ]

You already got drivers for 7,8. Here are drivers for 10,11. 

Test10.java  
usage:  (where n is 0-5) 
java Test10 n  

import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.*;
public class Test10{

  public static void testException(String name,int size){
    MyDeque base = new MyDeque();
    for(int i =0; i < size; i++){
      base.addFirst(""+i);
    }
    boolean result = true;
    for(int i =0; i < size && result; i++){
      result = result && base.removeLast().equals(""+i);
    }
    String message = "";

    if(result){
      try{
        base.removeLast();

         message = "FAIL Emptying case (No EXCEPTION THROWN): "+name;
      }catch(NoSuchElementException e){
        message = "Passed emptying case: "+name;

      }
    }else
    {
      message = "FAIL Emptying case (VALUE ERROR): "+name;
    }
   System.out.println( message);
  }
  public static void testCreation(String name,int size){
    ArrayDeque<String>d = new ArrayDeque<String>(size);
    MyDeque base = new MyDeque();
    long start = System.currentTimeMillis();
    for(int i = 0,j = 0; i < size/2; i++,j+=3){
      d.addFirst(""+i);
      base.addFirst(""+i);
      d.addLast(""+j);
      base.addLast(""+j);
    }
    String[]check = new String[size];
    int index = 0;
    while(index<size){
      check[index] = base.removeFirst();
      index++;
    }
    long end = System.currentTimeMillis() - start;

    if(Arrays.equals(d.toArray(),check)){
      System.out.println("Passed case: "+name+" in "+end/1000.0+" seconds.");
    }else{
      System.out.println("\tFAIL CREATION case: "+name +".");
    }

  }

  public static void main(String[]args){
        int testNum = new Integer(args[0]);
        if(testNum>=0 && testNum <4){
          testCreation(args[0],new Integer(args[1]));
        }
        if(testNum>=4 && testNum <6){
          testException(args[0],new Integer(args[1]));
        }

  }
}

Test11.java  
usage:  
java Test11 

public class Test11{

    public static void main(final String[] args) {
      int count=0;
      if(StackCalc.eval("0")==0.0){
        count++;
      }
      if(StackCalc.eval("-5")==-5.0){count++;}
      if(StackCalc.eval("20 3 +")==23.0){count++;}
      if(StackCalc.eval("108 212 + 525 -")==-205.0){count++;}
      if(StackCalc.eval("47 969 / 0 - 769 -")==-768.9514963880289){count++;}
      if(StackCalc.eval("15 443 * 336 * 939 / 600 -")==1777.7635782747602){count++;}
      if(StackCalc.eval("67 128 - 297 469 * + 354 + 66 - 345 - 732 -")
          == 138443.0){
            count++;
      }
      if(StackCalc.eval("670 150 511 / + 836 717 * 261 / + 60 - 851 +")==3757.8912432237894){
          count++;
      }
      System.out.println("SCORE out of 8 : " + count);
    }

}



OSIS1256781011
205312234902: 11 / 112006: 7 / 713136SCORE of 8 : 8 
205324502702: 11 / 112006: 7 / 77136SCORE of 8 : 8 
20556927062: ---006: 4 / 77: ---8: ---10: ---11: ---
205756174902: 11 / 112006: 7 / 71213111: ---
206016958902: 10 / 1106: ---7: ---8: ---10: ---11: ---
206119901902: 11 / 111506: 7 / 7101310: ---SCORE of 8 : 8 
206174740902: 11 / 112006: 7 / 713132SCORE of 8 : 8 
206298812902: 11 / 11006: 7 / 713131SCORE of 8 : 3 
206385445902: 11 / 112006: 7 / 713136SCORE of 8 : 8 
206779092902: 11 / 112006: 0 / 713120SCORE of 8 : 8 
206836678602: 11 / 112006: 6 / 77: ---131SCORE of 8 : 8 
20701107372: ---1006: 7 / 7111310: ---11: ---
207150723902: 11 / 112006: 7 / 7131310: ---SCORE of 8 : 8 
207175431902: 11 / 11006: 7 / 788: ---10: ---SCORE of 8 : 8 
207185661902: 11 / 112006: 6 / 713126SCORE of 8 : 8 
207186479902: 11 / 112006: 0 / 713136SCORE of 8 : 3 
207193376902: 11 / 112006: 7 / 7131310: ---SCORE of 8 : 8 
207198813902: 11 / 112006: 7 / 7131310: ---SCORE of 8 : 8 
207204637902: 11 / 111706: 7 / 710136SCORE of 8 : 8 
207234352802: 11 / 112006: 7 / 71313611: ---
207257510902: 11 / 112006: 7 / 713121SCORE of 8 : 8 
207268863902: 11 / 111006: 2 / 713134SCORE of 8 : 5 
207354838902: 11 / 112006: 7 / 77: ---136SCORE of 8 : 8 
207371998902: 11 / 112006: 7 / 713136SCORE of 8 : 8 
207374091902: 9 / 11006: 7 / 77: ---124SCORE of 8 : 8 
207374547902: 11 / 112069930 is HUUUUGE OUTPUT!7: ---8: ---10: ---SCORE of 8 : 8 
20739127792: ---006: 7 / 77: ---8: ---10: ---11: ---
207423799802: 11 / 112006: 7 / 77: ---1210: ---SCORE of 8 : 8 
207438474902: 11 / 112006: 2 / 71313611: ---
207474545902: 11 / 114108 is HUUUUGE OUTPUT!06: 7 / 7312111: ---
2075375561: ---2: ---006: 0 / 77: ---1310: ---11: ---
207677840902: 11 / 111912120SCORE of 8 : 8 
207691148902: 11 / 112006: 7 / 7131310: ---11: ---
207700485902: 11 / 112006: 7 / 713136SCORE of 8 : 8 
207723016902: 11 / 112006: 0 / 77130SCORE of 8 : 8 
207723230902: 11 / 1106: ---7: ---8: ---10: ---11: ---
207781790902: 11 / 112006: 0 / 7131210: ---SCORE of 8 : 8 
207782087886: ---330incorrect input 
207782368802: 11 / 111806: 7 / 713134SCORE of 8 : 8 
207915497902: 11 / 111806: 7 / 77: ---0611: ---
207979568902: 11 / 112006: 7 / 713120SCORE of 8 : 8 
208084780902: 11 / 111906: 7 / 71313011: ---
208087569902: 11 / 111806: 7 / 7131310: ---SCORE of 8 : 8 
208185835902: 11 / 112006: 7 / 713130SCORE of 8 : 8 
208248807802: 11 / 112006: 7 / 71311SCORE of 8 : 8 
208254029902: 11 / 11006: 7 / 71410: ---11: ---
208337451902: 11 / 112006: 7 / 712131SCORE of 8 : 8 
208365999802: 10 / 112006: 7 / 7100331 is HUUUUGE OUTPUT!1310: ---SCORE of 8 : 8 
208377580902: 11 / 112006: 7 / 713136SCORE of 8 : 8 
208394692902: 11 / 11006: 7 / 713126SCORE of 8 : 8 
208408385902: 11 / 112006: 7 / 712136SCORE of 8 : 8 
208434720902: 11 / 112006: 2 / 713130SCORE of 8 : 8 
20846581582: ---06: ---7: ---8: ---10: ---11: ---
208512509902: 11 / 112006: 7 / 713136SCORE of 8 : 8 
208512699902: 11 / 112006: 7 / 77: ---70SCORE of 8 : 8 
208584086902: 11 / 112006: 7 / 713126SCORE of 8 : 8 
208627539902: 11 / 112006: 7 / 713136SCORE of 8 : 8 
208667436902: 11 / 112006: 7 / 713136SCORE of 8 : 8 
208670125902: 11 / 112006: 7 / 7131310: ---11: ---
208744193902: 11 / 112006: 7 / 7131310: ---SCORE of 8 : 5 
208845016902: 11 / 111906: 7 / 713136SCORE of 8 : 8 
20889988092: ---126: ---13136SCORE of 8 : 8 
208908293902: 11 / 112006: 2 / 71313011: ---
208908533902: 11 / 112006: 7 / 712126SCORE of 8 : 8 
208947739902: 11 / 111606: 7 / 713131SCORE of 8 : 8 
20897984992: ---2006: 7 / 7131310: ---SCORE of 8 : 5 
209005677902: 11 / 112006: 7 / 713136SCORE of 8 : 8 
209033166902: 11 / 111706: 7 / 710134SCORE of 8 : 8 
209064732902: 11 / 112006: 7 / 713134SCORE of 8 : 8 
209267145902: 11 / 112006: 7 / 7131310: ---11: ---
20926828392: ---006: 7 / 77: ---110: ---11: ---
209475722902: 10 / 111806: 7 / 712121SCORE of 8 : 3 
209517523902: 11 / 112006: 6 / 713121081 is HUUUUGE OUTPUT!SCORE of 8 : 8 
214708794902: 11 / 11006: 0 / 77: ---8: ---10: ---11: ---
214717522902: 11 / 112006: 7 / 7131310: ---11: ---
215386194902: 11 / 112006: 7 / 7131310: ---SCORE of 8 : 8 
216000083902: 11 / 112006: 7 / 7131310: ---SCORE of 8 : 7 
216085423902: 11 / 112006: 0 / 7131310: ---SCORE of 8 : 8 
2164112071: ---02: 11 / 11106: ---128: ---10: ---11: ---
217774520902: 11 / 112006: 2 / 713134SCORE of 8 : 8 
220874002802: 10 / 112006: 7 / 7121310: ---SCORE of 8 : 8 
222491128902: 11 / 112006: 7 / 71131SCORE of 8 : 7 
226107795902: 11 / 111006: 7 / 71212111: ---
229080502902: 11 / 111906: 7 / 713134SCORE of 8 : 8 
2319108861: ---02: 11 / 112006: 7 / 71312611: ---
23314888192: ---2006: 7 / 713134SCORE of 8 : 8 
233149079902: 11 / 111806: 7 / 71213111: ---
236029385902: 11 / 112006: 7 / 77: ---8: ---10: ---11: ---
236053138902: 11 / 112006: 7 / 713136SCORE of 8 : 8 
236072427902: 11 / 112006: 7 / 713110: ---11: ---
23607546192: ---2006: 7 / 7131210: ---SCORE of 8 : 8 
236586327902: 11 / 112006: 7 / 713134SCORE of 8 : 8 
237060256902: 11 / 111906: 7 / 713130SCORE of 8 : 3 

2017-05-26 Final Project

posted May 26, 2017, 7:13 AM by Samuel Konstantinovich   [ updated May 26, 2017, 7:16 AM ]


Final Project Ideas: (and resources)

Calendar
May 26th: The official starting point. 
Create Final Project repo. 
Make sure you can commit to it from all of your computers properly. 
Look at the contribution graphs from time to time to make sure you didn't break something.
You can start doing your UML before writing code but can revise the UML.

May 31st: Full Prototype/ Finalized UML diagram. 
    Brief Summary of the project
    list of features, prioritized by importance
    Detailed Description
    Roadmap of development stages with estimated dates.
    How you plan to distribute the work.

June: 8-9: Demos.
June 12th: Final Deadline + Demos.

-If you have a planned absence then you must make sure you present before the 12th.

Grades:
Counts as 1.5 exams.
20% Prototype/UML
30% Worked consistently over the entire duration of the project, both members contributed to the code, used git properly branched
50% Actual Project + exit quiz


2017-05-25

posted May 25, 2017, 7:04 AM by Samuel Konstantinovich

On your PERSONAL computers, download processing here:
www.processing.org

The labs will be updated to have Processing by early next week!

Today: 
1. Finalize partners. 
2. Discuss Final Project Ideas. Remember: You don't have to make something original! Cloning an existing idea is already a very ambitious task. (Making a good copy is hard enough) This is true for games as well as normal programs. 
3. Start making the following:

-Project Description
Include the scope of the project, the 
-In depth UML diagram. 
Feel free to prototype using pen/paper, but when you are mostly done, type up a copy for next week.


Yesterday's Demo
Main Tab:

ArrayList<Face> lof;

public void setup() {
  size(800, 600);
  lof = new ArrayList<Face>();
  lof.add( new Face(width/3*2, height/2, 100));
  lof.add( new Face(width/3, height/2, 100));
}
public void draw() {

  background(200);
  for (Face a : lof) {
    a.display();
    a.x+= random(11)-5.5;
    a.y+= random(11)-5.5;
  }
}


void mousePressed() {
  int s = lof.size();
  for ( Face next : lof.toArray(new Face[0])) {
    for (Face newFace : next.breakIntoNPieces(5)) {
      lof.add(newFace);
    }
  }
  while (s>0) {
    lof.remove(0);
    s--;
  }
}


Face Class:

class Face {
  float x, y, size;
  

  
  ArrayList<Face> breakIntoNPieces(int n){
    ArrayList<Face> result = new ArrayList<Face>();
    while(n > 0){
      result.add(new Face(x,y,size*.6));
      n--;
    }
    return result;
  }

  Face(float x, float y, float size) {
    this.x = x;
    this.y = y;
    this.size = size;
  }

  public void display() {
    stroke(0);
    fill(255);
    rect(x, y, size, size);
    fill(255,0,0);
    noStroke();
    ellipse(x+size*.01*30, y+size*.01*30, size*.01*20, size*.01*20);
    ellipse(x+size*.01*70, y+size*.01*30, size*.01*20, size*.01*20);
    rect(x+size*.01*20, y+size*.01*80, size*.01*60, size*.01*10);
  }
}




2017-05-16

posted May 16, 2017, 8:58 AM by Samuel Konstantinovich   [ updated May 16, 2017, 3:15 PM ]

Pathfinding Demo:
http://qiao.github.io/PathFinding.js/visual/

College Recommendation Request form:


Maze Class Attached

2017-05-15 Maze Solver HW15

posted May 15, 2017, 7:12 AM by Samuel Konstantinovich   [ updated May 24, 2017, 9:12 PM ]



classes:

I simplified this to make fewer classes at the cost of some degree of elegance.

1. Frontier interface (see image)

2. Location (see image) [ I merged the node and location classes. this makes the Location store a little bit extra]
 2a implements Comparable<Location>

 2b instance variables:
 private int row,col
 private int distToGoal
 private int distToStart 
 private Location previous (used to trace the solution)
 private boolean aStarwhen this is true, compareTo will use: distToStart distToGoal
                                     when this is false, compareTo will use the distToGoalonly.
                                     
2c Constructors:
 Location(int r, int c, Location previous , int distToStartint distToGoal, boolean aStar)

2d Methods: 
  -accessors as needed
  -CompareTo( Location other) -> decide what number to compare using the aStar boolean.



2. FrontierPriorityQueue - implements Frontier
      This is just your Priority queue that implements Frontier ( add/next).

3. FrontierQueue - implements Frontier
       Store a Queue instance variable and implementation of Frontier

4. FrontierStack - implements Frontier
       Store a Stack instance variable and and implementation of Frontier

5. MazeSolver
  
5a constructors:
MazeSolver(String filename) {  this(filename,false); } //done!
MazeSolver(String filename, boolean animate) : filename - input name of the maze file, animate - true for animating your maze.

5b public methods:
  public void solve(){  solve(1);}
  public void solve(int style){} 
      - style is 0-4, where 0-DFS, 1-BFS,2-BestFirst, 3-A*
      - This method will instantiate the Frontier based on which style was chosen. 
     It will then add the starting location of the maze to the Frontier.
     Finally it will process each subsequent element of the frontier until the end is found. 

  toString() - call the toString of the maze instanceVariable.
  /*edit, added this!*/
  toString(int ms) - call the toString of the maze instanceVariable that takes an int parameter.

6. Maze - Will be given to you.


How does solve work?

Initialize your frontier
add the starting node.
while not done and not empty:
   get next node
   process that node





2017-05-08 HW14

posted May 8, 2017, 8:58 AM by Samuel Konstantinovich   [ updated May 8, 2017, 9:07 AM ]

github:

14/
  RunningMedian.java
  MyHeap.java  (copy from old assignment and change to a heap of Integers)

constructor:
   RunningMedian()  - make an empty running median.

public methods:
  void add(int) - insert the value into the heap.
  double getMedian()  - return the median (do not remove anything)



Exam Friday:
  multiple choice only
  general java stuff (studied already for the AP)
  Stacks, Queues, Trees, Heaps  

2017-05-04

posted May 3, 2017, 7:50 PM by Samuel Konstantinovich

Goal: May the 4th be with you.

Robots + Shoebox volunteer form:


1-10 of 44