Courses‎ > ‎APCS - Term 0‎ > ‎

Konstantinovich 2018-2019


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-17 Final Tips

posted Jan 18, 2019, 5:38 AM by Samuel Konstantinovich   [ updated Jan 18, 2019, 9:49 AM by Konstantinovich Samuel ]

Exam Calculator:

Your grade is not the number of questions correct! Each question is more than 1 point

GRADE * 0.822 + 16.308
Rounded to tenths.

New Median: 48.4 (90%)
New Upper Quartile: 50.8 (94%)

Your final exam is Tuesday. The room is posted on Talos.

IGNORE the jupiter schedule, it is the wrong day!!!

Goal: Maximizing Gain and Minimizing Pain on a CS Final Exam

The night before...

  • Refrain from staring at any light-radiating display for the half hour preceding slumber.
  • Do not consume caffeine or other stimulants after 5pm.
  • Implement redundant wake-up-on-time procedures.
  • Pack your bag
    • multiple pencils (Test them!)
    • multiple pens (blue/black; Test them!)
    • erasers (Test them!)
    • exam tickets (if applicable) and/or hardcopy of exam location & time info
    • water bottle
    • pro: granola bars or equivalent snack, since your normal lunch routine is likely out-of-whack

The day of...

    • Take an earlier train than the minimum.
    • Aim to arrive at least 30min before start of exam.
  • Hydrate.
  • Breathe.


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

Menu Demo:

//API :
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){
    for(int i = 0; i < s.length();i++){

  public static void putString(int r, int c,Terminal t,
        String s, Terminal.Color forg, Terminal.Color back ){

    for(int i = 0; i < s.length();i++){
  public static void main(String[] args) {

    Terminal terminal = TerminalFacade.createTextTerminal();

    TerminalSize size = terminal.getTerminalSize();

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

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


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

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

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

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


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





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:.
$ java -cp lanterna.jar:. TerminalDemo

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


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)


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

-Fill out this survey (it does not collect your email)
-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.


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
-Linked Lists
[Note that these topics won't be on the final exam]

Practice Final is posted

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

By tomorrow you should have all the multiple choice done


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:

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.

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:


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


    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)


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

Final Project Guidelines:

Pair Projects.
1. Choose a partner in the same period.
2. [Approval Required] Have a project proposal by Thurs Dec 20th.
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
    -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.

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.

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:
Image Filters - Apply various effects to images.

Calculator - evaluate expressions, solve equations

CSV editor - display the cells and let you


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

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


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

To get keystrokes in the terminal:


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 ]

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

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

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

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 =

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:


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

   Node start
   Node end
   int length   

      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 ? )


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:
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. 

  previous (optionally for double-linked lists)

  Starting Node
  Ending Node 

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();

1-10 of 64