Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /** This program will print out information regarding a loan and also capture the output of a file.
- * Class: CST183
- * Due 10/19/17
- * Name: Taylen White
- */
- import javax.swing.JOptionPane;
- public class LoanCalc{
- public static void main(String args[]) {
- // declare variables
- double monthlyPayment;
- int loanTerm;
- double loanAmount;
- int interestRate;
- loanTerm = getLoanTerm();
- if (loanTerm < 1 || loanTerm > 30) {
- JOptionPane.showMessageDialog(null, "Your loan term must be within the range of 1 - 30 years. ");
- }
- loanAmount = getLoanAmount();
- if (loanAmount < 0 || loanAmount > 1000000) {
- JOptionPane.showMessageDialog(null, "Your loan amount must be within the range of 0 - $1,000,000. ");
- }
- interestRate = getInterestRate();
- if (interestRate < 1 || interestRate > 8) {
- JOptionPane.showMessageDialog(null, "Your interest rate must be from 1 - 8%. ");
- }
- calculateMonthlyPayment(loanAmount, interestRate, loanTerm);
- JOptionPane.showMessageDialog(null, "Your monthly payment will be" + monthlyPayment );
- }
- public static int getLoanTerm()
- {
- String inputStringLoanTerm = JOptionPane.showInputDialog(null, "Please input your desired loan term.(Between 1 and 30 years) ");
- return Integer.parseInt(inputStringLoanTerm);
- }
- public static double getLoanAmount()
- {
- String inputStringLoanAmount = JOptionPane.showInputDialog(null, "Please input your desired loan amount. (Between 0 and $1,000,000) ");
- return Integer.parseInt(inputStringLoanAmount);
- }
- public static int getInterestRate()
- {
- String inputStringInterestRate = JOptionPane.showInputDialog(null, "Please input your desired interest rate. (Between 1 - 8%) ");
- return Integer.parseInt(inputStringInterestRate);
- }
- public static double calculateMonthlyPayment(double principal, int monthlyInterestRate, int numberOfMonths)
- {
- double monthlyPayment = principal / (1-(1 + monthlyInterestRate)- numberOfMonths / monthlyInterestRate);
- return monthlyPayment;
- }
- //public static double CreateAmortTable()
- // {
- // return amortTable;
- // }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement