session 2 of programming

14
Pimp UR Knowledge II Intro. To programming using Java SESSION NO.2

Upload: ramy-f-radwan

Post on 22-Jan-2018

187 views

Category:

Software


0 download

TRANSCRIPT

Page 1: Session 2 of programming

Pimp UR Knowledge II

Intro. To programming using Java

SESSION NO.2

Page 2: Session 2 of programming

What Are We Going To Do

• 2.1. Session’s Quiz

• 2.2. Quick Revision

• 2.3. Java tools(If statements and loops)

• 2.4. General Examples

• 2.5. Session’s Quiz

• 2.6. Session’s Report

• 2.7. Questions time

Page 3: Session 2 of programming

QUIZ

• Write a Java program that reads 2 numbers and prints out their sum.

Page 4: Session 2 of programming

Java Tools

If Statements:

• It’s normally as the if statements we use in verbal language:

• If … Condition … Answer of Condition >and> If not … Another Answer

Form:

if(Condition){

Answer Code}

else {

the other Answer Code}

Page 5: Session 2 of programming

Java Tools

Loops:

• Loops are used to repeat a piece of your code several times which could be

user defined or conditioned.

Form:For( int i = start ; i < finish ; i(+or-)=step)

{Code}

Page 6: Session 2 of programming

FINALLY!

Good programming style :

• Use good names for variables and methods

• Add whitespaces

• Don't duplicate tests

Page 7: Session 2 of programming

GENERAL EXAMPLES

Lets Play Java

Page 8: Session 2 of programming

EXAMPLE 1

Make a Java Program to simulate a waiter’s job in a restaurant where the

customer is asked for his desired food and dessert after the waiter tells the

menu. After the customer finishes his order he is told the cost.

Pizza Burger Grilled Fish Chocolate

Cake

Juice Coke

40 17 60 15 10 5

Page 9: Session 2 of programming

EXAMPLE 2

Write a salary program for a company to calculate the salary of the employee

according to the following table

Worker Type Base Salary

For 40

hours/hour

Over time

>40

Over Time

>60

Taxes

Worker 50 *1.5 *2 3%

Engineer 65 *2 *3 5%

Manager 80 *2 *3 7%

CEO 150 _______ ______ 10%

Page 10: Session 2 of programming

EXAMPLE 3

Design a Java Program to draw a Diamond shape using any symbol

Page 11: Session 2 of programming

EXAMPLE 4

• Write a Java Program to print out a sequence which it’s Start, Step,

Kind(Arithmetic or Geometric), End. Are Given to you as an input from the

user.

Page 12: Session 2 of programming

QUIZ

Design a Java Program to find numbers that it’s remainder after division on 3,

4, 5, 6, 7, 8 is 2. And Prints them out.

Design a Java Program that reads a number and prints out the Odd, Even,

Prime numbers till this number separated.

Page 13: Session 2 of programming

REPORT

Design a Java program that reads numbers as an input then puts them in an

array then:

• Sort Them in an ( ascending, descending ) an save both of them in a separate

array.

• Find The Maximum and Minimum Value and it’s Location in the array.

• Give an option to search for a value if available in the array or not if

available show the user the location

Page 14: Session 2 of programming