Search Blog

Biyernes, Enero 18, 2013

The simple interest on a loan is calculated by the formula. interest = principal * rate * days / 365; The preceding formula assumes that rate is the annual interest rate, and therefore includes the division by 365 (days). Develop a program that will input principal, rate and days for several loans, and will calculate and display the simple interest for each loan, using the preceding formula.


Java Codes
--+o0O0o+--

The simple interest on a loan is calculated by the formula.

interest = principal * rate * days / 365;

The preceding formula assumes that rate is the annual interest rate, and therefore includes the division by 365 (days). Develop a program that will input principal, rate and days for several loans, and will calculate and display the simple interest for each loan, using the preceding formula.


Code:


import java.util.Scanner;

public class MachineProblem10 {

    public static void main(String[] args) {
       
        Scanner input_user = new Scanner(System.in);
       
        float principal,rate,interest;
        int loan_days;
       
        System.out.println("*****************************************");
        for(int x = 0;x < 1000;x++)
        { 
           
        System.out.print("  Enter loan principal (-1 to end): ");
            principal = input_user.nextFloat();
           
            if(principal != -1)
            {
                System.out.print("  Enter interest rate: ");
                rate = input_user.nextFloat();
               
          System.out.print("  Enter term of the loan in days: ");
                loan_days = input_user.nextInt();
               
                interest = principal * rate * loan_days / 365;
                System.out.println("*****************************************");
System.out.println("  The interest charge is $" + interest);               System.out.println("*****************************************");
            }
            else
            {
                return;
            }        
            
        }
    }
}

Walang komento:

Mag-post ng isang Komento