Object-Oriented Programming Problem 3

မ​အား​တာ​နဲ့ တော်တော်​တောင် ကြာ​သွား​တယ်.. ပြီး​တော့ Problem 3 ကို အရမ်း​ကြီး​နား​မ​လည်​လို့ နဲ​နဲ စာပြန်​ဖတ်​ပြီး​မှ ဒီ Post ကို​တင်​နိုင်​တယ်.. ဖတ်​ပြီး​သွား​တော့ နားလည်​သ​လိုလို​တော့​ရှိ​သွား​တယ်.. ကဲ စ​ပြီး​ရေး​တော့​မယ်နော်.. ဘာ​ပြဿနာ​လဲ မ​ပြော​ခင် ဘာ​အကြောင်းအရာ​တွေ ပါ​လဲဆို​တာ အရင်​ပြော​မယ်။ ပထမ​ဆုံး​ကတော့ while loop ၊ ပြီး​တော့ Arrays ၊ နောက်ဆုံး​တစ်​ခု​ကတော့ For loop ။ အရင်​တုန်း​က Python သင်​ဖူး​ရင် နားလည်​ဖို့ ပို​လ​ပို​လွယ်​တယ်။ သဘော​တရား​က တူ⁠တူ​ပဲ​လေ..

Problem Statement ကတော့ အောက်​မှာ​ဖတ်​ကြည့်​လိုက်​တော့...



Andrew works part-time as a sales promoter and earns $1000 every month. Besides keeping records of his salary slips, he also kept his expense receipts last year. As he plans to better control his expenditure this year, he would like to know how much he spent and saved in 2009.

Help Andrew by building a simple application in Java to achieve his goal. The application should do the following:

(1) In the beginning of each month, the application puts $1000 into Andrew's bank balance.

(2) The application should ask Andrew to enter how much he spent in total for that month.

(3) When all the needed data is entered, the application:
a. Displays the expenditure for each month.
b. Calculates the total amount of money that Andrew spent for the year.
c. Calculates the monthly average amount of money that Andrew spent.
d. Calculates the balance of money left in his savings.

* Note - at any point in time, Andrew should not be able to spend more money than what he has saved so far. If Andrew enters a value larger than what he currently has in the bank, he should be asked to enter again.

Advanced Features

(4) The application should also take into account the interest rate of the bank (e.g. 1% per month). For this problem, we will assume that the bank pays compound monthly interest for Andrew’s savings.

ဖတ်​ပြီး​ပြီ​ဆို​ရင်​တော့ ဘာ​လုပ်​ရ​မ​လဲ သိ​ပြီ​ထင်​တယ်... 

ကုဒ်​စ​ရေး​တော့​မယ် အောက်​ဆုံး​မှ​ဘဲ ရေးထား​တဲ့ ကုဒ်​တွေ​ကို​ပြန်​ရှင်း​တော့​မယ်။
    public void start() {
        double[] spending = new double[12];
        double total = 0;
        double balance = 0;
        for (int i = 0; i < 12; i++) {
            balance = balance + 1000;
            spending[i] = Keyboard.readInt("How much did you spent for Month "
                    + (i + 1) + " : ");
            while (balance < spending[i]) {
                System.out
                        .println("*** Your are spending more than your balance ***");
                spending[i] = Keyboard
                        .readInt("How much did you spent for Month " + (i + 1)
                                + " : ");
            }

            balance = balance - spending[i];
            total = total + spending[i];

        }
        for (int i = 0; i < 12; i++) {
            System.out.println("Spending for Month" + (i + 1) + " is "
                    + spending[i]);

            System.out.println("Total saving is " +balance);
            System.out.println("Total Spending >>" + total);
            System.out.println("Average Spending >> " + (total / 12));
        }
        System.out.println("End of Program");

    }

double[] spending = new double[12];
ဆိုတာက Arrays တစ်ခုလုပ်လိုက်တာ။ ဘယ်လောက်လုပ်မှာလဲဆိုတော့ ၁၂ခုထဲ့ထာမယ်ဆိုတော့ [12]။
 for (int i = 0; i < 12; i++){}
ကတော့ သိရမှာ ၃ခုရှိတယ်။ int i=0; ဆိုတာကတော့ ဘယ်ကစမှာလဲ ကိုပြောတာ။ i<12; ဆိုတာကတော့ ဘယ်မှာဆုံးမယ်ဆိုတာကို ပြောတာ။ နောက်ဆုံးတစ်ခုကတော့ i++ or i=i+1; ကတော့ ဘယ်လောက်တိုးပြီးသွားမလဲဆိုတာကိုပြောတာပါ။ ဒီ loop မှာဆိုရင် arrays မှာ ၁၂ index ရှိပါတယ်။ ၀ ကနေစပြီးတော့ ၁၁ အထိပေါ့။
 balance = balance + 1000;
balance ကို ၁၀၀၀ ရှိတယ်လို့ပြောချင်တာ


spending[i] = Keyboard.readInt("How much did you spent for Month " + (i + 1) + " : ");
ဒါကတော့ spending arrays ကို input လုပ်တာပါ။ (i+1)ဆိုတာကတော့ ပထမ ဆုံးကို ၁ ဖြစ်အောင်လုပ်လိုက်တာပါ။ ပုံမှန်ဆိုရင်တော့ i က 0 ဖြစ်နေတာပါ။
while (balance < spending[i]) {}
while နဲ့ for ကသဘောတရားကတူတူပါပဲ။ အစတွေ၊ အဆုံးတွေ၊ စတဲ့ condition တွေမသိဘူးဆိုရင် while ကိုပိုသုံးပါတယ်။ 

နောက်ဆုံးသိရမှာကတော့ ဒီအခန်းဟာ တော်တော်အရေးပါတဲ့ အခန်းဖြစ်ပါတယ်။ for loop, while loop, arrays စတာတွေမသိဘူး နားမလည်ဘူးဆိုရင်တော့ နောက်ပိုင်းအခန်းတွေဆိုပိုဆိုးသွားနိုင်ပါတယ်။ အဲ့တော့ နောက်တစ်ခေါက်လောက် ပြန်ကြည့်ရင်ပိုကောင်းမယ်။ ကျွန်တော်က ရှင်းတာမကောင်းလို့သေသေချာချာ မရှင်းပြနိုင်တာ ခွင့်လွတ်ပေးပါလို့ တောင်းပန်ပါတယ်။ မှားတာရှိရင်လည်း ပြောခဲ့ကြပါ။
ဆက်ပါအုံးမယ်... နောက်တစ်ပတ်တော့ လေ့ကျင့်ခန်းလေးတွေပါ လုပ်ကြည့်မယ်နော်... 

0 comments:

Post a Comment