Courses‎ > ‎AP Computer Science‎ > ‎

Konstantinovich

Email: 
    konstans@stuy.edu

Office Hours:
    Periods 6,7,8  in room 301
    Note: 6th is my lunch and I tend to be out getting food the 1st 10 minutes of the period


2019-01-07

posted Jan 7, 2019, 6:49 AM by Konstantinovich Samuel   [ updated Jan 14, 2019, 6:39 AM ]

Menu Demo:

//API : http://mabe02.github.io/lanterna/apidocs/2.1/
import com.googlecode.lanterna.terminal.Terminal.SGR;
import com.googlecode.lanterna.TerminalFacade;
import com.googlecode.lanterna.input.Key;
import com.googlecode.lanterna.input.Key.Kind;
import com.googlecode.lanterna.terminal.Terminal;
import com.googlecode.lanterna.terminal.Terminal.Color;
import com.googlecode.lanterna.terminal.TerminalSize;
import com.googlecode.lanterna.LanternaException;
import com.googlecode.lanterna.input.CharacterPattern;
import com.googlecode.lanterna.input.InputDecoder;
import com.googlecode.lanterna.input.InputProvider;
import com.googlecode.lanterna.input.Key;
import com.googlecode.lanterna.input.KeyMappingProfile;


public class MenuDemo {

  public static void putString(int r, int c,Terminal t, String s){
    t.moveCursor(r,c);
    for(int i = 0; i < s.length();i++){
      t.putCharacter(s.charAt(i));
    }
  }

  public static void putString(int r, int c,Terminal t,
        String s, Terminal.Color forg, Terminal.Color back ){
    t.moveCursor(r,c);
    t.applyBackgroundColor(forg);
    t.applyForegroundColor(Terminal.Color.BLACK);

    for(int i = 0; i < s.length();i++){
      t.putCharacter(s.charAt(i));
    }
    t.applyBackgroundColor(Terminal.Color.DEFAULT);
    t.applyForegroundColor(Terminal.Color.DEFAULT);
  }
  public static void main(String[] args) {

    Terminal terminal = TerminalFacade.createTextTerminal();
    terminal.enterPrivateMode();

    TerminalSize size = terminal.getTerminalSize();
    terminal.setCursorVisible(false);

    boolean running = true;
    int mode = 0;
    long lastTime =  System.currentTimeMillis();
    long currentTime = lastTime;
    long timer = 0;


    while(running){
      Key key = terminal.readInput();
      if (key != null)
      {

        //YOU CAN PUT DIFFERENT SETS OF BUTTONS FOR DIFFERENT MODES!!!

        //only for the game mode.
        if(mode == 0){
          if (key.getKind() == Key.Kind.Escape) {
            terminal.exitPrivateMode();
            running = false;
          }
        }

        //for all modes
        if (key.getCharacter() == ' ') {
          mode++;
          mode%=2;//2 modes
          terminal.clearScreen();
          lastTime = System.currentTimeMillis();
          currentTime = System.currentTimeMillis();
        }
      }

      terminal.applySGR(Terminal.SGR.ENTER_BOLD);
      putString(1,1,terminal, "This is mode "+mode,Terminal.Color.WHITE,Terminal.Color.RED);
      terminal.applySGR(Terminal.SGR.RESET_ALL);


      if(mode==0){
        lastTime = currentTime;
        currentTime = System.currentTimeMillis();
        timer += (currentTime -lastTime);//add the amount of time since the last frame.
        //DO GAME STUFF HERE
        putString(1,3,terminal, "Game here...",Terminal.Color.WHITE,Terminal.Color.RED);
        putString(3,5,terminal, "Time: "+timer,Terminal.Color.WHITE,Terminal.Color.RED);

      }else{

        terminal.applySGR(Terminal.SGR.ENTER_BOLD,Terminal.SGR.ENTER_BLINK);
        putString(1,3,terminal, "Not game, just a pause!",Terminal.Color.RED,Terminal.Color.WHITE);
        terminal.applySGR(Terminal.SGR.RESET_ALL);

      }

    }


  }
}

2019-01-03

posted Jan 3, 2019, 6:16 AM by Konstantinovich Samuel   [ updated Jan 4, 2019, 5:48 AM ]

Goal: Terminal Manipulation

Download the java file, and the jar file.

A jar file like this is a library that can be used, but you need to compile in a particular manner that uses the -cp flag. ***

Assuming you are in a directory with the java file AND the jar file:

$ javac -cp lanterna.jar:. TerminalDemo.java
$ java -cp lanterna.jar:. TerminalDemo

Notice
1)  -cp (which stands for classpath) includes the jar file, a separator colon, and . (current directory)
2) "." which is almost always required because it means to include classes in the current directory, which is required if you have more than one class in your prioject.
3) You can also have multiple jar files, in different locations if you like:
-cp  ../file.jar:file2.jar:.



If your terminal pops up a terminal and lags:

You are on a system with a windowing environment. We can fix that!
You can pass the following option to the JRE:
$ java -Djava.awt.headless=true -cp lanterna.jar:. TerminalDemo

OR

TerminalFacade.createTextTerminal(); //USE THIS COMMAND INSTEAD!



***I will ONLY compile on the terminal, so don't use eclipse until the last day and then realize you have no idea how to compile it on the terminal 


When you run this, some terminals will pop up a second terminal and then lag, this is unfortunate, but can easily be fixed. (There is probably a better way but it doesn't matter)





2019-01-02

posted Jan 2, 2019, 5:55 AM by Konstantinovich Samuel   [ updated Jan 2, 2019, 6:31 AM ]

Classwork:
-Fill out this survey (it does not collect your email) https://goo.gl/forms/4aXPzXA3mELcXr0S2
-Complete the free response questions of the practice final that was posted.
-If you have your prototype done, I will look at it and give you a green light to get started on that (but you still need to complete the practice final questions)

We will briefly discuss solutions tomorrow.

2018-12-20

posted Dec 20, 2018, 6:26 AM by Konstantinovich Samuel   [ updated Dec 20, 2018, 8:39 AM ]

The exam before the final exam (Friday after Break)
-Runtime Analysis
-Sorts
-Linked Lists
[Note that these topics won't be on the final exam]

Practice Final is posted



Classwork: 
On a new page in your notes, work on the practice final.
Take it under testing conditions. (No notes/calculators/discussion)

Question 8: 
This is NOT the existing Comparable<T> interface.

Question 10:
No Correct Choice

Homework:
By tomorrow you should have all the multiple choice done

2018-12-19

posted Dec 19, 2018, 6:18 AM by Konstantinovich Samuel   [ updated Dec 19, 2018, 9:24 AM ]

Try this basic Github tutorial to explain things you may already know:    
    https://learngitbranching.js.org

Branching tutorial:
Always keep your best working version in the master branch, and semi-working code in your development branches. 
This means I will just clone your master branch when the demo-able version is due! 

Suggested (but not required) Book:
    Barron's AP Computer Science A , 8th Edition
    Good practice, useful explanations of java concepts.

Calendar:
12-20 (Thurs): Proposals Due.
01-03 (Thur): Prototypes Due, Project Coding Starts.
01-04 (Fri): Exam. 
01-14 (Mon): Final Project Demo Commit. I will clone in the morning.
    14-18th class time demos (4 groups per day so you can still have face time on project)
01/22 (Tues):
    Final Exam.
    Final Project Due. No More Final Project commits.

Prototype Requirements


note: Diagrams should be included to illustrate your features, you can use plain text (ASCII art) or hand draw them.

Front Page:

    Header:

Group Members                 Period ___
Group Name                    Group ____ (leave blank)


    Body:

    Project Name

    Project Description: An overview of what you plan to make.

    Include a summary of features for each of the milestones below:
  • minimum viable product
  • expected product
  • If you have extra time
New Page:

UML Diagram
- your expected class structure, this will certainly evolve over time.

New Page(s):

Development Stages
  • What is the order that you plan to implement features
  • How do you plan to break up the work
  • What features are dependent on other features (A tree like timeline can be a useful diagram here)







2018-12-18

posted Dec 18, 2018, 6:25 AM by Konstantinovich Samuel

Final Project Guidelines:

Pair Projects.
1. Choose a partner in the same period.
2. [Approval Required] Have a project proposal by Thurs Dec 20th.
3. DO NOT WRITE ANY CODE OVER BREAK. NO CODE WRITTEN OVER BREAK WILL COUNT.
4. [20 points] Your group must have 3 hard copies of a prototype by Thurs Jan 3rd (one to be submitted and one per group member). If it looks like you spent minimal effort, you will lose points.
5. Make a final project repo, add your partner as a collaborator. Make sure that every computer you use commits correctly. Look at the list of commits and see if your commits have your username + show your icon. ***OR YOU GET NO CREDIT***
6. [10 points] Your repo must have the following in README.md:
    -Instructions including how to compile, run, and use the program. (Updated before the demo and before the final deadline)
    -A development log that summarizes daily progress/changes/bugs. (Updated approximately once for every day you work)
7. [15 points] You must
    -commit regularly **starting after break**.
    -use proper commit messages.
8. [40 points] In class demo + Final Project
    -Your code should be readable
    -Include comments in your code
    -Proper variable/method names
    -Include good class heirarchy    

     
Total 85 Points.


Deadlines:
Dec 20th : 1-2 paragraph proposal describing what you plan to create.
Jan 3rd - Prototype due. (More details on requirements to follow)
    -Detailed Description of what you plan on doing
    -UML Diagram
    -Step by step plan which features to implement first
Jan X - Your Demo commit. This should be a working version of your final project, that you will improve upon over the next week. 
Jan Y - Your Final commit.

Presentations:
Jan X-? You will present the version you committed on Jan X (by 8am, you MUST make a demo branch to make it easy to pull. ) . I will clone everyone's demo branch. Please run through how you will demo beforehand. If you commit something that is UNTESTED, you will demo the untested code. TEST Your code as if you were going to demo it!


Types of projects:
Games are not prohibited, but I strongly urge you to consider something else for the 1st semester. 

Terminal Programs:
Easy:
Image Filters - Apply various effects to images.

Moderate:
Calculator - evaluate expressions, solve equations

Hard:
CSV editor - display the cells and let you

Games:

Easy text based games:
Board Games (not Monopoly/Catan)
Checkers
2048
Pacman

Moderate:
Chess for 2 human players (not computer AI)
Rogue-like game

Harder:
Tetris
NetHack

Text Adventure (Prohibited, generally they are poorly done and have too little structure)

To get keystrokes in the terminal:


2018-12-17

posted Dec 16, 2018, 9:05 PM by Konstantinovich Samuel   [ updated Dec 18, 2018, 6:26 AM ]

You most likely SHOULD NOT call getNthNode more than 1 time in the same method!
You can get the next/previous node, so calling it to get the next/previous will add a lot of extra time for no reason!

Let us discuss various ways of writing some of the methods in linked list. 


Connecting two linked lists should be able to happen in constant time!
//New Method:
public class myLinkedList{
   public void extend(MyLinkedList other){
        //in O(1) runtime, move the elements from other onto the end of this
        //The size of other is reduced to 0
        //The size of this is now the combined sizes of both original lists
    }
}


 

2018-12-13 LinkedList

posted Dec 13, 2018, 6:11 AM by Konstantinovich Samuel   [ updated Dec 14, 2018, 6:49 AM ]

DO NOW:
Read the entire lab. Discuss the discussion points with your neighbors.
Notice there are some warnings.

Please do not get me candy/chocolate (nor flowers) for the holidays.

Goal Let us talk about our algorithms with respect to doubly linked lists


DO NOT:
Loop through the list by index, especially in your toString() !!!


(Discussion point1. Why don't you want to use get(index) in your toString() ?  )

INSTEAD:
Traverse the list by keeping track of which node you are currently looking at using a Node variable.
Traversing the list in this manner is useful, but can only be done inside of the LinkedList class as it has direct access to the nodes.

Node current = first_node
while current != null:
  print current.value()
  current = current.next()

By making your while loop stop early:
-You can use this to find a node with a particular value
-You can use this to find the n'th node


Having a method to get the nth node is very useful. You would use such a method in many of your other methods.
Keep in mind: Any MyLinkedList method that returns a Node or takes a Node parameter should be private!


Git Repo:

MKS21X-LinkedList


Node
Fields:
    Node next,prev
    Integer data
Methods:
    Node next()
    Node prev()
    void setNext(Node other)
    void setPrev(Node other)
    Integer getData()
    Integer setData(Integer i)
    String toString()


MyLinkedList
Fields:
   Node start
   Node end
   int length   

Constructor:
      MyLinkedList() - make an empty list.

Public Methods:   (This is a good order to try to implement them)
     boolean add(Integer value)
     int size()   
     String toString()   //note you don't have get(index) yet, nor would you want to use it here

    Having a private method to get the nth node is very useful.
    You would use such a method in many of your other methods (hinted with a *)
    (Discussion point2. Why should getNthNode be private?)

*    Integer get(int index) 
*    Integer set(int index,Integer value)

     boolean contains(Integer value)
     int indexOf(Integer value)

*    void add(int index,Integer value) 
*    Integer remove(int index) 
*    boolean remove(Integer value) //a private method to find a node you want could be useful here
edit: fixed typo, remove(value) returns boolean

Remember to throw any exceptions that the actual LinkedList would throw. (Look at the documentation)

(Discussion point3. Regarding your methods, what are several situations that may cause special cases ? )





2018-12-12

posted Dec 12, 2018, 5:38 AM by Konstantinovich Samuel   [ updated Dec 12, 2018, 12:58 PM ]

Goal : Linked Lists 

Do Now:
1. List the operations ArrayLists have that are O(1)
2. List the operations ArrayLists have that are O(N)


Java Lists:
https://docs.oracle.com/javase/8/docs/api/java/util/List.html
The list interface does not require that you store the data in any particular way!

Java linked lists:

Scheme lists were linked lists. Remember Box Diagrams?

Linked Lists are different in runtime from array based lists.

add / remove 
at the end 
in the middle 
in the front 

List is a series of Nodes, each node has data, and a reference to the next (and possibly previous) Node.
This is possible because the node doesn't store an entire node inside of it! 
Since objects are stored as references, you do not have an object inside of an object inside of an object.
Instead you have an object with a reference to another object. That other object happens to be the same type as this object. 

MyNode:
  data
  next
  previous (optionally for double-linked lists)

MyLinkedList:
  Starting Node
  Ending Node 
  Size

Get Started with the following portions of linked list in a repo MKS21X-LinkedList

class Node{
 private int data;
 private Node next,prev;
}

class MyLinkedList{
 private int size;
 private Node start,end;

 public int size();
 public boolean add(int value);
 public String toString();
}



2018-12-11

posted Dec 11, 2018, 5:57 AM by Konstantinovich Samuel   [ updated Dec 11, 2018, 6:58 AM ]

Lab Day:
1. Anyone that has completed all sorts should test the times of selection vs insertion @ 40k,80k
    The insertionSort should take 1/3rd to 1/6th the time of selectionSort.
2. Verify your bubble sort works on 1 million zeros (all 0's) very quickly. (< 1 sec)
3. Work on advent of code problems! Discuss which are the "easy" problems on the google group! Some are much harder than others.


1-10 of 63