473,385 Members | 1,772 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Controlling screen output

My program seems to run across the screen like carzy and I can not figoure out how to make it stop. Can anyone help me with this. Here is my program:
Expand|Select|Wrap|Line Numbers
  1. import java.text.DecimalFormat;
  2.  
  3. public class mortgagecalculatorwk3
  4. {
  5. public static void main (String[]args)
  6.     {
  7. /*Declares and intialize my varibles*/
  8.     double P=200000; /*the initial amount of the loan*/
  9.     double I =0.0575; /*annual interest rate(1 to 100 percent*/
  10.     int    t=30;      /*length of the loan*/
  11.     double mi=0;     /*monthly interest I/(12*100)*/
  12.     double mp=0;   /*monthly payment*/
  13.     double T=0;    /*declares monthly interest to be raised.*/
  14.     double NM=0;    /*current monthly interest*/
  15.     double c=0;        /*monthly payment-monthly interest rate*/
  16.     double np=0;    /*new balance of loan*/
  17.     double IP=0;    /* interest of the life of the loan*/
  18.     int year=0;       /*number of years*/
  19.     int month=0;    /*number of months*/
  20.     int count=12;
  21.  
  22.  
  23. /*Formulas that will be used are:*/
  24. mi=(I/(12*100));
  25. mp=(P*((I/12)/(1-Math.pow((1+(I/12)),-(t*12)))));
  26. NM=P*mi;//monthly interest//
  27. c=mp-NM;//monthly payment minus interest//
  28. np=P-c;//balance of the loan to-date//
  29. P=np;//the new balance of the loan//
  30.  
  31. System.out.println("Principal=$"+P);
  32. System.out.println("Interest rate="+I*100);
  33. System.out.println("Years of term="+t);
  34. System.out.println("Number of payments="+t*12);
  35. System.out.println("Monthly payment=$"+mp);
  36. /*loop begins here*/
  37.         for(year=1; year<=t; year++)
  38.         {
  39.         System.out.println();
  40.         System.out.println("Press Enter key to continue.");
  41.  
  42.         for(month=1; month<=12; month++)
  43.         {
  44.         System.out.println("The monthly payment" + month + "year" + year + "Principle is:$ "+c);
  45.         System.out.println("Interest for the life of the loan:$ "+NM);
  46.         System.out.println("New balance of the loan:$  "+np);
  47.         }//Exit month loop
  48.  
  49.         }//exit year loop
  50. System.out.println();
  51. System.out.println("Press Enter to continue");
  52.  
  53.     }
  54. }
  55.  
  56.  
Please help me out here!
Feb 18 '07 #1
2 1540
horace1
1,510 Expert 1GB
I assume after the message "Press Enter key to continue." you want the program to wait for the user to hit the enter key, try using Scanner, e.g.
Expand|Select|Wrap|Line Numbers
  1. import java.text.DecimalFormat;
  2. import java.util.Scanner;
  3.  
  4. public class mortgagecalculatorwk3
  5. {
  6. public static void main (String[]args)
  7.         {
  8. Scanner s=new Scanner(System.in);
  9. /*Declares and intialize my varibles*/
  10.         double P=200000; /*the initial amount of the loan*/
  11.         double I =0.0575; /*annual interest rate(1 to 100 percent*/
  12.         int    t=30;    /*length of the loan*/
  13.         double mi=0;    /*monthly interest I/(12*100)*/
  14.         double mp=0;   /*monthly payment*/
  15.         double T=0;    /*declares monthly interest to be raised.*/
  16.         double NM=0;    /*current monthly interest*/
  17.         double c=0;        /*monthly payment-monthly interest rate*/
  18.         double np=0;    /*new balance of loan*/
  19.         double IP=0;    /* interest of the life of the loan*/
  20.         int year=0;        /*number of years*/
  21.         int month=0;    /*number of months*/
  22.         int count=12;
  23.  
  24.  
  25. /*Formulas that will be used are:*/
  26. mi=(I/(12*100));
  27. mp=(P*((I/12)/(1-Math.pow((1+(I/12)),-(t*12)))));
  28. NM=P*mi;//monthly interest//
  29. c=mp-NM;//monthly payment minus interest//
  30. np=P-c;//balance of the loan to-date//
  31. P=np;//the new balance of the loan//
  32.  
  33. System.out.println("Principal=$"+P);
  34. System.out.println("Interest rate="+I*100);
  35. System.out.println("Years of term="+t);
  36. System.out.println("Number of payments="+t*12);
  37. System.out.println("Monthly payment=$"+mp);
  38. /*loop begins here*/
  39.                 for(year=1; year<=t; year++)
  40.                 {
  41.                 System.out.println();
  42.                 System.out.println("Press Enter key to continue.");
  43.                 s.nextLine();
  44.                 for(month=1; month<=12; month++)
  45.                 {
  46.                 System.out.println("The monthly payment" + month + "year" + year + "Principle is:$ "+c);
  47.                 System.out.println("Interest for the life of the loan:$ "+NM);
  48.                 System.out.println("New balance of the loan:$  "+np);
  49.                 }//Exit month loop
  50.  
  51.                 }//exit year loop
  52. System.out.println();
  53. System.out.println("Press Enter to continue");
  54.  
  55.         }
  56. }
  57.  
Feb 18 '07 #2
Thank you that has seem to fix my problem.
Feb 18 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Jason | last post by:
I have a screen where I ask the user their payment type. Once they select the payment type either check or credit card, I would like them to go to a seperate checkout page. How can I write a bit of...
4
by: Dennis | last post by:
Hi, I suppose this post could fall under comp.os.linux/comp.os.unix as well, but I figured since my end goal was control from C++ code I figured this group might be the place to start. As the...
3
by: Scott M | last post by:
Hi, I am currently trying to write a simple game using vb.net the form I am working on is 800*600 (this is set as the maximum size) and autoscroll is set to true. The user moves around the...
1
by: cplusplusstudent | last post by:
Hello I am a new C++ programmer and am working with the Visual C++ studio. I am attempting to create a simple console application for myself but I fin that neither of the introductory C++ books...
0
by: Scott M | last post by:
Hi, I am currently trying to write a simple game using vb.net the form I am working on is 800*600 (this is set as the maximum size) and autoscroll is set to true. The user moves around the...
1
by: steve | last post by:
Hi All I want to display a splash screen when my windows application loads, to show sql server connection progress etc. First though I want to run some code to check for a valid program...
48
by: mantrid | last post by:
Hello Is there a way to prevent users copying a full size image from a web page. Displaying the image with a smaller width and height only affects the image as viewed, the actual full size image...
1
by: Mario Figueiredo | last post by:
Hello everyone, I'm having trouble controlling the cursor position when I make two consecutive calls to the get family of functions. This problem does not happen if there is an output in...
13
by: trbjr | last post by:
My client-side application works reliably and as intended in Firefox, but not in IE6. The problem seems to be that I do not have control over the page stack in IE, while I do in Firefox. So far I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.