Class & Constructor


Submit solution

Points: 50 (partial)
Time limit: 1.0s
Memory limit: 256M

Authors:
Problem types

題目說明

根據主程式需求,定義Bank類別的程式碼

本利和 = 本金 * (1+月利率)^期數

請完成註解TODO部分,使程式符合題目要求。
⚠️ 請依照程式模板進行撰寫,若人工檢查時發現結構變更將無法得分。

import java.util.Scanner;

class Bank {

private double principal; // 存款本金不可讓外部直接存取,設定成private
public double monthlyIR; //月利率
public int period;//期數

    public Bank(...){

        //TODO:建構Bank物件(參考試算表250)

    }


    //TODO:建立calculate方法,使用參數執行本利和計算


}

public class MyProgram {

    public static void main(String[] args) {

        Scanner input = new Scanner(System.in);
        double mIR = input.nextDouble();    // 月利率
        double p = input.nextDouble();      // 本金
        int t = input.nextInt();            // 期數

        // TODO:宣告Bank物件,傳遞月利率、本金、期數
        // TODO:呼叫Bank物件方法(計算本利和),並顯示計算後的結果

    }

}

輸入

月利率 本金 期數

輸出

計算出的本利和(四捨五入到整數)

測試資料1 輸入

0.01 1000 5

測試資料1 輸出

1051
本利和 = 1000 * (1+0.01)^5 = 1051.010,四捨五入到整數=1051

Comments

There are no comments at the moment.