2016-09-19 HW04

posted Sep 19, 2016, 6:41 AM by Samuel Konstantinovich   [ updated Sep 19, 2016, 10:47 AM ]
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");

    Given:
    public static int foo(int x){
        return 2 * x + 1;
    }
    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 ( <boolean> ) {
  // run here if above is true
}

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


HW04:
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 if you feel you want to get back on track. 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