Courses‎ > ‎AP Computer Science‎ > ‎Konstantinovich‎ > ‎notes‎ > ‎

2017-09-13

posted Sep 13, 2017, 10:14 AM by Samuel Konstantinovich   [ updated Sep 13, 2017, 1:42 PM ]

Windows users can run ubuntu as a virtual machine:
 https://www.lifewire.com/install-ubuntu-linux-windows-10-steps-2202108

If you want to do this then mMake sure you use Ubuntu 16.04.3 LTS

After you install the ubuntu virtual machine:

1. Install emacs:
sudo add-apt-repository ppa:kelleyk/emacs
sudo apt-get update
sudo apt-get install emacs25
2. Install git:  (we will use this later it isn't just for the next step)
sudo apt-get install git
3. Install java: 
sudo apt-get install openjdk-8-jdk
4. Add a nice config for emacs like this:
git clone https://github.com/bodil/ohai-emacs.git ~/.emacs.d

You can read about the config here: https://github.com/bodil/ohai-emacs   


Goal: More converting your prior CS into Java specific CS.

Do Now: Predict the result of each print statement

note that:
- "ab" + "cd"  results in "abcd"
- 1 + "fish"   results in "1fish"
- Strings only work with +, not other operators.
       System.out.println(1 + 2 + 3 / 3);
       System.out.println(2.0 + 1 / 2);
       System.out.println(2 + 1.0 / 2);
       System.out.println("hey" + "you");
       System.out.println("2+3" + "4");
       System.out.println("5"+ 6 + 7);
       System.out.println(1 + 2 + "3");
       System.out.println(23 % 4);

    Functions!
    public static RETURN_TYPE FUNCTION_NAME(TYPE PARAMNAME...){
        
    }

    public static int foo(int x){
        return 2 * x + 1;
    }
    public static double bar(int x, int y){
        return x * x + y + 1.0;
    }

    //void means there is no return type!
    public static void bah(int x, int y){
        System.out.println("Shhh!");
    }

    Evaluate:
    foo(2)
    foo( foo(2) )
    int u = 2;
    foo( u + foo(3) )

Boolean expressions are created using: and, or, not. Java does not have those keywords however instead use the following. 
and:    &&
or:     ||
not:     !   
example:   a && !b || !(a && b)

and, or, and not only work on boolean values or expressions. They do not work on numbers.

To turn other values into booleans we use comparisons:
>    <=
<    >=
==   !=
  
Conditional Statements:

if ( <boolean1> ) {
  // run here if boolean1 is true
}



if ( <boolean2> ) {
  //A only run this section when <boolean2> is true
}
else{
  //B only run this section when <boolean2> is false
}
//At this point either A or B have executed, but never both (always exactly one)


HW03:
1. Create an account on http://codingbat.com/ please do NOT use the Mozilla Persona thing. 
2. Do any 2 warmup-1 problems to see how the site works.
3. Be careful, when you want to work on problems you should LOG IN first, or the progress will not be saved. 
This site is another great resource and has many problems to practice on! I will also assign many problems from here.

4. Look at the Logic-1  section, and complete these 4 problems:
 > sortaSum 
 > dateFashion 
 > caughtSpeedin
 > squirrelPlay 


Comments