### 2018-09-17

posted Sep 17, 2018, 5:51 AM by Konstantinovich Samuel   [ updated Sep 17, 2018, 10:04 AM ]
 Homework:1. Create an account on http://codingbat.com/ please do NOT use the Mozilla Persona thing.IF YOU DID 1b IN CLASS, PLEASE DO IT AGAIN (I reset it period 6)1b. In your profile SHARE with konstans@stuy.edu 1c. Change your MEMO to be your name formatted like:  PD.Last.First   (no spaces in your name please)  e.g.       3.Kim.Jamal    7.WeiMin.Fahran    8.Keiko.Jimenez2. 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 Goal: Converting more of your prior CS into Java specific CS.Do Now: Predict the result of each print statementnote that:- Strings only work with the + operator (concatenation), 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);//remember ASCII?System.out.println('A'+1);System.out.println('C'-1+" B");System.out.println('A'+'A');Functions!public static TYPE IDENTIFIER( PARAMS ){   //body goes here       }parameters:  0 or more variables with their types:Just some function headers as examples:public static int foo(int a)public static float bar(int x, String s) public static void foobleh()Complete function examples:    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:    System.out.println(   foo(2)    );    System.out.println(   foo( foo(2) ) );    int u = 2;    System.out.println(   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 is true}else{  //B only run this section when is false}//At this point either A or B have executed, but never both (always exactly one)else can be connected to an additional if statement:if( a ){}else if( b ){} //OPTIONALLY ADD ANOTHER ELSE
Comments