الرئيسية / مقرر تطبيقات الموبايل / الفصل 5 الجزء 1

الفصل 5 (الجزء 1): Java basics: variables and operators

Types, names, values and the operators that work on them

على طول: المتغير نوعه واسمه وقيمته، والعمليات اللي بتشتغل عليه.

فيديو المحاضرة

الفيديو قيد الإعداد

الفيديو قيد الإعداد. في الأثناء اقرأ المحاضرة المكتوبة وجرّب الأمثلة تحت.

رسوم متحركة

المتغير: نوع واسم وقيمة

أمثلة كود

أمثلة قصيرة وبسيطة

كل مثال وراه زرار «شغّل خطوة بخطوة»: بيعلّم على السطر اللي بيتنفّذ ويطبع الناتج زي ما بيتنفّذ بالظبط. ده شرح تنفيذ الكود سطر بسطر، مش مترجم حقيقي جوه الصفحة.

المثال ١: إعلان وطباعة

int age = 25;double salary = 8500.5;String name = "Mona";boolean done = true;System.out.println(age + " " + salary);System.out.println(name + " " + done);

    

المثال ٢: قسمة صحيحة وقسمة كسرية

int a = 7, b = 2;System.out.println(a / b);System.out.println(a % b);System.out.println((double) a / b);

    

المثال ٣: النص كائن

String name = "Mona";System.out.println(name.length());System.out.println(name.toUpperCase());System.out.println(name.equals("Mona"));

    

اختبار قصير

اختبر فهمك

1. Which line declares a decimal number?

2. 7 / 2 in Java with two ints gives:

3. Which operator gives the remainder?

4. Comparing two Strings for the same text should use:

5. A boolean variable holds:

تمارين

جرّب بإيدك

التمرين 1

اعمل متغيرات لعمرك وطولك واسمك واطبعهم في سطر واحد.

Create variables for your age, height and name and print them on one line.

Starter code:

// TODO: three variables and one println

التمرين 2

احسب متوسط تلات درجات 18 و 20 و 15، واطبعه ككسر عشري.

Compute the average of 18, 20 and 15, and print it as a decimal.

Starter code:

int s1 = 18, s2 = 20, s3 = 15;// TODO: average as a double and print it

مشروع صغير في آخر المحاضرة

فاتورة صغيرة بضريبة

الداتا: bill: our own three items with prices (12, 25, 8) and a 14% tax rate.

License / source: Our own numbers; Oracle Java tutorial link only. Reference page

الخطوات

  1. خزّن تمن تلات أصناف في متغيرات int.
  2. اجمعهم في متغير total.
  3. احسب الضريبة 14% كـ double، واجمعها على الإجمالي.
  4. اطبع الإجمالي قبل الضريبة وبعدها. المتوقع تحت.

Starter code:

int pen = 12, book = 25, bag = 8;// TODO: total// TODO: tax = total * 0.14// TODO: print total and total with tax

Credits: the topic order follows the course notes "Mobile Application Development 1" by Dr. Muhammad Kashif Saeed (Applied College, Muhayil, King Khalid University), shared by the course owner. The explanations, diagrams, data and code in this lecture are our own; we copy nothing from the notes. Extra reference: Oracle Java tutorials: variables, operators, expressions and control flow (docs.oracle.com/javase/tutorial).