import java.util.Scanner;

public class Revision {

    public static void main(String[] args) {
//        The first question.
        Scanner s = new Scanner(System.in);
        String fullname, acc;
        int usage;
        double payment;
        System.out.print("Enter Full Name:");
        fullname = s.nextLine();
        System.out.print("Enter Account Number:");
        acc = s.nextLine();
        System.out.print("Enter Total Usage(kWh):");
        usage = s.nextInt();

        if (usage > 400){
            payment = (usage - 400)*0.416 + 100 * 0.4 + 100*0.334 +200*0.218;
        }else if (usage>300){
            payment = (usage - 300)*0.4 + 100*0.334 + 200*0.218;
        }else if (usage>300){
            payment = (usage - 200)*0.334 + 200*0.218;
        }else{
            payment = usage * 0.218;
        }
        if (payment < 3){
            payment = 3;
        }

        System.out.println("Full Name: " + fullname + "\nAccount:" + acc);
        System.out.println("Total Usage:" + usage);
        System.out.printf("Total Payment: RM %.2f\n", payment);

//        The third question
        double deposit, rate;
        int month;
        System.out.print("Enter deposit amoount (RM) : ");
        deposit = s.nextDouble();
        System.out.print("Enter number of months : ");
        month = s.nextInt();
        System.out.print("Enter annual interest rate (%) : ");
        rate = s.nextDouble();
        System.out.printf("%-10s%-15s%-15s%-20s\n","Month", "Principal (p)", "Interest (r)", "Interest r/1200*p");
        double interest, p, total=0;
        p = deposit;
        for (int i=1; i<=month; i++,rate+=0.12){
            interest = p*rate / 1200;
            total +=interest;
            System.out.printf("%-10d%-15.2f%-15.2f%-20.2f\n",i, p, rate, interest);
            p += interest;
        }
        System.out.printf("Total interest (RM) : %.2f" ,total);

//s.next().charAt(0)

    }
}

发表评论