Hi,
I'm new to java and I have a homework.
Below is my working code, however, I would like to have a loop in order to return to the menu for user's input.
package mortgagecalc_cr2;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
/**
*
* @author adr1817
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws IOException {
/*************************************************************
** Initialze Variables **
** Decimal Format to return 2 decimal point. **
** **
*************************************************************/
String userChoice;
int Choice;
BufferedReader myIn= new BufferedReader(new InputStreamReader(System.in));
java.text.DecimalFormat df = new java.text.DecimalFormat("###,###.00");
double Principal = 200000;
int termOne = 84;
int termTwo = 180;
int termThree = 360;
double rateOne = .0535;
double rateTwo = .0550;
double rateThree = .0575;
for (int i=0; i<1; i++) {
double firstOption, secondOption, thirdOption, currentBalance, monthlyInterestPaid;
double mosIntrateOne = (rateOne/12);
double mosIntrateTwo = (rateTwo/12);
double mosIntrateThree = (rateThree/12);
System.out.println();
System.out.printf("%51s\n", "Mortgage Payment Calculator");
System.out.printf("%60s\n", "===========================================");
System.out.println();
System.out.println("This program will show you the monthly mortgage payment of each loan.");
System.out.println("Please select from the three loan types.");
System.out.println();
System.out.printf("%10s\n", "Loan amount = $200,000\n");
System.out.printf("%48s\n", "Loan #1: 7yrs, 5.35%");
System.out.printf("%48s\n", "Loan #2: 15yrs, 5.50%");
System.out.printf("%48s\n", "Loan #3: 30yrs, 5.75%");
System.out.println();
System.out.println("\t\tView all loans - press 4 on your keyboard.");
System.out.println();
/***********************************************************************
** This is where it will prompt the user to do a choose **
** which loan to take. **
***********************************************************************/
System.out.println ("Which loan would you like to take a look at?");
System.out.println ("Please key-in a number from 1 to 4, then press ENTER: ");
userChoice = myIn.readLine();
Choice = Integer.parseInt(userChoice);
/* Math equation */
firstOption = (Principal * mosIntrateOne) / (1 - 1 / Math.pow((1 + mosIntrateOne), termOne));
secondOption = (Principal * mosIntrateTwo ) / (1 - 1 / Math.pow((1 + mosIntrateTwo ), termTwo));
thirdOption = (Principal * mosIntrateThree ) / (1 - 1 / Math.pow((1 + mosIntrateThree ), termThree));
currentBalance = Principal;
/*Condition */
switch(Choice){
case 1:
System.out.println();
System.out.println();
System.out.println("You have chosen Loan #1\n");
System.out.println("Loan Term \t Interest \t Monthly Payment");
System.out.println("7 Years \t 5.35% \t " + (df.format(firstOption)));
break;
case 2:
System.out.println();
System.out.println();
System.out.println("You have chosen Loan #2\n");
System.out.println("Loan Term \t Interest \t Monthly Payment");
System.out.println("15 Years \t 5.50% \t " + (df.format(secondOption)));
break;
case 3:
System.out.println();
System.out.println();
System.out.println("You have chosen Loan #3\n");
System.out.println("Loan Term \t Interest \t Monthly Payment");
System.out.println("30 Years \t 5.75% \t " + (df.format(thirdOption)));
break;
case 4:
System.out.println();
System.out.println("You have chosen to view all 3 loans.\n");
System.out.println("Loan Term \t Interest \t Monthly Payment");
System.out.println("7 Years \t 5.35% \t " + (df.format(firstOption)));
System.out.println("15 Years \t 5.50% \t " + (df.format(secondOption)));
System.out.println("30 Years \t 5.75% \t " + (df.format(thirdOption)));
break;
default:
InvalidChoice(); // Calls an invalid selection when different number is press
}
}
}
private static void InvalidChoice() {
System.out.println("Invalid selection!");
}
}