Announcements


2015-01-20 Practice Final

posted Jan 20, 2015, 9:00 AM by Samuel Konstantinovich   [ updated Jan 20, 2015, 9:05 AM ]

Look at the PDF here: (you can work on any paper you wish)
https://www.dropbox.com/s/dfubc6wo48stzs9/APCS-Fall-2013-final.pdf?dl=0

Please fill this out really quickly, one per final project group: (regarding project presentations)

2015-01-14

posted Jan 13, 2015, 5:42 PM by Samuel Konstantinovich   [ updated Jan 13, 2015, 5:42 PM ]

NYU Trip Sign Up:
Deadline is next wednesday end of 10th. 
-If you forget to sign up, you can't go.
-If you forget to bring in the trip slips ON TIME, you can't go.
-If you cancel at the last minute (or just don't show up) you rob a classmate of the opportunity of going, so you will be banned from all future CS opportunities.

https://docs.google.com/forms/d/1u8d84Kx0BzkfQACLiQbiX7Dnzw8k6PO0NFcdxYNeR3M/viewform

2014-12-22

posted Dec 21, 2014, 9:28 PM by Samuel Konstantinovich   [ updated Dec 21, 2014, 9:29 PM ]

Today you have the period to: 
-brainstorm project ideas Ideas in groups 
-find a partner in class

Note that and more than one group can work on similar projects (provided they work independently)

Logistics:
1. One member of the group will create a project repo on github, and add the other member as a collaborator.
****If your git logs don't have you contributing from your git account, you don't get credit for the commits. So make sure you test that your commits work the right way and your names link back to your git account. 

2. The readme file will be updated constantly with:
A chronological history of 
new features
bug fixes
project milestones etc.

3a. Overall You will be given 2 weeks of homework time, about 2 weeks of class time, + 2 weekends to work on this. 
I estimate you have to put in about 17-20 hours per person on this project spread out over about 14 days.  
3b. You are ABSOLUTELY not allowed procrastinate. I will reserve 15% of your grade for: "Did you  do work over time." (Easy to get an A, if you do the work the right way!)
procrastination = 15% penalty! 
3c. This will count as 1.5 exams. 

4. You are allowed to work on the project over break, and that would lessen the amount of work you are required to do later. 



2014-12-10 GUI-II

posted Dec 10, 2014, 11:45 AM by Samuel Konstantinovich   [ updated Dec 10, 2014, 11:45 AM ]


HW:
Complete your Celsius to Fahrenheit converter.

Notes:
import java.awt.event.*;
import javax.swing.*;
import java.awt.*; //needed for pane
public class Gui2 extends JFrame implements ActionListener{
    private Container pane;
    private JButton b,clear;
    private JLabel l;
    private JTextField text;
    private Container buttons;
    private Container textyStuff;
    private JCheckBox box;

    public Gui2() {
				this.setTitle("Who is the doctor!");
				this.setSize(600,100);
				this.setLocation(100,100);
				this.setDefaultCloseOperation(EXIT_ON_CLOSE);
        
				pane = this.getContentPane();
				pane.setLayout(new GridLayout(2,1));

				l = new JLabel("Text:",null,JLabel.CENTER);
				b = new JButton("Punctuate!");
				clear = new JButton("Exterminate!");
				text = new JTextField(40);
				box = new JCheckBox("!!!!");

                                // make the buttons call the actionListener
b.setActionCommand("addPeriod"); b.addActionListener(this); clear.setActionCommand("delete"); clear.addActionListener(this); buttons = new Container(); buttons.setLayout(new FlowLayout()); buttons.add(clear); buttons.add(b); buttons.add(box); textyStuff = new Container(); textyStuff.setLayout(new FlowLayout()); textyStuff.add(l); textyStuff.add(text); //add the 2 containers pane.add(textyStuff); pane.add(buttons); }
                                    //look at which command is being executed, and choose an action
public void actionPerformed(ActionEvent e){ String action = e.getActionCommand(); //System.out.println(action); if(action.equals("addPeriod")){ String s = text.getText(); if(box.isSelected()){ s+="!"; }else{ s+="."; } text.setText(s); } if(action.equals("delete")){ text.setText(""); } } public static void main(String[] args) { Gui2 g = new Gui2(); g.setVisible(true); } }

2014-12-09 GUI

posted Dec 10, 2014, 6:00 AM by Samuel Konstantinovich   [ updated Dec 10, 2014, 6:00 AM ]

Basic Window:
import javax.swing.*;
public class Window extends JFrame {
    public Window() {
        this.setTitle("My first GUI");
        this.setSize(600,400);
        this.setLocation(100,100);
        this.setDefaultCloseOperation(EXIT_ON_CLOSE);
    }

    public static void main(String[] args) {
        Window g = new Window();
        g.setVisible(true);
    }
}


Window With some stuff added:

import javax.swing.*;
import java.awt.*;
public class Window2 extends JFrame {
private Container pane;

private JButton b;
private JLabel l;
private JTextField t;
private JCheckBox c;
    public Window2() {
this.setTitle("My first GUI");
this.setSize(600,400);
this.setLocation(100,100);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);


pane = this.getContentPane();
pane.setLayout(new FlowLayout());

b = new JButton("Do Nothing");
l = new JLabel("This is AWESOME! (lies)",null,JLabel.CENTER);
t = new JTextField(12);
c = new JCheckBox("Overclock!!!");
pane.add(l);
pane.add(b);
pane.add(t);
pane.add(c);
}

    public static void main(String[] args) {
        Window2 g = new Window2();
        g.setVisible(true);
    }
}

2014-12-04

posted Dec 3, 2014, 7:00 PM by Samuel Konstantinovich   [ updated Dec 3, 2014, 7:11 PM ]

You must know the following sorts for the AP:
selection sort (you will learn this soon)
insertion sort
merge sort (you will learn this 2nd semester)

In addition to sorting you need to know how to search for something using:
linear search  
binary search

Note that for StuyCS you are required to know much more. 
We will go over many more sorts later. 
Including but not limited to: radix    quick    bubble    heap

Today, I assume you have a functional insertionSort()

Consider the following method :
int find(String target)
The method should return the smallest index of an element in your List that matches the target string. (The index of the left most matching element)

You must add it to BOTH your SuperArray and OrderedSuperArray.


BEFORE YOU WRITE ANY CODE:
Take out your notebook. Write your name/date on the top of a piece of paper. You will write some answers down:

-Discuss with others and WRITE DOWN ANSWERS: 
1. What algorithm should be used for searching in the SuperArray vs the OrderedSuperArray, why?
2. What happens if you find the target on the 1st try in the linear search? (remember you want the smallest index that has the target value)
3. What happens if you find the target on the 1st try in the binary search?(remember you want the smallest index that has the target value)
4. At the bottom of the page write the word "Thanks to the following people"
5. Have at least 2 people that you discussed these questions with with write their names on the paper. 



2014-12-03 COMPETITION!

posted Dec 2, 2014, 10:23 PM by Samuel Konstantinovich   [ updated Dec 2, 2014, 10:23 PM ]

Document means you need to write it down in a place I can look at. 
If you don't have EXPLICITLY written explanations, then <insert amusing but serious threat>.

1. Please verify that your insertionSort() DOES in fact work by testing it. Are you sure it worked?  Document how you did this. 
Hint: Arrays.sort() is guaranteed to work. 

2. Please compare the speed of your insertionSort() to this version of insertionSort:
public void badInsertionSort(){
        OrderedSuperArray c = new OrderedSuperArray();
        while( this.size() > 0){ 
            c.add(this.remove(0));
        }
        while(c.size() > 0){
            this.add(c.remove(0));
        }
}

2a. You need to devise a simple, but robust testing methodology, then apply it to the two sorts. Document how you did this. 
2b. If your insertion sort is SLOWER than the badInsertionSort(), then you did something wrong! Go fix it. 

3. In class you can compare with others to see how fast is possible. You cannot compare your insertion sorts against each other on different machines. Instead see how much faster (as a %) your insertion sort is compared to the bad one (on the same size data set, using the same testing methodology).  

3b. Nominate one student to log the times of the top 5 fastest versions, and the name of the students that wrote it. Students should verify the top 5 fastest ones work, because you can sort poorly VERY fast.

Homework:
4. Please compare your OrderedSuperArray to the one at the end of the post. This is to help you understand by reading (hopefully) good code.  



/*++++++++++++++++++++++++++++++++++++++++++++++*/

Solution to OrderedSuperArray:

public class OrderedSuperArray extends SuperArray{

    public void add(String o){
        int index = size();
        while( index >0 && get(index-1).compareTo(o) > 0 ){
            index--;
        }
        super.add(index, o);
    }

    public void add(int index, String o){
        add(o);
    }

    public String set(int index, String o){
        //this is the lazy way, but a good start.
        //This commented out code makes 2 linear passes:
        /*
          String old = remove(index); //remove is linear...
          add(o);//add is linear...
          return old;

        */


        //replacing that code with this code, means you only do 1 linear pass:
        String old = data[index];
        if(size() == 0){ //Included so that you cannot try it on an empty list.
            throw new IndexOutOfBoundsException("" + index);
        }

        //decide if you need to shift left or right, you do EITHER, or none.
        if(o.compareTo(data[index]) > 0){ //move it to the right
            //at least one item left && the next item is smaller
            while(index < size() - 1 && o.compareTo(get(index + 1)) > 0 ){
                //shift the element
                data[index] = data[index+1];
                index++;
            }
        }else if(o.compareTo(data[index]) < 0){//move it to the left
            while(index > 0 && o.compareTo(get(index - 1)) < 0 ){
                data[index] = data[index-1];
                index--;
            }
        }
        data[index] = o;
        return old;
    }
    //Writing the code to save 1 linear pass may not be worth it...
    //in fact in this case it probably isn't! This method is challenging for several reasons.


    //P.S. A bug in my code (I copy pasted a while loop, changed the < to >,
    //but don't change the ++ to --) resulted in 15 minutes of testing.
    //Next time you face a hard problem, realize that NOBODY gets
    //everything right away all the time.
}

2014-12-01 SuperArray

posted Dec 1, 2014, 7:36 AM by Samuel Konstantinovich   [ updated Dec 1, 2014, 9:30 AM ]

Change SuperArray

  • Take your SuperArray code and make a copy in folder 04OrderedSuperArray.
  • Change the data type from Object/Integer to String
  • You may have to change references from == to .equals (or compareTo)

Make a new class OrderedSuperArray

OrderedSuperArray acts like SuperArray but always maintains the array in sorted order, that is Strings that start with "a" come before words that start with "b" etc. Use the String compareTo to determine the location.

Notes:

  • OrderedSuperArray must extend SuperArray
  • The add(index,element) routine no longer makes sense - what should you do with it?
  • The add(element) routine used to add to the end of the SuperArray, change it so that it adds the new element in it's proper location.
  • When you get the basic class working, overload the set method. It should change the value of the element and then move it to its proper location.

DO NOT: use the built in Arrays.sort() command.

Extras:

  • If you are ambitious you can look to change SuperArrray to use generics (do a search for Java generics) - Generics are the Java feature that let us specify the type in the angle brackets. For example, when we use ArrayLists: ArrayList<String> or ArrayList<Integer>

2014-11-26 files

posted Nov 26, 2014, 8:38 AM by Samuel Konstantinovich   [ updated Nov 26, 2014, 8:38 AM ]

Interfaces demo files:
https://github.com/konstantinnovation/APCS/tree/master/interfaces

2014-11-25 HW (vacation)

posted Nov 24, 2014, 5:57 PM by Samuel Konstantinovich   [ updated Nov 24, 2014, 8:41 PM ]

This documents the final required revisions to your WordSearch. 

-The deadline is Tuesday December 2nd 11:59pm. (That what due by Wednesday means)
-You have a lot of time to complete this, please do not slack off. 
-I expect to see your git commits and pushes regularly. Lack of commits can and will be used to reduce points of the project... so don't just do it without github and commit a working version. I am not trying to hurt your grade, I am trying to encourage you to use github properly.


Overview of new main behavior:
java Driver rows cols randomSeed answers
1. rows and cols are the dimension of the puzzle.
2. The randomSeed can be changed to force the same puzzle to occur again.
3. Only if the randomSeed is provided, should you be able to trigger answer mode by passing the value 1 into the answers parameter. All other values will be a normal puzzle, and not show the answer.

so:

java Driver 20 30 124850 0 would print the 20x30 puzzle seeded by 124850, including which words are inside the puzzle. 
java Driver 20 30 124850 1 would print the answer key for the 20x30  puzzle seeded by 124850    (both of these will match)

java Driver 10 20 8230 123 would print the 10x20  puzzle seeded by 8230
java Driver 10 20 8230     would print the 10x20  puzzle seeded by 8230  (both of these will match)

Changing the dimensions or wordlist, even by a single number or word, will cause a completely different puzzle. 

Example: 

(because of outdated terminal limitations, I try to keep the lines < 80 characters long. Clearly we can make our terminals wider, but this avoids the requirement to resize. You should keep things from getting too wide.)

$ java Driver 12 18 42308
Find these words:
      zonae           zymurgy          zinckier            zither
    zouaves             zooms           zorilla           zipless
    zigzags            zizzes         zoologist            zooeas
    zooming             zoeal             zitty            zinebs
     zorros            zygoma           zoccolo           zoysias
     zonked            zipped           zechins            zoccos
    zoecium             zooey             zorch             zupas
r g n i m o o z r e h t i z e h v y
x l e z o r c h i l e o l o c c o z
e s t y i z e z s n a a z o e a l i
z z z t z y w i g a n z e c h i n s
o i o t o m d p k z o e c i u m f d
o p y i r u e p h c z f s e z z i z
m l s z r r k e c g n l q b h m o t
s e i u o g n d t k m i s a e o o z
l s a p s y o s o c c o z q b n r f
z s s a l d z z o o l o g i s t i g
g d z s e v a u o z i g z a g s n z
z o o e y a l l i r o z a m o g y z


Now with the same seed (42308) I can generate an answer:
$ java Driver 12 18 42308 1  
Findd these words:
      zonae           zymurgy          zinckier            zither
    zouaves             zooms           zorilla           zipless
    zigzags            zizzes         zoologist            zooeas
    zooming             zoeal             zitty            zinebs
     zorros            zygoma           zoccolo           zoysias
     zonked            zipped           zechins            zoccos
    zoecium             zooey             zorch             zupas
_ g n i m o o z r e h t i z _ _ _ _
_ _ _ z o r c h _ _ e o l o c c o z
_ _ _ y _ z e z _ _ a _ z o e a l _
z z z t z y _ i _ _ n z e c h i n s
o i o t o m d p k z o e c i u m _ _
o p y i r u e p _ c z _ s e z z i z
m l s z r r k e _ _ n _ _ b _ _ _ _
s e i u o g n d _ _ _ i s a e o o z
_ s a p s y o s o c c o z _ _ n _ _
_ s s a _ _ z z o o l o g i s t i _
_ _ _ s e v a u o z i g z a g s _ z
z o o e y a l l i r o z a m o g y z

4. The main will pass the fileName of the list of words into the constructor as well. 

Your main will look like this:

public static void main(String[]args){
   /*this is the "NEW SECTION" 
    *
    *This is where you need to write something in order
    *to get the values from args, OR decide to use default values 
    */
    WordGrid w = new WordGrid( /*some stuff from NEW SECTION*/ );
    if(you need to change the random seed){  /*see more notes on this later*/
      w.setSeed( ??? );  
    }
    w.loadWordsFromFile("fileNameYouMade.txt", /*something from NEW SECTION*/ );
    System.out.println( "Find these words:\n"+ w.wordsInPuzzle() );
    System.out.println( w );
}
That is all! So easy. But wait... how does that load the words? This means your main is merely to handle parameter passing from the terminal to the constructor. All logic should be handled internal to your class!!!

THINGS YOU ARE WRITING:

New Instance Variables:
1. Make a Random as part of your WordGrid class. This will make it really easy to reproduce things, just use that random anytime you need to generate random numbers. 
2. Make something to store the words you successfully added to your WordGrid.

New Constructor Parts: 
3. Make sure your constructor initializes the new instance variables


New Required Methods:
4.
public void loadWordsFromFile(String fileName, boolean fillRandomLetters)
    -filename is used to tell the WordGrid from which file to read all of the words.
    -fillRandomLetters is used to determine if you need to fill it up or not. If there are 4 arguments, look at the 4th one to determine this boolean. A '1' means this should be false, otherwise If the value is not '1' or there aren't enough parameters you assume that you DO want to fill in the letters, and default the value to true

5. public String wordsInPuzzle()
    -Return a formatted string of text that has several words per line. This will require you to keep track of the added words.

6. public void setSeed(long seed)
    -Mutator that changes the random seed of your Random object. Call this method before you add words to predict the way they are added!

Regarding Randoms and seeds:
 Random rng = new Random(seed);

Is equivalent to:

 Random rng = new Random();
 rng.setSeed(seed);
The 2nd method allows you to only set the seed in some instances, and not others. This allows the default behavior of different seeds all the time to be used unless a seed is specified. 


Methods that would be very useful:
7. addManyWordsToList ( ArrayList<String> allWords )









1-10 of 36