Write a program that lets the user enter loan amount and loan period in numbers of years and display the monthly and total payments for each interest rate starting from 5% to 8%,with an increment of 1/8. Your program should have at least 2 methods,method for calculation and method to display the output. Suppose u enter the loan amount 10,000 for 5 years

Loan amount 10,000
Number of years: 5

Interest Rate Monthly Payment Total Payment
5% 188.71 11322.74
5.125% 189.28 11357.13


8% 202.76 12165.83

The formula as follows:
Monthly interest rate=Annual interest/1200
Monthly payment=(Loan Amount*Monthly Interest)/(1-(1+monthly interest)^number of years*12)
Total payment=Monthly Payment*number of years*12

The policy here is we don't write programs for people. We can provide suggestions if you get stuck or need help with certain concepts though.

In your case, are you writing a GUI program or a console program? And what part do you need help with?

First of all, i would like to say sorry to the admin because i do not read the policy clear enough. Second, i would like to ask is about the concept of "method" in java, i already wrote the program, but there are still a lot of errors, can u help me to solve the error. Thank you

import java.util.Scanner;
public class question1 {

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        double loanAmt;//loan Amount
        double years;
        double aI;//Annual Interest
        double mi; //monthly interest
        double mp;//monthly payment
        double ai;
        double tp;//total payment
        Scanner input=new Scanner(System.in);
        System.out.print("Please enter the loan Amount");
        loanAmt=input.nextDouble();
        System.out.print("Please enter the number of years");
        years=input.nextDouble();
    }
        public static double mi(double aI ){
            for (aI=5;aI<=8;aI=aI+0.125);
            double mi;
            mi=aI/1200;
        return mi;
        }
        public static double mp (double mi, double loanAmt,double years ){
            double mp; 
            mp = loanAmt * mi / (1 -
                      (Math.pow(1 / (1 + mi), years * 12)));
                    return mi;
        }
        public static double tp (double mp, double years){
            double tp;
            tp=mp*years*12;
            return tp;
        }
        public static void main(double mp,double tp){
        System.out.print("Interest Rate"+"\t"+"Monthly Payment"+"\t"+"Total Payment");


        for (double interestrate=5;interestrate<=8;interestrate=interestrate+0.125);

        System.out.println("\t"+mp+"\t"+tp);




        }




    }

Edited 3 Years Ago by Dani: Formatting fixed

The policy here is we don't write programs for people. We can provide suggestions if you get stuck or need help with certain concepts though.

In your case, are you writing a GUI program or a console program? And what part do you need help with?

First of all, i would like to say sorry to the admin because i do not read the policy clear enough. Second, i would like to ask is about the concept of "method" in java, i already wrote the program, but there are still a lot of errors, can u help me to solve the error. Thank you
import java.util.Scanner;
public class question1 {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
double loanAmt;//loan Amount
double years;
double aI;//Annual Interest
double mi; //monthly interest
double mp;//monthly payment
double ai;
double tp;//total payment
Scanner input=new Scanner(System.in);
System.out.print("Please enter the loan Amount");
loanAmt=input.nextDouble();
System.out.print("Please enter the number of years");
years=input.nextDouble();
}
public static double mi(double aI ){
for (aI=5;aI<=8;aI=aI+0.125);
double mi;
mi=aI/1200;
return mi;
}
public static double mp (double mi, double loanAmt,double years ){
double mp;
mp = loanAmt * mi / (1 -
(Math.pow(1 / (1 + mi), years * 12)));
return mi;
}
public static double tp (double mp, double years){
double tp;
tp=mp*years*12;
return tp;
}
public static void main(double mp,double tp){
System.out.print("Interest Rate"+"\t"+"Monthly Payment"+"\t"+"Total Payment");


for (double interestrate=5;interestrate<=8;interestrate=interestrate+0.125);

System.out.println("\t"+mp+"\t"+tp);


}


}

The formula for Monthly Payment is incorrect.
It should be:
Monthly payment = ((Loan Amount*Monthly Interest)/(1-(1+monthly interest)^(-number of years*12))
The method to calculate the Monthly Payment should thus be:

public static double monthlyPayment (double aI, double loanAmt,int years ){
double mp; 
double mi = aI/1200;
mp = loanAmt * mi / (1 - Math.pow((1+mi), -years * 12));
return mp;
}

First of all, i would like to say sorry to the admin because i do not read the policy clear enough. Second, i would like to ask is about the concept of "method" in java, i already wrote the program, but there are still a lot of errors, can u help me to solve the error. Thank you

import java.util.Scanner;
public class question1 {

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        double loanAmt;//loan Amount
        double years;
        double aI;//Annual Interest
        double mi; //monthly interest
        double mp;//monthly payment
        double ai;
        double tp;//total payment
        Scanner input=new Scanner(System.in);
        System.out.print("Please enter the loan Amount");
        loanAmt=input.nextDouble();
        System.out.print("Please enter the number of years");
        years=input.nextDouble();
    }
        public static double mi(double aI ){
            for (aI=5;aI<=8;aI=aI+0.125);
            double mi;
            mi=aI/1200;
        return mi;
        }
        public static double mp (double mi, double loanAmt,double years ){
            double mp; 
            mp = loanAmt * mi / (1 -
                      (Math.pow(1 / (1 + mi), years * 12)));
                    return mi;
        }
        public static double tp (double mp, double years){
            double tp;
            tp=mp*years*12;
            return tp;
        }
        public static void main(double mp,double tp){
        System.out.print("Interest Rate"+"\t"+"Monthly Payment"+"\t"+"Total Payment");


        for (double interestrate=5;interestrate<=8;interestrate=interestrate+0.125);

        System.out.println("\t"+mp+"\t"+tp);




        }




    }

end quote.

Could you post the specific errors you're getting? That makes it easier to debug your program.

A Java method is essentially a subroutine. It's used for repetitive tasks. For example instead of having to continually write loops to sum all the numbers from 1 to n, you can write a method to do it.

The basic structure is as follows:

[access specifier] [return type] <method name>([parameters]) {
method body
}

For example:

public int sum(int a, int b) {
return a+b;
}

Edited 3 Years Ago by mike_2000_17: Fixed formatting

jackcfj0129,
(1) since you have established the correct method for calculating the monthly payment (public static double monthlyPayment (double aI, double loanAmt,int years )) can you write the code inside the main(String args[]) method to print out the information for the specific case as your professor indicated : loan for 5 years and the Loan Amount of 10,000? You may use a for loop to do 25 loops. The annual interests rate goes up with each increment of 0.125. The output is shown in the following image
(2) transform the main(String args[]) method into a static method for the future new main method to call:
public static void display(int y, double LoanAmount)
(3) Finally write a new main method where the client is asked to type in the information :
(a) loanAmount
(b) how many years for the loan
so that you may call the method: public static void display(int y, double LoanAmount)
to print out necessary information accordingly.

Edited 6 Years Ago by tong1: n/a

Attachments loan.JPG 42.38 KB
This article has been dead for over six months. Start a new discussion instead.