37
STARTUP DIVKOM DAY 2 IPUNG HAVIDZ WIDJAJA / 18112023

STARTUP DIVKOM DAY 2 IPUNG HAVIDZ WIDJAJA / 18112023

Embed Size (px)

Citation preview

Page 1: STARTUP DIVKOM DAY 2 IPUNG HAVIDZ WIDJAJA / 18112023

STARTUP DIVKOM DAY 2

IPUNG HAVIDZ WIDJAJA / 18112023

Page 2: STARTUP DIVKOM DAY 2 IPUNG HAVIDZ WIDJAJA / 18112023

PROGRAMMING

Welcome to day 2 startup divkom 2014

Today we will learn about programming

We will focus on java programming

Page 3: STARTUP DIVKOM DAY 2 IPUNG HAVIDZ WIDJAJA / 18112023

WHY JAVA?

There are several reasons why we only focus on java programming : 1. most of programming method now focus on object oriented programming (OOP)

2. Most of Divkom’s project in programming is about developing android program 3. Java will be the foundational structure of all Android app/game development that we will cover (at least in the predictable future)

Page 4: STARTUP DIVKOM DAY 2 IPUNG HAVIDZ WIDJAJA / 18112023

“WHAT THE….WHAT IS OOP?”  A method of programming based on a hierarchy of classes, and well-defined and cooperating objects.

KEY POINTS : State and Behavior

Imagine an object. This can be anything, such as a dog, a bag, a bottle, a car, or any other conceivable (or sometimes inconceivable!) THING.

Think about what each dog, or each bag, or each bottle, or each car has in common. They can DO things, and they can also have special quirks to them.

Dogs bark, chase cats, scratch themselves, and sleep. They can be timid, quiet, loud, excitable, of any number of colors, big, small. Cars can move, can stop, can contain passengers, can go fast, or slow.

Object oriented programming is a way to describe what a thing IS and what it can DO.

Page 5: STARTUP DIVKOM DAY 2 IPUNG HAVIDZ WIDJAJA / 18112023

“SO, WHY DO WE USE OOP?” The process of designing and programming objects seems very cumbersome, why bother?

It’s difficult to see from such a small example, but for larger projects, OOP techniques allow a great deal of flexibility.

OOP will make your work EASIER!

Page 6: STARTUP DIVKOM DAY 2 IPUNG HAVIDZ WIDJAJA / 18112023

“THEN, HOW DO WE OOP?”

Page 7: STARTUP DIVKOM DAY 2 IPUNG HAVIDZ WIDJAJA / 18112023

JOB TO DO

1. prepare your android developer tools (ADT) Bundle eclipse

2. file new java project (give a proper name on your project]

3. expand your project. On src, right click and choose new Classes

4. name your class file. For example : HelloWorld

Page 8: STARTUP DIVKOM DAY 2 IPUNG HAVIDZ WIDJAJA / 18112023

Result :

Page 9: STARTUP DIVKOM DAY 2 IPUNG HAVIDZ WIDJAJA / 18112023

ABOUT JAVA SYNTAX

A. Variables in java Example : integer, Boolean, float, string, char, etc… Variables may be a global/local variables (what’s the difference?]

Global : You can use it in any method/class on your java project Local : you can only use it in specific method/class

Page 10: STARTUP DIVKOM DAY 2 IPUNG HAVIDZ WIDJAJA / 18112023

MORE ABOUT VARIABLES…..

1. Instance variable Declared without ‘static’ example : int number Has unique values depending on each instance that they belong to

2. Class variable Declared with ‘static’ example : static int number = 10 There will be a single copy of this variable

Page 11: STARTUP DIVKOM DAY 2 IPUNG HAVIDZ WIDJAJA / 18112023

LET’S TRY THIS!Result :

Page 12: STARTUP DIVKOM DAY 2 IPUNG HAVIDZ WIDJAJA / 18112023

ANALYZING THE SYNTAX….

1. the first result will be 11 because total is the value of class/global variable ‘eight’ is added to local variable ‘number’, which means 8+3 = 11.

2. the second result will be 16 because total is the value of class/global variable ‘eight’ s added to class/global variable ‘number’, which means 8+8 = 16.

Page 13: STARTUP DIVKOM DAY 2 IPUNG HAVIDZ WIDJAJA / 18112023

B. Basic operation There are several basic math operations on java :

+ : addition - : Substraction / : Division * : Multiplication % : mod operation (returns the value of remainder]

Page 14: STARTUP DIVKOM DAY 2 IPUNG HAVIDZ WIDJAJA / 18112023

LET’S TRY THIS! (2)Result :

Page 15: STARTUP DIVKOM DAY 2 IPUNG HAVIDZ WIDJAJA / 18112023

C. Increment and Decrement Another math operation in java is increment and decrement :

1. increment : increase the value of a variable with a specific value 2. decrement : decrease the value of a variable with a specific value

For example in java syntax counter++ (adds one to counter variable], counter+=3 [adds 3 to counter variable]

If there is an exact value before increment/decrement, the previous value will be added/substracted.

Page 16: STARTUP DIVKOM DAY 2 IPUNG HAVIDZ WIDJAJA / 18112023

MORE ABOUT INCREMENT/DECREMENT There are two types of increment/decrement in java syntax : 1. Pre-increment/decrement : the value is added/substracted first before being executed

2.Post-increment/decrement : The value is executed first before being added/substracted

Page 17: STARTUP DIVKOM DAY 2 IPUNG HAVIDZ WIDJAJA / 18112023

LET’S TRY THIS! [3]Result:

Page 18: STARTUP DIVKOM DAY 2 IPUNG HAVIDZ WIDJAJA / 18112023

D. conditional (if-else] In java, there is also if-else statement, like other programming languages. It is about comparison between two/more variables Operator used :

== equals to != doesn’t equal to >= more than equal <= less than equal > more than < less than && logical operator ‘and’ || logical operator ‘or’

Page 19: STARTUP DIVKOM DAY 2 IPUNG HAVIDZ WIDJAJA / 18112023

LET’S TRY THIS! [4]Result :

Page 20: STARTUP DIVKOM DAY 2 IPUNG HAVIDZ WIDJAJA / 18112023

D. switch method It’s like if-else statement, but more general Assign an output depends on statement

Page 21: STARTUP DIVKOM DAY 2 IPUNG HAVIDZ WIDJAJA / 18112023

Result :

Page 22: STARTUP DIVKOM DAY 2 IPUNG HAVIDZ WIDJAJA / 18112023

E. looping techniques There are several methods to do looping techs :

1. while-do 2. do-while 3.for

Page 23: STARTUP DIVKOM DAY 2 IPUNG HAVIDZ WIDJAJA / 18112023

MORE ABOUT LOOPING

Result :

RESULT :

Page 24: STARTUP DIVKOM DAY 2 IPUNG HAVIDZ WIDJAJA / 18112023

Result :

Page 25: STARTUP DIVKOM DAY 2 IPUNG HAVIDZ WIDJAJA / 18112023

F. randomization For several programs, we need randomization (for example, about number which will come from a rolled dice]

Declaration

Page 26: STARTUP DIVKOM DAY 2 IPUNG HAVIDZ WIDJAJA / 18112023

There will be an error before executing (OMG Hello! Why???]

The answer is : you need to import a library

How to import a library CTRL+SHIFT+O

Page 27: STARTUP DIVKOM DAY 2 IPUNG HAVIDZ WIDJAJA / 18112023
Page 28: STARTUP DIVKOM DAY 2 IPUNG HAVIDZ WIDJAJA / 18112023

PRINTF/SCANF

Remember about printf/scanf on C programming language?

In java, there are several ways to express those operation

We use ‘system.out.println(“ “) ‘ to print some text on monitor, as we have used before

We use ‘scanner.input = new scanner(system.in)’ to scan the input from keyboard

Of course we need to import a library use CTRL+SHIFT+O

This method is used for a string input, so the data type must be string

How about integer input? See the next slide

Page 29: STARTUP DIVKOM DAY 2 IPUNG HAVIDZ WIDJAJA / 18112023

Result :

Page 30: STARTUP DIVKOM DAY 2 IPUNG HAVIDZ WIDJAJA / 18112023

TIPS AND TRICK

You see that your syntax is not good enough! (read : not tidy ) Use CTRL+SHIFT+F to make your syntax looks beautiful

if you want to type your syntax faster, try CTRL+SPACE

Page 31: STARTUP DIVKOM DAY 2 IPUNG HAVIDZ WIDJAJA / 18112023

SUMMARY

You have known what oop is

You have known why we use oop and java

You have known about some basic java languages

You have known about some basic math operations

You have known about increment/decrement

You have know about variables

You have known about conditional (if-else), switch-case

You have known about looping techniques

You have known about randomization

You have known about printing and scanning

Several tips and tricks given

Page 32: STARTUP DIVKOM DAY 2 IPUNG HAVIDZ WIDJAJA / 18112023

ANY QUESTION?

Page 33: STARTUP DIVKOM DAY 2 IPUNG HAVIDZ WIDJAJA / 18112023

HOMEWORKS!

“omg hello why homeworks??”

Practice makes perfect

Your homeworks (individually, choose one only )

Page 34: STARTUP DIVKOM DAY 2 IPUNG HAVIDZ WIDJAJA / 18112023

YOUR HOMEWORKS

1. ‘Equal Game!’ Create a simple equal game that is played by 2 players (You and Computer). This game is adopted from ‘Cepe’ Game in Indonesia, but much different. How this work? The specification below will explain all of this : First, a number shown from a random process. For example, the first number shown is 4. It is the

initial total. You will be the first player to draw a card also from a random process. It is represented as number. You will be given a decision whether you want to add/substract your number to/from the first number

shown. Now the total depends on your decision. Computer will draw a card from a random process (represented as number too). The opponent will

add/substract depends on total. In this case, if total <= 45, computer will always add the number. Now, the total is changed (added/substracted by computer’s choice)

If the total is 50 after you add your number, you win. If the total is 50 after opponent adds his number, you lose. The total may be less/more than 50 If the total is negative, the game ends immediately.

Page 35: STARTUP DIVKOM DAY 2 IPUNG HAVIDZ WIDJAJA / 18112023
Page 36: STARTUP DIVKOM DAY 2 IPUNG HAVIDZ WIDJAJA / 18112023

2. Too hard? You can submit your own PROGRAM! The specification is : you need to use all of the basic syntax in Java you have learnt today.

The program must at least use 2 procedures/function to be called in main program

Create the program effectively and efficiently!

Submit your program to : E-mail : [email protected] dengan subject : Tugas2_Nama_NIMDeadline : Saturday, November 8 2014 (11.59 PM)File to be sent : java format file. (xxx.java) or the whole package you’ve made!

Page 37: STARTUP DIVKOM DAY 2 IPUNG HAVIDZ WIDJAJA / 18112023

THANK YOU FOR YOUR ATTENTION!