| | |
Java equivalant to C's getchar()
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
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.
Java Syntax (Toggle Plain Text)
import java.io.*; // java input output package import java.text.DecimalFormat; // allows placement of decimal public class MonthlyPayments3c extends Thread //class header with "Thread" for sleep { public static void main(String[] args) { double Loan, NewBal, MIP; double Rate, MonthlyInterest, Payments; //double precision variables //assign values to variables Loan= 200000; // loan amount Rate = .0575; //interest rate MonthlyInterest = Rate / 12; // interest for each month Payments = Loan * (MonthlyInterest / (1 - Math.pow(1+MonthlyInterest, -360))); //my formula DecimalFormat twoDigits = new DecimalFormat("$,000.00"); // declares decimal format MIP= (Loan * Rate) / 12; NewBal = Loan -(Payments-MIP); System.out.println("Monthly Payments Interest Paid This Payment Loan Balance"); System.out.println();//my printout provides extra line System.out.print(" " + twoDigits.format(Payments)); //my printout System.out.print("\t\t\t" + twoDigits.format(MIP));//my printout System.out.println("\t\t\t" + twoDigits.format(NewBal));//my printout System.out.print(" " + twoDigits.format(Payments)); //my printout MIP=(NewBal*Rate)/12; System.out.print("\t\t\t" + twoDigits.format(MIP));//my printout NewBal=NewBal -(Payments-MIP); System.out.println("\t\t\t" + twoDigits.format(NewBal));//my printout System.out.print(" " + twoDigits.format(Payments)); //my printout while (NewBal > 1) //while loop to make computations continue until gets to $200000 { MIP=(NewBal*Rate)/12; System.out.print("\t\t\t" + twoDigits.format(MIP));//my printout NewBal=NewBal -(Payments-MIP); System.out.println("\t\t\t" + twoDigits.format(NewBal));//my printout System.out.println(" " + twoDigits.format(Payments)); //my printout if (NewBal <100000) // tells when this is met to transition to sleep phase try { Thread.sleep (50); //sleep phase needed per change request also states pause is 500 milliseconds } catch (InterruptedException e) { } } if (NewBal <1); { double Rate2; Rate2 = .055; //interest rate MonthlyInterest = Rate2 / 12; // interest for each month Payments = Loan * (MonthlyInterest / (1 - Math.pow(1+MonthlyInterest, -180))); //my formula MIP= (Loan * Rate2) / 12; NewBal = Loan -(Payments-MIP); System.out.println("Monthly Payments Interest Paid This Payment Loan Balance"); System.out.println();//my printout provides extra line System.out.print(" " + twoDigits.format(Payments)); //my printout System.out.print("\t\t\t" + twoDigits.format(MIP));//my printout System.out.println("\t\t\t" + twoDigits.format(NewBal));//my printout System.out.print(" " + twoDigits.format(Payments)); //my printout MIP=(NewBal*Rate)/12; System.out.print("\t\t\t" + twoDigits.format(MIP));//my printout NewBal=NewBal -(Payments-MIP); System.out.println("\t\t\t" + twoDigits.format(NewBal));//my printout System.out.print(" " + twoDigits.format(Payments)); //my printout while (NewBal > 1) //while loop to make computations continue until gets to $200000 { MIP=(NewBal*Rate)/12; System.out.print("\t\t\t" + twoDigits.format(MIP));//my printout NewBal=NewBal -(Payments-MIP); System.out.println("\t\t\t" + twoDigits.format(NewBal));//my printout System.out.println(" " + twoDigits.format(Payments)); //my printout try { Thread.sleep (50); //sleep phase needed per change request also states pause is 500 milliseconds } catch (InterruptedException e) { } } if (NewBal <1); { double Rate3; Rate3 = .0535; //interest rate MonthlyInterest = Rate2 / 12; // interest for each month Payments = Loan * (MonthlyInterest / (1 - Math.pow(1+MonthlyInterest, -84))); //my formula MIP= (Loan * Rate3) / 12; NewBal = Loan -(Payments-MIP); System.out.println("Monthly Payments Interest Paid This Payment Loan Balance"); System.out.println();//my printout provides extra line System.out.print(" " + twoDigits.format(Payments)); //my printout System.out.print("\t\t\t" + twoDigits.format(MIP));//my printout System.out.println("\t\t\t" + twoDigits.format(NewBal));//my printout System.out.print(" " + twoDigits.format(Payments)); //my printout MIP=(NewBal*Rate)/12; System.out.print("\t\t\t" + twoDigits.format(MIP));//my printout NewBal=NewBal -(Payments-MIP); System.out.println("\t\t\t" + twoDigits.format(NewBal));//my printout System.out.print(" " + twoDigits.format(Payments)); //my printout while (NewBal > 1) //while loop to make computations continue until gets to $200000 { MIP=(NewBal*Rate)/12; System.out.print("\t\t\t" + twoDigits.format(MIP));//my printout NewBal=NewBal -(Payments-MIP); System.out.println("\t\t\t" + twoDigits.format(NewBal));//my printout System.out.println(" " + twoDigits.format(Payments)); //my printout try { Thread.sleep (50); //sleep phase needed per change request also states pause is 500 milliseconds } catch (InterruptedException e) { } } } } } }
•
•
Join Date: Jun 2006
Posts: 2
Reputation:
Solved Threads: 0
•
•
•
•
Originally Posted by korbynlehr
How do you use the sleep method?
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
![]() |
Similar Threads
- Java Client/Server (Java)
- Java Expert (Needed) (Java)
Other Threads in the Java Forum
- Previous Thread: Mortgage array Help please
- Next Thread: Inserting Data into Access Database
| Thread Tools | Search this Thread |
Tag cloud for Java
actionlistener android api apple applet application apps arguments array arrays automation balls binary bluetooth card chat class classes clear client code component consumer database draw eclipse ee error event exception fractal free game gameprogramming gis givemetehcodez graphics gui html ide image input integer j2me j2seprojects java javaprojects jni jpanel julia jvm key linux list loop machine map method methods migrate mobile mobiledevelopmentcreatejar myaggfun netbeans newbie nextline nls notdisplaying number oracle output print problem program programming project recursion recursive scanner screen security server set size sms socket sort spamblocker sql sqlite string sun swing terminal test threads time tree trolltech windows






