Introduction to Application Programming https://xliu12.mysite.syr.edu/ Introduction to Application Programming IST 256 Application Programming for Information Systems Xiaozhong Liu
Mario player = new Mario(); //hit a special brick Mario problem http://www.pouetpu-games.com/index.php?section=2&game_id=1&w=640&h=480 Mario player = new Mario(); //hit a special brick if (player.status.equals(“small”)) { show_mushroom(); } else { show_flower();
Mario problem Mario player = new Mario(); //Mario change if (get_mushroom()) { player.status = “big”; } if (get_flower()){ player.status = “shoot”; if (get_hurt() && player.status.equals(“big”)) { player.status = “small”; if (get_hurt() && player.status.equals(“small”)) { player.status = “die”;
Example 1 If your age > 20, serve you wine; else, serve you soda… int age; String drink; age = ??; if (age > 20) { drink = “wine”; } else { drink = “soda”; System.out.println(drink);
System.out.println(result); Sum of: 1 + 2 + 3 + 4 + 5 + 6 +……….. + 100 int result = 0; result = result + 1; result = result + 2; result = result + 3; …… result = result + 100; System.out.println(result);
for (int i = 0; i <= 100; i = i + 1) { result = result + i; } Sum of: 1 + 2 + 3 + 4 + 5 + 6 +……….. + 100 int result; result = 0; for (int i = 0; i <= 100; i = i + 1) { result = result + i; } System.out.println(result);
Example int i = 1 result = result + i; i ++ yes i <= 100? no Initialization int i = 1 Loop Body Increment result = result + i; i ++ yes Condition? yes i <= 100? no no
result = result + number; } System.out.println(number); Sum of: 1 + 2 + 3 + 4 + 5 + 6 +……….. + ??? Result more than 1000 int result = 0; int number = 0; while (result < 1000) { number = number + 1; result = result + number; } System.out.println(number);
Compare for (int i = 0; i <= 100; i = i + 1) { result = result + i; } while (result < 1000) { number = number + 1; result = result + number; }
For or While? Compute 25! (factorial) 2. Save $1000 in the bank, interest rate is 3.5%. How many years total = $1800 3. Send messages to your facebook friends automatically