Problem 1 တုန်းက ပြောခဲ့တဲ့ Data Types၊ Declare လုပ်တာ စတဲ့ ရေးရမဲ့ ပုံစံတွေကို ပြန်သိဖို့တော့ လိုမယ်။
အခု Problem 2 ကတော့ အရမ်းကြီးမခက်ဘူး။ Python မှာသင်ဖူးတဲ့ {if, else if, else} လိုမျိုးတွေရေးရမယ်။ တစ်နည်းပြောရရင် true or false conditions တွေကို ရေရတာပဲ။ true ဖြစ်ရင် ဘာ ဆက်လုပ်မယ်၊ false ရင်ဘာလုပ်မယ်၊ စတာတွေကို ရေးရမှာပါ။ python နဲ့မတူတာက java မှာ if ကို { } နဲ့ လုပ်တယ်။ ရှင်းအောင်ပြောရရင်..
if {
else if {
}
else {
}
}
else {
}
ဒါကမှ Problem 2 ပါ...
Fit Lions Sports Club is pleased with the Sports Training Calculator that you have developed. Thus they would to add some addition features to the existing Sports Training calculator.
The Sports Training Calculator should use the following table to determine if the athlete is within the guidelines for their selected sport:
VO2Max | |||
Sport | Age | Males | Females |
Basketball | 18-30 | 40-60 | 43-60 |
Bicycling | 18-26 | 62-74 | 47-57 |
Canoeing | 18-26 | 55-67 | 47-67 |
Gymnastics | 18-22 | 52-58 | 36-50 |
Swimming | 10-25 | 50-70 | 40-60 |
Each team needs to complete at least 2 different sports. Can your team help to make the modifications?
အရင်တုန်းကရေးထားတဲ့ ကုဒ်ကို ပြန်သုံးရမယ်နော်.. ဒီမှာပိုသွားတာက if conditions တွေပါလာတာဘဲ။ worksheet ကိုအကုန်လုံးပြန်မရေးတော့ဘူးဗျာ.. အရမ်းများတယ်။ အားလုံးလည်းသိပြီးသားလို့ထင်တယ်။ ချုံ့ပြီးပြောရရင် ၊ ကုဒ်သုံးခုပေးထားတယ်...
Version A, B, C မှာ ဘယ်ဟာက ကောင်းဆုံးလဲ၊ ကျွန်တော်ကတော့ C လို့ ဖြေလိုက်တယ်၊
ပြီးတော့ Multiple Branching အကြောင်းလုပ်ရတယ်။ အဲ့ဒါက if, else if, else ကိုပြောတယ်ဘဲ။
နောက်တစ်ခုက Multiple Conditions အဲ့ဒါကတော့ {or , and} ကိုပြောတာ၊ အသေးစိတ်ကိုတော့ နောက်မှာဆက်ပြောမယ်။ ပြီးတော့ Flowchat တစ်ခုပေးထားတယ် အဲ့ဒါကိုကြည့်ပြီး ကုဒ်ရေးရင်ရပြီ။ flowchart ပေးထားရင် ကုဒ်ရေးရတာ အရမ်းလွယ်သွားပြီလေ...
အပေါ်မှာပြထားတာ ရှင်းရှင်းလေးပဲ.. အရင်ဆုံး true တွေကို if နဲ့ စရေးမယ်။ age, gender, VO2 တွေက မှန်တယ်ဆိုရင် .. Age and VO2 are OK! လို့ ပြလိုက်မယ်။ age and gender က မှန်တယ်၊ VO2 ကမှားမယ်ဆိုရင် VO2 is not within limit လို့ ပြမယ်။ အဲ့လိုပဲ male and female ကိုလည်း ခွဲလိုက်မယ်။ နောင်ဆုံးကတော့ Age ကို မှန်လားမှာလားလို့ခွဲမယ်.. ကျွန်တော်က နောက်ကနေ ပြန်ရေးထားသလို ဖြစ်နေတယ်ထင်တယ်... စာရှင်းပြတာလုံးဝမကောင်းတာကို သည်းခံ ပေးကြပါနော်...
ဒါကတော့ အပေါ်က flowchart အတိုင်းပြန်ရေးထားတာ။ ဒါက game ကိုရွေးရတဲ့အပိုင်း မပါသေးဘူး။ 6P မှာတော့ ပြောသွားတယ်။ မမှတ်မိတော့ဘူး 6P ရမှပဲ ပြောတော့မယ်။ ကျွန်တော်ကတော့ ကိုယ့်နည်းကိုယ့်ဟန်နဲ့ ရေးထားတယ်။ ဘယ်လိုလဲဆိုတော့ နောက်ထက် if condition ထက်ထဲ့လိုက်တယ်၊ မရေးပြတော့ဘူး...
ဒါကတော့ သုံးထားတဲ့ formula ပါ။ ဘာလို့ return ကိုသုံးထားလဲဆိုတာတော့ ပြောဖို့မလိုတော့ဘူးထင်တယ်...
Notes :
return ဆိုတာ formula ကို ပြန်သုံးချင်လို့။ loop လုပ်တဲ့အခါ formula ကို တစ်ခါဘဲရေးပြီး ပြန်သုံးတာ။
if {
} ပြီးရင် ; မလိုဘူး
Int ဆိုရင် = or == သုံးလို့ရတယ်
String ကိုဆိုရင်တော့ .equals(), compareTo(), and compare() ကိုသုံးတယ်..read more
equal() ကို capital or small letter မခွဲချင်ဘူးဆိုရင် equalsIgnoreCase ကိုသုံးတယ်။
နောက်ဆုံးပြောရရင်တော့ ဒီ Problem မှာ {if, else if, else} ကိုကောင်းကောင်းသုံးတတ်ရမယ်။ {&& and ||} ကို နားလည်ရမယ်။ ဂွင်း{ } တွေကိုနေရာမှန်အောင်ထားတတ်ရမယ်။ ကျွန်တော်ကတော့ တခါတည်း ဂွင်းစရော"{" ဂွင်းပိတ်ရော"}" တန်းရေးတယ်။ ပြီးရင် Ctrl + Shift + F လုပ်ပြီး ညီအောင်ပြန်စီတယ်။ ဒါမှကြည့်လို့ကောင်းပြီး ရှင်းနေမယ်... condition ကို ";" မလိုဘူး၊ ( ) ဆိုရပြီ။ statement ပြီးရင်တော့ ";"ရေးပေးရတယ်...
ဆက်ပါအုံးမည်....
public class UsingMethod { public void versionA() {
double area1 = 3.142 * 3.0 * 3.0;
double area2 = 3.142 * 3.5 * 3.5;
double area3 = 3.142 * 4.0 * 4.0;
System.out.println("Area of circle 1 is " + area1);
System.out.println("Area of circle 2 is " + area2);
System.out.println("Area of circle 3 is " + area3);
}
public void versionB() {
double area1 = areaOfCirle(3.0);
double area2 = areaOfCirle(3.5);
double area3 = areaOfCirle(4.0);
System.out.println("Area of circle 1 is " + area1);
System.out.println("Area of circle 2 is " + area2);
System.out.println("Area of circle 3 is " + area3);
}
public void versionC() {
System.out.println("Area of circle 1 is " + areaOfCirle(3.0));
System.out.println("Area of circle 2 is " + areaOfCirle(3.5));
System.out.println("Area of circle 3 is " + areaOfCirle(4.0));
}
private double areaOfCirle(double radius) {
double area = 3.142 * radius * radius;
return area;
}
}
Version A, B, C မှာ ဘယ်ဟာက ကောင်းဆုံးလဲ၊ ကျွန်တော်ကတော့ C လို့ ဖြေလိုက်တယ်၊
ပြီးတော့ Multiple Branching အကြောင်းလုပ်ရတယ်။ အဲ့ဒါက if, else if, else ကိုပြောတယ်ဘဲ။
နောက်တစ်ခုက Multiple Conditions အဲ့ဒါကတော့ {or , and} ကိုပြောတာ၊ အသေးစိတ်ကိုတော့ နောက်မှာဆက်ပြောမယ်။ ပြီးတော့ Flowchat တစ်ခုပေးထားတယ် အဲ့ဒါကိုကြည့်ပြီး ကုဒ်ရေးရင်ရပြီ။ flowchart ပေးထားရင် ကုဒ်ရေးရတာ အရမ်းလွယ်သွားပြီလေ...
အပေါ်မှာပြထားတာ ရှင်းရှင်းလေးပဲ.. အရင်ဆုံး true တွေကို if နဲ့ စရေးမယ်။ age, gender, VO2 တွေက မှန်တယ်ဆိုရင် .. Age and VO2 are OK! လို့ ပြလိုက်မယ်။ age and gender က မှန်တယ်၊ VO2 ကမှားမယ်ဆိုရင် VO2 is not within limit လို့ ပြမယ်။ အဲ့လိုပဲ male and female ကိုလည်း ခွဲလိုက်မယ်။ နောင်ဆုံးကတော့ Age ကို မှန်လားမှာလားလို့ခွဲမယ်.. ကျွန်တော်က နောက်ကနေ ပြန်ရေးထားသလို ဖြစ်နေတယ်ထင်တယ်... စာရှင်းပြတာလုံးဝမကောင်းတာကို သည်းခံ ပေးကြပါနော်...
if (age >= 18 && age <= 22) { if (gender.equalsIgnoreCase("male")) { if (v02Max >= 52 && v02Max <= 58) { System.out.println("Your Age and VO2 are Ok!"); } else { System.out.println("VO2 is not within limit"); } } else if (gender.equalsIgnoreCase("female")) { if (v02Max >= 36 && v02Max <= 50) { System.out .println("Your Age and VO2 are Ok!"); } else { System.out .println("You are not qualified to play Game"); } } } else { System.out.println("You are Under Age!"); }
ဒါကတော့ အပေါ်က flowchart အတိုင်းပြန်ရေးထားတာ။ ဒါက game ကိုရွေးရတဲ့အပိုင်း မပါသေးဘူး။ 6P မှာတော့ ပြောသွားတယ်။ မမှတ်မိတော့ဘူး 6P ရမှပဲ ပြောတော့မယ်။ ကျွန်တော်ကတော့ ကိုယ့်နည်းကိုယ့်ဟန်နဲ့ ရေးထားတယ်။ ဘယ်လိုလဲဆိုတော့ နောက်ထက် if condition ထက်ထဲ့လိုက်တယ်၊ မရေးပြတော့ဘူး...
// Using Method (formulae)
private double calcV02Max(int restingHeartRate, int maxHeartRate) {
return 15.0 * maxHeartRate / restingHeartRate;
}
private double calcTrgHeartRate(int maxHeartRate) {
return 0.8 * maxHeartRate;
}
private int calcMaxHeartRate(int age) {
return 220 - age;
}
ဒါကတော့ သုံးထားတဲ့ formula ပါ။ ဘာလို့ return ကိုသုံးထားလဲဆိုတာတော့ ပြောဖို့မလိုတော့ဘူးထင်တယ်...
Notes :
return ဆိုတာ formula ကို ပြန်သုံးချင်လို့။ loop လုပ်တဲ့အခါ formula ကို တစ်ခါဘဲရေးပြီး ပြန်သုံးတာ။
if {
} ပြီးရင် ; မလိုဘူး
if ( <conditions> ) {
statements;
…
}
နောက်တစ်ခုက Int ဆိုရင် = or == သုံးလို့ရတယ်
String ကိုဆိုရင်တော့ .equals(), compareTo(), and compare() ကိုသုံးတယ်..read more
equal() ကို capital or small letter မခွဲချင်ဘူးဆိုရင် equalsIgnoreCase ကိုသုံးတယ်။
နောက်ဆုံးပြောရရင်တော့ ဒီ Problem မှာ {if, else if, else} ကိုကောင်းကောင်းသုံးတတ်ရမယ်။ {&& and ||} ကို နားလည်ရမယ်။ ဂွင်း{ } တွေကိုနေရာမှန်အောင်ထားတတ်ရမယ်။ ကျွန်တော်ကတော့ တခါတည်း ဂွင်းစရော"{" ဂွင်းပိတ်ရော"}" တန်းရေးတယ်။ ပြီးရင် Ctrl + Shift + F လုပ်ပြီး ညီအောင်ပြန်စီတယ်။ ဒါမှကြည့်လို့ကောင်းပြီး ရှင်းနေမယ်... condition ကို ";" မလိုဘူး၊ ( ) ဆိုရပြီ။ statement ပြီးရင်တော့ ";"ရေးပေးရတယ်...
ဆက်ပါအုံးမည်....
0 comments:
Post a Comment