Java equivalant to C's getchar()

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: May 2006
Posts: 18
Reputation: korbynlehr is an unknown quantity at this point 
Solved Threads: 0
korbynlehr's Avatar
korbynlehr korbynlehr is offline Offline
Newbie Poster

Java equivalant to C's getchar()

 
0
  #1
Jun 3rd, 2006
I am needing to put a pause in between each mortgage calculation and do not know what the C equivalant of getchar() is in Java. Here is the code I have so far, after it is finished with the first mortgage at 30 years I want the user to have to press enter to continue to the next rate. Help is appreciated.

  1. import java.io.*; // java input output package
  2. import java.text.DecimalFormat; // allows placement of decimal
  3.  
  4. public class MonthlyPayments3c extends Thread //class header with "Thread" for sleep
  5. {
  6. public static void main(String[] args)
  7. {
  8.  
  9. double Loan, NewBal, MIP;
  10. double Rate, MonthlyInterest, Payments; //double precision variables
  11.  
  12.  
  13. //assign values to variables
  14. Loan= 200000; // loan amount
  15. Rate = .0575; //interest rate
  16. MonthlyInterest = Rate / 12; // interest for each month
  17. Payments = Loan * (MonthlyInterest / (1 - Math.pow(1+MonthlyInterest, -360))); //my formula
  18. DecimalFormat twoDigits = new DecimalFormat("$,000.00"); // declares decimal format
  19. MIP= (Loan * Rate) / 12;
  20. NewBal = Loan -(Payments-MIP);
  21. System.out.println("Monthly Payments Interest Paid This Payment Loan Balance");
  22. System.out.println();//my printout provides extra line
  23. System.out.print(" " + twoDigits.format(Payments)); //my printout
  24. System.out.print("\t\t\t" + twoDigits.format(MIP));//my printout
  25. System.out.println("\t\t\t" + twoDigits.format(NewBal));//my printout
  26. System.out.print(" " + twoDigits.format(Payments)); //my printout
  27. MIP=(NewBal*Rate)/12;
  28. System.out.print("\t\t\t" + twoDigits.format(MIP));//my printout
  29. NewBal=NewBal -(Payments-MIP);
  30. System.out.println("\t\t\t" + twoDigits.format(NewBal));//my printout
  31. System.out.print(" " + twoDigits.format(Payments)); //my printout
  32.  
  33. while (NewBal > 1) //while loop to make computations continue until gets to $200000
  34. {
  35.  
  36. MIP=(NewBal*Rate)/12;
  37. System.out.print("\t\t\t" + twoDigits.format(MIP));//my printout
  38. NewBal=NewBal -(Payments-MIP);
  39. System.out.println("\t\t\t" + twoDigits.format(NewBal));//my printout
  40. System.out.println(" " + twoDigits.format(Payments)); //my printout
  41.  
  42. if (NewBal <100000) // tells when this is met to transition to sleep phase
  43.  
  44. try
  45. {
  46. Thread.sleep (50); //sleep phase needed per change request also states pause is 500 milliseconds
  47. }
  48. catch (InterruptedException e)
  49. {
  50. }
  51. }
  52. if (NewBal <1);
  53. {
  54. double Rate2;
  55. Rate2 = .055; //interest rate
  56. MonthlyInterest = Rate2 / 12; // interest for each month
  57. Payments = Loan * (MonthlyInterest / (1 - Math.pow(1+MonthlyInterest, -180))); //my formula
  58. MIP= (Loan * Rate2) / 12;
  59. NewBal = Loan -(Payments-MIP);
  60. System.out.println("Monthly Payments Interest Paid This Payment Loan Balance");
  61. System.out.println();//my printout provides extra line
  62. System.out.print(" " + twoDigits.format(Payments)); //my printout
  63. System.out.print("\t\t\t" + twoDigits.format(MIP));//my printout
  64. System.out.println("\t\t\t" + twoDigits.format(NewBal));//my printout
  65. System.out.print(" " + twoDigits.format(Payments)); //my printout
  66. MIP=(NewBal*Rate)/12;
  67. System.out.print("\t\t\t" + twoDigits.format(MIP));//my printout
  68. NewBal=NewBal -(Payments-MIP);
  69. System.out.println("\t\t\t" + twoDigits.format(NewBal));//my printout
  70. System.out.print(" " + twoDigits.format(Payments)); //my printout
  71.  
  72. while (NewBal > 1) //while loop to make computations continue until gets to $200000
  73. {
  74.  
  75. MIP=(NewBal*Rate)/12;
  76. System.out.print("\t\t\t" + twoDigits.format(MIP));//my printout
  77. NewBal=NewBal -(Payments-MIP);
  78. System.out.println("\t\t\t" + twoDigits.format(NewBal));//my printout
  79. System.out.println(" " + twoDigits.format(Payments)); //my printout
  80. try
  81. {
  82. Thread.sleep (50); //sleep phase needed per change request also states pause is 500 milliseconds
  83. }
  84. catch (InterruptedException e)
  85. {
  86. }
  87. }
  88. if (NewBal <1);
  89. {
  90. double Rate3;
  91. Rate3 = .0535; //interest rate
  92. MonthlyInterest = Rate2 / 12; // interest for each month
  93. Payments = Loan * (MonthlyInterest / (1 - Math.pow(1+MonthlyInterest, -84))); //my formula
  94. MIP= (Loan * Rate3) / 12;
  95. NewBal = Loan -(Payments-MIP);
  96. System.out.println("Monthly Payments Interest Paid This Payment Loan Balance");
  97. System.out.println();//my printout provides extra line
  98. System.out.print(" " + twoDigits.format(Payments)); //my printout
  99. System.out.print("\t\t\t" + twoDigits.format(MIP));//my printout
  100. System.out.println("\t\t\t" + twoDigits.format(NewBal));//my printout
  101. System.out.print(" " + twoDigits.format(Payments)); //my printout
  102. MIP=(NewBal*Rate)/12;
  103. System.out.print("\t\t\t" + twoDigits.format(MIP));//my printout
  104. NewBal=NewBal -(Payments-MIP);
  105. System.out.println("\t\t\t" + twoDigits.format(NewBal));//my printout
  106. System.out.print(" " + twoDigits.format(Payments)); //my printout
  107.  
  108. while (NewBal > 1) //while loop to make computations continue until gets to $200000
  109. {
  110.  
  111. MIP=(NewBal*Rate)/12;
  112. System.out.print("\t\t\t" + twoDigits.format(MIP));//my printout
  113. NewBal=NewBal -(Payments-MIP);
  114. System.out.println("\t\t\t" + twoDigits.format(NewBal));//my printout
  115. System.out.println(" " + twoDigits.format(Payments)); //my printout
  116. try
  117. {
  118. Thread.sleep (50); //sleep phase needed per change request also states pause is 500 milliseconds
  119. }
  120. catch (InterruptedException e)
  121. {
  122. }
  123. }
  124. }
  125. }
  126. }
  127. }
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 5,273
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 378
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

Re: Java equivalant to C's getchar()

 
0
  #2
Jun 4th, 2006
You could use the scanner util class instead, possibly?
*Voted best profile in the world*
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 2,108
Reputation: server_crash is on a distinguished road 
Solved Threads: 18
server_crash server_crash is offline Offline
Postaholic

Re: Java equivalant to C's getchar()

 
0
  #3
Jun 4th, 2006
Sleep or prompt the user?

BufferedReader.readLine()?
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 18
Reputation: korbynlehr is an unknown quantity at this point 
Solved Threads: 0
korbynlehr's Avatar
korbynlehr korbynlehr is offline Offline
Newbie Poster

Re: Java equivalant to C's getchar()

 
0
  #4
Jun 4th, 2006
So how does this scanner util class work?
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 18
Reputation: korbynlehr is an unknown quantity at this point 
Solved Threads: 0
korbynlehr's Avatar
korbynlehr korbynlehr is offline Offline
Newbie Poster

Re: Java equivalant to C's getchar()

 
0
  #5
Jun 4th, 2006
How do you use the sleep method?
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 2
Reputation: JasonAnders is an unknown quantity at this point 
Solved Threads: 0
JasonAnders JasonAnders is offline Offline
Newbie Poster

Re: Java equivalant to C's getchar()

 
0
  #6
Jun 4th, 2006
Originally Posted by korbynlehr
How do you use the sleep method?
Hi,

this is easily found on the Java Apidocs...

http://java.sun.com/j2se/1.5.0/docs/...ng/Thread.html
(this is for 1.5. but 1.4.x behaves exactly the same)

static void sleep(long millis)
Causes the currently executing thread to sleep (temporarily cease execution) for the specified number of milliseconds

your code can simply call
java.lang.Thread.sleep(10000);

Jason


Sunflower Network - Instant Computer Help
http://www.sunflowernetwork.com
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Java Forum
Thread Tools Search this Thread



Tag cloud for Java
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC