//import classes
import java.io.*;
import java.lang.*;
import java.text.*;

//Class Header
public class Mortgage3
{
    //Public method header
    public Mortgage3()
    {
    }

    //Get user input
    public double loanAmt() throws IOException
    {

        //Declare Method Variables
        double PrincipalIn = 0;
        String answer;
        boolean done = false;
        BufferedReader dataIn = new BufferedReader(new InputStreamReader(System.in));


        //Loop until done
                    System.out.println();
            System.out.print("\t\t\tPlease Enter the Loan Amount:$");
            answer = dataIn.readLine();
            PrincipalIn = Double.parseDouble(answer);

        try
        {
            if(PrincipalIn <= 0) throw new NumberFormatException();

            else done = true;
        }

            catch(NumberFormatException nfe)
            {
                System.out.println("\t\t\tYou Have Entered An Invalid Response.");
                System.out.println();
            }

        return PrincipalIn;
    }

        //Get user input for interest rate
        public float loanRate() throws IOException
        {
            //Declare method variables
            float InterestIn = 0;
            String InterestAnswer;
            boolean done = false;
            BufferedReader dataIn = new BufferedReader(new InputStreamReader(System.in));
            DecimalFormat monetary = new DecimalFormat("#,###0.00");

            //loop until done

                System.out.println();
                System.out.print("\t\t\tPlease Enter Interest Rate %:");
                InterestAnswer = dataIn.readLine();
                InterestIn = Float.parseFloat(InterestAnswer);

                //System.out.println("\t\t\tThe Interest Rate of Your Loan Is %" + percentage.format(InterstIn));

                try
                {
                    if(InterestIn <=0) throw new NumberFormatException();

                    else done = true;
                }

                catch(NumberFormatException nfe)
                {
                    System.out.println("\t\t\tYou Have Entered An Invalid Reponse.");
                    System.out.println();
                }


            return InterestIn;
    }

    //get user input for Term
    public double loanTerm() throws IOException
    {
        //Declare mehtod Variables
        double TermIn = 0;
        String TermAnswer;
        boolean done = false;
System.out.println("Please Enter the Term of the Loan in Months:");
        BufferedReader dataIn = new BufferedReader(new InputStreamReader(System.in));

        //loop until done


                TermAnswer = dataIn.readLine();
                TermIn = Double.parseDouble(TermAnswer);
            try
            {
                if(TermIn <= 0) throw new NumberFormatException();
                else done = true;
            }
            catch(NumberFormatException nfe)
            {
                System.out.println("\t\t\tYou Have Entered An Invalid Response.");
                System.out.println();
            }

        return TermIn;
    }
        //Calculation of Monthly Mortgage Payment
        public double CalcAmt(float loanRate, double loanTerm, double loanAmt)
        {
            double NP, PV;
            float IR;
            NP = loanTerm/12;
            IR = loanRate/100/12;
            PV = loanAmt;

        //Calculation Formula for the Loan
        return (PV * IR) / (1 - Math.pow(1 + IR, - NP));
        }

    }

Edited 3 Years Ago by Reverend Jim: Fixed formatting

I'm not about to read through code that is not posted properly (ie. Use Code Tags). Also what problem are you having? It will be easier for people to provide assistance if you indicate what is happening and what you expect.

Hello can u just tell what all errors your are getting so that we can help you and please use code tag for posting your code.

This is the error.

java.lang.NoSuchMethodError: main
Exception in thread "main" Exit code: 1
There were errors

Sorry about the code tags, how do I do that?

just use ' your code....... //' note: without '


i dont see any main method..im also new in java.

Edited 6 Years Ago by ubi_ct83: n/a

ubi_ct83 is correct. There is no main method, and any runnable java code requries it. Add this into your code:

public static void main(String[] args)
{
     //your main code goes here
}

you have not created main in your program.i think this is the code which you may need.

//import classes
import java.io.*;
import java.lang.*;
import java.text.*;

//Class Header
public class Mortgage3
{
//Public method header
public Mortgage3()
{
}

//Get user input
public double loanAmt() throws IOException
{

//Declare Method Variables
double PrincipalIn = 0;
String answer;
boolean done = false;
BufferedReader dataIn = new BufferedReader(new InputStreamReader(System.in));


//Loop until done
System.out.println();
System.out.print("\t\t\tPlease Enter the Loan Amount == ");
answer = dataIn.readLine();
PrincipalIn = Double.parseDouble(answer);

try
{
if(PrincipalIn <= 0) throw new NumberFormatException();

else done = true;
}

catch(NumberFormatException nfe)
{
System.out.println("\t\t\tYou Have Entered An Invalid Response.");
System.out.println();
}

return PrincipalIn;
}

//Get user input for interest rate
public float loanRate() throws IOException
{
//Declare method variables
float InterestIn = 0;
String InterestAnswer;
boolean done = false;
BufferedReader dataIn = new BufferedReader(new InputStreamReader(System.in));
DecimalFormat monetary = new DecimalFormat("#,###0.00");

//loop until done

System.out.println();
System.out.print("\t\t\tPlease Enter Interest Rate % == ");
InterestAnswer = dataIn.readLine();
InterestIn = Float.parseFloat(InterestAnswer);

//System.out.println("\t\t\tThe Interest Rate of Your Loan Is %" + percentage.format(InterstIn));

try
{
if(InterestIn <=0) throw new NumberFormatException();

else done = true;
}

catch(NumberFormatException nfe)
{
System.out.println("\t\t\tYou Have Entered An Invalid Reponse.");
System.out.println();
}


return InterestIn;
}

//get user input for Term
public double loanTerm() throws IOException
{
//Declare mehtod Variables
double TermIn = 0;
String TermAnswer;
boolean done = false;
System.out.println("Please Enter the Term of the Loan in Months:");
BufferedReader dataIn = new BufferedReader(new InputStreamReader(System.in));

//loop until done


TermAnswer = dataIn.readLine();
TermIn = Double.parseDouble(TermAnswer);
try
{
if(TermIn <= 0) throw new NumberFormatException();
else done = true;
}
catch(NumberFormatException nfe)
{
System.out.println("\t\t\tYou Have Entered An Invalid Response.");
System.out.println();
}

return TermIn;
}
//Calculation of Monthly Mortgage Payment
public double CalcAmt(float loanRate, double loanTerm, double loanAmt)
{
double NP, PV;
float IR;
NP = loanTerm/12;
IR = loanRate*100/12;
PV = loanAmt;

//Calculation Formula for the Loan
return (PV * IR) / (1 - Math.pow(1 + IR, - NP)); 
}

public static void main(String args[]) throws IOException
{
    Mortgage3 m1 =	new Mortgage3();
	float b;
	double a,c;
	
	a=m1.loanAmt();
	b=m1.loanRate();
	c=m1.loanTerm();
  	m1.CalcAmt(b,c,a);
  	System.out.println("Output == "+m1.CalcAmt(b,c,a));
}
}

Thanks guys, i can't believe I did something so stupid

This question has already been answered. Start a new discussion instead.