Computers Programming Languages 102 12 102 102 102

  • Slides: 18
Download presentation
Computers & Programming Languages

Computers & Programming Languages

10+2 12 10+2 = 102 10+2 = 12 Twelve

10+2 12 10+2 = 102 10+2 = 12 Twelve

Lesson 4 - Objectives § Identify data types § Identify identifiers § Use identifiers

Lesson 4 - Objectives § Identify data types § Identify identifiers § Use identifiers to name memory cells § Select the appropriate data type

Variables Containers that store data (numbers & letters) in the program. Modern Cars Modern

Variables Containers that store data (numbers & letters) in the program. Modern Cars Modern Calculators

Declaration of Variables Data Type Variable Name ;

Declaration of Variables Data Type Variable Name ;

Data Type Activity 1. 2. 3. 4. 5. ﺃﻨﻮﺍﻉ ﺍﻟﺒﻴﺎﻧﺎﺕ Answer the following questions

Data Type Activity 1. 2. 3. 4. 5. ﺃﻨﻮﺍﻉ ﺍﻟﺒﻴﺎﻧﺎﺕ Answer the following questions What’s your name ? Your Age ? Your weight ? / selected question What is the value of PI ? Are you interested to travel abroad to complete your study ?

Data Type ﺃﻨﻮﺍﻉ ﺍﻟﺒﻴﺎﻧﺎﺕ Primitive Data Types Floating Point integer byte short int long

Data Type ﺃﻨﻮﺍﻉ ﺍﻟﺒﻴﺎﻧﺎﺕ Primitive Data Types Floating Point integer byte short int long float double character Boolean char boolean

Data Type / Integer 6 Data type int is the commonly integer type used

Data Type / Integer 6 Data type int is the commonly integer type used in programming

Data Type / Floating Point 6 Data type double is the commonly floating point

Data Type / Floating Point 6 Data type double is the commonly floating point used in programming Book Activity Page 170

Practical Activity § Open a new java project name (lesson 4 -1) Variable name

Practical Activity § Open a new java project name (lesson 4 -1) Variable name

Variable identifiers (Name) 1. 2. 3. 4. 5. Identifiers consists of A-Z, _ ,

Variable identifiers (Name) 1. 2. 3. 4. 5. Identifiers consists of A-Z, _ , $ , numbers Identifiers should not start with numbers Identifiers are case sensitives Some words should not be used as identifiers : Boolean, byte, class, double, float, public , void …. etc Illegal identifiers ( 123 abc, -salary, @palace Book Activity Page 171

Activity in your book P-172

Activity in your book P-172

Activity in your book P-172 § Find Errors & correct them: Declaration Error Correction

Activity in your book P-172 § Find Errors & correct them: Declaration Error Correction int num 1 Missing ; int num 1; duoble price; double (spelling mistake) double price; Int area; Int (spelling mistake) int area; int double; Reserved word double int d; int 3 age; 3 age int age 3;

Activity / group work § An employee earns a basic salary of 5500 AED,

Activity / group work § An employee earns a basic salary of 5500 AED, transportation 1200 AED, housing allowance 200 AED. Write an algorithm and then create a java program to calculate his total salary. Algorithm 1. Get basic salary, transportation, housing allowance. 2. Find total salary = basic salary + transportation + housing allowance. 3. Print total salary program int num 1, num 2, num 3, total; num 1 = 5500; num 2 = 2000; num 3 = 1200; total = num 1 + num 2 + num 3; System. out. println ( "total =" + total);

Activity in your book P-172 § Create java program that declares two variables which

Activity in your book P-172 § Create java program that declares two variables which represent your grade and average program int grade; double average; grade = 10; average = 90. 5; 5 Minutes System. out. println ( “grade is " + grade); System. out. println ( “average is " + average);

Activity in your book P-172 § Suppose that ahmed bought a new smartphone from

Activity in your book P-172 § Suppose that ahmed bought a new smartphone from an electronics shop and that he got 12. 5% discount on his purchase. Create a java program to declare the variables. program int price; double discount , Total; price= 2500; discount = 0. 125; Total = (price - (price*discount)); 5 Minutes System. out. println ( “Price after dsicount" + Total);