ခဏလေး ဒီလိုပဲ စဉ်းစားကြည့်
ဒီ lesson က အသစ်ဘာမှ မသင်ပါဘူး၊ Basic chapter မှာ သင်ခဲ့တဲ့ variables, datatypes, operators, functions, if-else, loops, lists, maps တွေကို ပြန်လှန်ပြီး လက်တွေ့ ကိုယ်တိုင် code ရေးကြည့်ရမယ့် practice session ပါ။ Concept တစ်ခုချင်းကို သီးခြားစီ မကျင့်ဘဲ တွဲသုံးနိုင်အောင် exercises တွေကို ရောပြီးထားပါတယ်။ ဒီလို ပေါင်းသုံးတဲ့အခါ real-world logic ကို ဘယ်လို ချရေးရမလဲဆိုတာ ပိုနားလည်လာမှာပါ။ Code ကို run ပြီးမှ output ကို ကြိုတွက်ကြည့်တဲ့ အလေ့အကျင့်ကို ဦးစားပေးပါ။
လေ့ကျင့်ခန်းများ
Task 1: `int`, `double`, `String`, `bool` type လေးမျိုးကို variable declare လုပ်ပြီး string interpolation သုံးပြီး တစ်ကြောင်းတည်း sentence တစ်ခု print ပါ။ Task 2: `celsiusToFahrenheit(double c)` ဆိုတဲ့ function ရေးပြီး formula `(c * 9/5) + 32` သုံးပြီး temperature ပြောင်းပါ။ Task 3: `for` loop သုံးပြီး 1 ကနေ 20 ထိ ရှိတဲ့ number တွေထဲက even number တွေကိုပဲ list တစ်ခုထဲ ထည့်ပါ။ Task 4: student name ကို key, score ကို value အဖြစ် `Map<String, int>` တစ်ခုဆောက်ပြီး score 50 အောက်ဆို "Fail", 50 ကနေအထက်ဆို "Pass" ဆိုပြီး `if-else` နဲ့ loop တွဲသုံးပြီး စစ်ပါ။
Code နမူနာ
// Task 1 skeleton
void main() {
int age = 0; // TODO
double height = 0.0; // TODO
String name = ''; // TODO
bool isStudent = true; // TODO
print('$name is $age years old.');
// Task 2
print(celsiusToFahrenheit(30));
// Task 3
List<int> evens = [];
// TODO: fill evens with even numbers from 1 to 20
print(evens);
// Task 4
Map<String, int> scores = {
'Aung': 45,
'Su': 78,
'Mya': 60,
};
// TODO: loop through scores and print Pass/Fail
}
double celsiusToFahrenheit(double c) {
// TODO
return 0.0;
}Console မှာ student name/age sentence, converted temperature, even number list, ပြီးတော့ student တစ်ယောက်စီအတွက် Pass/Fail status တွေ print ထွက်လာရမှာဖြစ်ပါတယ်။၅ မိနစ် စမ်းကြည့်
Timer 5 မိနစ်ထားပြီး skeleton code ကို မကြည့်ဘဲ scratch ကနေ Task 2 (temperature converter) တစ်ခုတည်းကို ကိုယ်တိုင် ပြန်ရေးကြည့်ပါ။
သတိလေးတစ်ချက်
Task တွေကို IDE autocomplete မသုံးဘဲ လက်နဲ့ ရိုက်ကြည့်ပါ၊ syntax mistake တွေကို ကိုယ်တိုင်တွေ့ရင် ပိုမှတ်မိပါလိမ့်မယ်။