I already have a Please Press Enter to continue... Statement for the end of my list that will allow the list to stay on the screen, be read, then when the user is ready they hit enter and the list continues to the next page. That is part of the assignment what I want to add is not part of the assignment but I think would be cool to learn. I would like to give the user the option of either Pressing Enter to Continue (have this) or to return to the main console, or to exit the program.
Do I use a series of IF statements, or If/else statements, is what I am looking for called something else?
I googled what I thought to as on how to do this but I still can't find anything.
Thanks for any help you can give.
*---------------------------------------------------------------------------*/
// PROGRAM INFORMATION
// Programmer : Mari Dutton
//
// Date : (8/14/2010)
// Name : MortgageCalculator
// Filename: MortgageCalculator.java
// Purpose : The purpose of this program is to calculate mortgage payments.
// To calculate and display the customer's monthly mortgage
// of $200000 at 5.75% interest over 30 years.The program will display
// 360 payments with interest by the Month for 30 years.
//---------------------------------------------------------------------------*/
import java.text.DecimalFormat;//to import decimal format for money
import java.text.NumberFormat;//to import number format
import java.io.Console;//Calls the class Console for user input and output
public class MortgageCalculator1 // Starts the Class
{
public static void main(String[]args) throws Exception //declaring main method with thrown Exception
{
//Arrays
double loanAmount = 200000; //Starting Balance of loan
double[] tMonths = {360,180,84};// Array for year term of the Loan
double[] iRate = {.0575,.055,.0535}; // Array for interest rate of the Loan
//Varibles
double balance; //Final balance of each month
double principal; // Principal of each month
double monthlyInterestPaid; // Monthly Interest paid with each payment
//Table display
int row;
int maxRows = 12; //maximum number of rows to display
//User entry input
int userEntry;
String userEntry2;
String userEntry3;
//Varibles for calculations per loan type
double mPayments30;
double mPayments15;
double mPayments07;
//calculating the arrays
mPayments30 = ((iRate[0]/12) * loanAmount) / (1-(Math.pow(1+(iRate[0]/12),
(- tMonths[0]))));
mPayments15 = ((iRate[1]/12) * loanAmount) / (1-(Math.pow(1+(iRate[1]/12),
(- tMonths[1]))));
mPayments07 = ((iRate[2]/12) * loanAmount) / (1-(Math.pow(1+(iRate[2]/12),
(- tMonths[2]))));
//initializing balance varible
balance = loanAmount;
//Calls in the console
Console c = System.console();
//Programming infromation
System.out.println();
System.out.println("\t\t Mortgage Calculator");
System.out.println("\t\t -------------------");
System.out.println("\t\t Programmed by Mari Dutton");
System.out.println("\t\t Mobile Loan Calculator ");
System.out.println("");
//User imput/instance Menu to determine type of loan
System.out.println("");
System.out.println("");
System.out.println("\t\t Select your Loan. ");
System.out.println("\t\t ------------------");
System.out.println("\t\t 1. 30 year with interest at 5.75%.");
System.out.println("\t\t 2. 15 year with interest at 5.5% ");
System.out.println("\t\t 3. 07 year with interest at 5.35% ");
System.out.println("\t\t 4. Exit");
System.out.println("");
//Uner Entry Input from user
userEntry = (int)System.in.read();
if (c == null)
{
System.err.println("Console Error.");
System.exit(5);
}
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\\
//=30 year loan
//If statement to enter User Entry input
if (userEntry == '1')
{
System.out.println("");
System.out.println("");
System.out.println("Loan Information: ");
System.out.println("========================");
System.out.println("Loan Amount: $200,000.00");
System.out.println("Months: " + tMonths[0]);
System.out.println("Interest% Rate: " + iRate[0]);
System.out.printf ("Monthly payment amount will be $%.2f", mPayments30);
System.out.println("");
System.out.printl("++++++++++++++++++++++++++++++++++++++++++++++++++");
System.out.println("Payment Amount Interest Paid Principal Balance ");
System.out.println("++++++++++++++++++++++++++++++++++++++++");
for ( row =1; row <= tMonths[0]; row++)
//Calculating the Monthly Paid Interest;
monthlyInterestPaid = (iRate[0]/12) * balance; //calculates monthly Interest Paid
//Calculating the Principal
principal = mPayments15 - monthlyInterestPaid;//calculates Principal
//Calculating the Balance
balance = balance - principal;
System.out.println("Payment " +row+
":\t"+NumberFormat.getCurrencyInstance().format (mPayments30) +
",\t"+NumberFormat.getCurrencyInstance().format(monthlyInterestPaid) +
",\t"+NumberFormat.getCurrencyInstance().format(principal) +
",\t"+NumberFormat.getCurrencyInstance().format(balance));
if ((row % maxRows) == 0)
userEntry2 = c.readLine("Press Enter to continue... ");
}
}
{
if (userEntry == '2')
{
System.out.println("");
System.out.println("");
System.out.println("Loan Information: ");
System.out.println("========================");
System.out.println("Loan Amount: $200,000.00");
System.out.println("Months: " + tMonths[1]);
System.out.println("Interest% Rate: " + iRate[1]);
System.out.printf ("Monthly payment amount will be $%.2f", mPayments15);
System.out.println("");
System.out.println("");
System.out.println("++++++++++++++++++++++++++++++++++++++++++++++++++++++");
System.out.println("Payment Amount Interest Paid Principal Balance ");
System.out.println("++++++++++++++++++++++++++++++++++++++++++++++++++++++");
for ( row =1; row <= tMonths[1]; row++)
{
//Calculating the Monthly Paid Interest;
monthlyInterestPaid = (iRate[1]/12) * balance; //calculates monthly Interest Paid
//Calculating the Principal
principal = mPayments15 - monthlyInterestPaid;//calculates Principal
//Calculating the Balance
balance = balance - principal;
System.out.println("Payment" +row+
": \t"+NumberFormat.getCurrencyInstance().format (mPayments15) +
", \t"+NumberFormat.getCurrencyInstance().format(monthlyInterestPaid) +
", \t"+NumberFormat.getCurrencyInstance().format(principal) +
", \t"+NumberFormat.getCurrencyInstance().format(balance));
if ((row % maxRows) == 0)
userEntry2 = c.readLine("Press Enter to continue... ");
}
}
{
if (userEntry == '3')
{
System.out.println("");
System.out.println("");
System.out.println("Loan Information: ");
System.out.println("------------------------");
System.out.println("Loan Amount: $200,000.00");
System.out.println("Months: " + tMonths[2]);
System.out.println("Interest% Rate: " + iRate[2]);
System.out.printf("Monthly payment amount will be $%.2f", mPayments07);
System.out.println("");
System.out.println("+++++++++++++++++++++++++++++++++++++++++++++++++++");
System.out.println("Payment Amount Interest Paid Principal Balance ");
System.out.println("+++++++++++++++++++++++++++++++++++++++++++++++++++");
for ( row =1; row <= tMonths[2]; row++)
{
//Calculating the Monthly Paid Interest;
monthlyInterestPaid = (iRate[2]/12) * balance; //calculates monthly Interest Paid
//Calculating the Principal
principal = mPayments07 - monthlyInterestPaid;//calculates Principal
//Calculating the Balance
balance = balance - principal;
System.out.println("Payment " +row+
": \t"+NumberFormat.getCurrencyInstance().format (mPayments07) +
", \t"+NumberFormat.getCurrencyInstance().format(monthlyInterestPaid) +
", \t"+NumberFormat.getCurrencyInstance().format(principal) +
", \t"+NumberFormat.getCurrencyInstance().format(balance));
if ((row % maxRows) == 0)
userEntry2 = c.readLine("Thank you Please Press enter to exit ");
}
}
{
if(userEntry == '4')
{
System.out.println("\t Exiting the The Mortgage Calculator now. Thank you");
System.exit(0); //calling exit method
}
}
}
}
}
}