?
Solved

Mortgage Program - Inserting User Pause (Press any key to continue)

Posted on 2008-10-17
4
Medium Priority
?
1,136 Views
Last Modified: 2013-11-23
I need to be shown the code to insert and where to insert it t make my program ask for the user to press any key to continue. I read doing it with the Java read command and it did not work. Right now I am using a "sleep" method which isn't really conducive to a good end user experience.

Also I need to know how to make the program print out each MONTH that a payment is being made for.

Right now, the program is only printing the numbers 1, 2 & 3, based on the arrays. I'd like to add another column for which month the payment is on (ie, month 40, 41, 42 etc..)

Yes this is homework however as you can see when you compile it, the program runs just fine and all of the math and calculations are 100% correct. So the core functionality is there and I am not really "cheating" at this point by asking how to do the assignment, which I would never do, because I won't learn anything.

I am just merely asking about how to make it pause and to print the months out, because I feel these are aesthetic additions and is not related to the core academia of the assignment.

Thank you,
/*
	Assignment detail
 
Modify the mortgage program to display 3 mortgage loans: 7 year at 5.35%, 15 year at 5.5 %, and 30 year at 5.65%.
Use an array for the different loans (the array will be needed in the next course).  Display the mortgage payment
amount for each loan.  Do not use a graphical user interface.  Insert comments in the program to document the program.
*/
 
 
//Import this Java class for formatting the dollar amount later on in the program
import java.text.DecimalFormat;
 
public class mortgagecalcweek5rev1
{
 public static void main(String[] args)
	{
 
 
//Setup output parser to correctly placed decimal places into final value
DecimalFormat decimalPlaces = new DecimalFormat("$ 0.00");
 
//Setup variables and store data
double [] cInterestRate = {.0535, .0550, .0565};
int [] cTotalMortgageMonths = {7*12,15*12,30*12};
double cFinalMonthlyPaymentOutput;
 
System.out.println("\tFIXED MORTGAGE CALCULATOR FOR THREE LOANS");
System.out.println();
System.out.println("\t\tFirst Interest Rate: 5.35% @ 7 years");
System.out.println("\t\tSecond Interest Rate: 5.50% @ 15 years");
System.out.println("\t\tThird Interest Rate: 5.65% @ 30 years");
 
 
 
int lineprints = 0;
 
//Setup for loop
 
for(int i=0; i<cTotalMortgageMonths.length; i++)
 
	     {
 
//Screen output section
System.out.println();
System.out.println();
System.out.println("\t\tMortgage Payment based on a $200,000 total loan amount");
System.out.println();
 
 
//Setup variables from previously defined array
 
double cTotalMortgageAmount = 200000;
double ir = cInterestRate[i];
double monthlyint = ir/12;
int t = cTotalMortgageMonths[i];
double cMonthlyInterestPayment = (cTotalMortgageAmount * (cInterestRate[i]/12));
 
 
//while(cTotalMortgageMonths[i]>0)
 
 
//Calculation section
 
double cMonthlyPayment = (cTotalMortgageAmount * monthlyint)/(1-Math.pow(1+monthlyint, -t));
 
double cMonthlyPrincipalPayment = (cMonthlyPayment - cMonthlyInterestPayment);
 
 
while(cTotalMortgageMonths[i]>0)
{
 
//Print the final total monthly amount
 
System.out.println("\t\tThe Total Monthly Payment is: "+ decimalPlaces.format (cMonthlyPayment));
 
System.out.println();
 
//Print Banner for columns
 
	System.out.println("\n\n\tPayment Principal\t\tInterest\t\tBalance");
	System.out.println("\t~~~~~~~~~~~~~~~~~~\t\t~~~~~~~~~\t\t~~~~~~~~~");
 
System.out.println((i+1) + "\t\t" + decimalPlaces.format(cMonthlyPrincipalPayment) +
    "\t\t" + decimalPlaces.format(cMonthlyInterestPayment) +
    "\t\t" + decimalPlaces.format(cTotalMortgageAmount));
 
 
//Calculate the interest and principal payments within the looping part of the mortgage program
	cMonthlyInterestPayment = (cTotalMortgageAmount * (cInterestRate[i]/12));
	cMonthlyPrincipalPayment = (cMonthlyPayment - cMonthlyInterestPayment);
 
//reduce balance
	cTotalMortgageAmount -= cMonthlyPrincipalPayment;
 
cTotalMortgageMonths[i]--;
 
 
 
if(lineprints == 25)
    {
    lineprints = 0;
     try
      {
      Thread.sleep(4800);
         }
       catch (InterruptedException e)
      {
 
         }
      }
      else
      {
	lineprints++;
 
                }
                }
}
}
}

Open in new window

0
Comment
Question by:packetattack
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 24

Expert Comment

by:sciuriware
ID: 22747392
Simplest:

          JOptionPane.showMessageDialog(yourJFrame, "Press ENTER to continue");

yourJFrame is your JFrame or any component to center on.


"Any key" is complexer and prone to mistakes.
;JOOP!
0
 

Author Comment

by:packetattack
ID: 22748511
Thanks Sciu for answering however this program is not using a GUI, it is strictly console output.
0
 
LVL 24

Accepted Solution

by:
sciuriware earned 500 total points
ID: 22748593
Then you can:

      System.out.print("Press ENTER to continue - ");  // No carriage return
      System.in.read();   // Reads 1 character.
// It makes sense to read until you see a '\r' character.

;JOOP!
0
 

Author Closing Comment

by:packetattack
ID: 31507386
Thanks, great help.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses
Course of the Month13 days, 8 hours left to enroll

800 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question