//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));
}
}
evak77
0
Newbie Poster
Recommended Answers
Jump to PostI'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.
Jump to PostYour code goes here
Do that. Clicking the "#" button will do it automatically for you.
All 9 Replies
cale.macdonald
4
Junior Poster
DeadSoul
-2
Junior Poster in Training
evak77
0
Newbie Poster
ubi_ct83
-3
Junior Poster
BestJewSinceJC
700
Posting Maven
cale.macdonald
4
Junior Poster
DeadSoul
-2
Junior Poster in Training
evak77
0
Newbie Poster
DeadSoul
-2
Junior Poster in Training
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.