lectures and homework

Remember to use the Discussion Board: (Via Email, or as a forum)
https://groups.google.com/a/stuy.edu/forum/#!forum/konstantinovich-apcs2016

2017-01-19 or 20 depending...

posted Jan 19, 2017, 12:13 PM by Samuel Konstantinovich   [ updated Jan 19, 2017, 12:13 PM ]

2017-01-17 - Hand in Prototypes

posted Jan 17, 2017, 6:36 AM by Samuel Konstantinovich   [ updated Jan 17, 2017, 5:40 PM ]

I want to collect all of the prototypes at once, please have them! I forgot to ask for them so bring them tomorrow.


1. Volunteer order for final project demos.
2. Review For Final Exam:

-Java Operations and types

TYPES:

All the primitive types have a fixed size. Thus, the primitive types are limited to a range of values. 

A smaller primitive type (byte) can contain a smaller ranger of values than a bigger one (long).

CategoryTypesSize
(bits)
Minimum
Value
Maximum
Value
PrecisionExample
Integerbyte8-128127From +127 to -128byte b = 65;
char160216-1All Unicode characterschar c = 'A';
char c = 65;
short16-215215-1From +32,767 to -32,768short s = 65;
int32-231231-1From +... to -...
(big values you can calculate)
int i = 65;
long64-263263-1From +... to -...  
(big values you can calculate)
long l = 65L;
Floating
point
float322-149(2-2-23)·2127From 3.402,823,5 E+38
to      1.4 E-45
float f = 65f;
double642-1074(2-2-52)·21023From 1.797,693,134,862,315,7 E+308
      to 4.9 E-324
double d = 65.55;
Otherboolean1----false, trueboolean b = true;
void----------



OPERATIONS:

Each operator in java wants to perform the operation on the same type, and give a result of that type.
1/2 results in 0
1.0 / 2.0  results in 0.5

Notice that INTEGER division truncates the result! This is potentially dangerous if you forget about it.

This means something special has to happen when you mix types:
1 / 2.0  ->  ???   (it is 0.5 also)

This is due to Type Promotion - when one of the operands is promoted to a broader type. A temporary variable is created to store this converted value, and that is used
to perform the calculation. The hierarchy of types from broad to narrow is as follows:  (as you might predict by knowing about types from before)
  1. double
  2. float
  3. long
  4. int
  5. char or short
  6. byte
So if you perform:    1.0 * 2.0f   (double times float)   
The float is converted to a double, and then multiplied to give you 2.0 (a double)


2017-01-13 Final Project Update

posted Jan 13, 2017, 7:13 AM by Samuel Konstantinovich   [ updated Jan 13, 2017, 7:15 AM ]

Update: Final Project Readme file MUST include:
-Brief description of your project
-List of Working features / Things I should test
-List of unresolved bugs
-Directions on how to compile and run your code 
-Directions on how to use your program
(Please format the document to look reasonably clear)


Do Now:

/**for each function decide:
   What is the runtime in terms of n?*/
  public static int foo1(int n){
    int x = 0;
    for(int i = 0; i < n/2; i++){
      for(int j = 0; j < n/2; j++){
        x += i*j;
      }
    }
    return x;
  }
  
  public static int foo2(int n){
    int x = 0;
    for(int i = 0; i < n; i++){
      for(int j = 1; j < n; j*=2){
        x += i*j;//doesn't matter
      }
    }
    return x;
  }
  
  public static int foo3(int n){
    int x = 0;
    for(int i = 0; i < n; i+=3){
      for(int j = 0; j < n; j++){
        for(int k = 0; k < j; k++){
          x+= i+j+k;//doesn't matter
        }
      }
    }
    return x;
  }

2017-01-11

posted Jan 11, 2017, 6:05 AM by Samuel Konstantinovich   [ updated Jan 11, 2017, 6:05 AM ]

Practice Exam Questions posted on mailing list. Ignore question 2. 
Complete them over the next two weeks.
Some practice multiple choice questions can be found on the AP course description pdf (page 18 onwards)

2017-01-06 Terminal Things

posted Jan 6, 2017, 5:50 AM by Samuel Konstantinovich   [ updated Jan 11, 2017, 6:27 AM ]

public class Text{
    private static final int BRIGHT = 1;
    private static final int DARK = 2;
    private static final int ITALICS = 3;
    private static final int BLACK = 30;
    private static final int RED = 31;
    private static final int GREEN = 32;
    private static final int YELLOW = 33;
    private static final int BLUE = 34;
    private static final int MAGENTA = 35;
    private static final int CYAN = 36;
    private static final int WHITE = 37;
    private static final String CLEAR_SCREEN =  "\033[2J";
    private static final String HIDE_CURSOR =  "\033[?25l";
    private static final String SHOW_CURSOR =  "\033[?25h";

    //use this to go back to normal terminal colors
    private static final String RESET = color(40,37)+SHOW_CURSOR;

    //use this to convert from color to background (30 to 37 becomes 40 to 47)
    public static int background(int color){
	return color + 10;
    }

    //terminal specific character to move the cursor to a location
    //top left is 1,1
    private static String go(int x,int y){
        return ("\033[" + x + ";" + y + "H");
    }

    
    private static String color(int a, int b){
        return ("\033[0;" + a+ ";" + b + "m");
    }
    private static String color(int a, int b,int c){
        return ("\033[0;" + a+ ";" + b + ";" + c+ "m");
    }
    private static String color(int a, int b,int c, int d){
        return ("\033[0;" + a+ ";" + b + ";" + c + ";" + d + "m");
    }


    //And don't forget you can easily delay the printing if needed:
    private static void wait(int millis){
        try {
            Thread.sleep(millis);
        }
        catch (InterruptedException e) {
        }
    }


    public static void main(String[]args){
	System.out.println(CLEAR_SCREEN);
	System.out.println(HIDE_CURSOR);

	//SHOW A LOT OF COLORS!
	for(int i = 0; i < 8; i++){
	    for(int j = 0; j < 8; j++){
		System.out.println(go(i+1,j+1)+color(30+i,40+j) + "#");
		System.out.println(go(i+1,j+10)+color(30+i,40+j,BRIGHT) + "#");
		System.out.println(go(i+1,j+19)+color(30+i,40+j,DARK,ITALICS) + "#");
	    }
	}

	//HOW TO USE FOR SOME PARTS:
	System.out.println(go(15,20)+color(ITALICS,RED,background(BLUE))+"ITALICS FISH!~~~~");
	System.out.println(go(20,20)+color(GREEN,background(YELLOW))+"+=+ ^o^ ");


	System.out.println(RESET);
	
    }

}

2016-12-23 HW Survey

posted Dec 23, 2016, 7:06 AM by Samuel Konstantinovich   [ updated Dec 23, 2016, 7:06 AM ]

Final Project Information Form: 

2016-12-22 Prototype

posted Dec 22, 2016, 6:02 AM by Samuel Konstantinovich   [ updated Dec 22, 2016, 6:02 AM ]

Regarding final projects:
-Please let me know if your partner is non-cooperative.
-Please let me know if you and your partner cannot resolve a conflict.
-If you wait until the last minute to tell me you have partner issues, I will not be able to do anything. 


Prototype: Due the Wed after you get back from break, it can be updated afterward, but I want to see that you have it. 

This will be 20% of your final project grade. It should look like you put serious effort into it. If it looks like you did this assignment on the train coming to school or rushed it the night before, I will grade you accordingly. 


Prototype Format Document:
https://www.dropbox.com/s/x4xcomc9poc28xg/Prototype.pdf?dl=1

-The purpose of the document is for
   a. Come together with your partner and make a clear picture of what you BOTH want to do. 
   b. Explicitly describe the behavior of your project so I can tell you if there are potential problems. 
   c. Make clear expectations public so you have guidelines to follow and don't cut features for no reason.
   d. Have the document in class when you are working so I can reference it when I see your group.

-There should be absolutely NO CODE!

-A timeline of features to be added is nice, prioritize by importance

-Describe what your minimum viable product would be. This is what you want to get working ASAP because you are going to demo your project a week before the deadline. 

2016-12-21

posted Dec 21, 2016, 6:09 PM by Samuel Konstantinovich   [ updated Dec 21, 2016, 6:09 PM ]

Sample Code:

import javax.swing.*;
import java.awt.*;//NEW STUFF!
import java.awt.event.*;

public class Window3 extends JFrame implements ActionListener{
    private Container pane;
    private JLabel j;
    private JTextField t;

   public Window3() {
    this.setTitle("My first GUI");
    this.setSize(600,400);
    this.setLocation(100,100);
    this.setDefaultCloseOperation(EXIT_ON_CLOSE);

    pane = this.getContentPane();
       pane.setLayout(new BoxLayout(pane, BoxLayout.Y_AXIS));
      JButton b = new JButton("ByteMe");
      b.addActionListener(this);
      b.setActionCommand("Byte");
      JButton b2 = new JButton("No...");
      b2.addActionListener(this);
      b2.setActionCommand("NotByte");
     t = new JTextField(10);
     JCheckBox c = new JCheckBox("OverClock");
     j = new JLabel("Meaning of life is... ");
     pane.add(c);
     pane.add(t);
     pane.add(b);
     pane.add(b2);
     pane.add(j);
  }

  public void actionPerformed(ActionEvent e){
   String event = e.getActionCommand();
   if(event.equals("Byte")){
     String s = t.getText();
     s += "-0101000";
     j.setText(s);
   }
   if(event.equals("NotByte")){
    j.setText("Fish");
   }
  }
}

2016-12-20

posted Dec 20, 2016, 6:29 AM by Samuel Konstantinovich   [ updated Dec 20, 2016, 6:33 AM ]

Homework:
1. Write static methods CtoF(double t) and FtoC(double t) that converts the given temperature from/to the indicated scale.
CtoF(-40.0) -> -40.0
CtoF(100.0) -> 212.0
FtoC(212.0) -> 100.0

We will use these tomorrow.

2. Review some java GUI (graphical user interface) code so that we can start tomorrow with how to make it do things!

note : These java programs must be run on a local terminal, not a remote terminal session (ssh) or tty session.

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:
Basically you m ake some "things" and then add them to the content pane. 


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;
 
  //CONSTRUCTOR SETS EVERYTHING UP
  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());  //NOTE!! THIS CAN BE CHANGED (see below)
    
     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);
}

  //MAIN JUST INSTANTIATES + MAKE VISIBLE
  public static void main(String[] args) {
     Window2 g = new Window2();
     g.setVisible(true);
  }
}

LAYOUTS CAN MAKE A HUGE DIFFENCE:

2016-12-19 Final Project

posted Dec 19, 2016, 7:12 AM by Samuel Konstantinovich   [ updated Jan 9, 2017, 11:17 AM ]

Final Project Guidelines:
Pair Projects.
1. Choose a partner in the same period.
2. Have a project proposal by Wed Dec 21st.
3. Make a final project repo  
4. You must have a hard copy of a prototype by Wed Jan 4th.

Deadlines:
Jan 10th - Your Demo commit. This should be a working version of your final project, that you will improve upon over the next week. 
Jan 17th - Your Final commit.

Presentations:
Jan 10-14 You will present the version you committed on the 10th (by 8am, you can also make a demo branch to make it easy to get) . I will clone everything the morning of the 10th. 
Jan 17-20 You will present the final version (optional but strongly recommended) Reasons to not present again would be discussed on a per-project basis.

Types of projects:
Games are not prohibited, but I strongly urge you to attempt something else for the 1st semester. Games are much harder because they are larger in scope, and require a lot of polish. 

1-10 of 65