keyboard input help
Author |
Message |
mendem03
|
Posted: Thu May 27, 2010 3:45 pm Post subject: keyboard input help |
|
|
I would like keyboard input help with this program. How do i add it to this program so i could do keyboard input
public static void main(String[]text)
{
double amount=Double.parseDouble (text[0]);
double interestRate[]=new double[4];
System.out.println("\n" + "We are offering loans upto $50000 at good rates so if anyone is looking for a loan we are here for you.");
System.out.println("\n" + "How much money do you want to borrow?.");
if (amount<=10000)
{
System.out.print("\n" + "The interest rate you are borrowing at is ");
System.out.print(interestRate[1]=5);
System.out.println(" %.");
System.out.println(interestRate[1]/=100);
}
else if ((amount>10000) && (amount<=20000))
{
System.out.print("\n" + "The interest rate you are borrowing at is ");
System.out.print(interestRate[2]=10);
System.out.println(" %.");
System.out.println(interestRate[2]/=100);
}
else if ((amount>20000) && (amount<=50000))
{
System.out.print("\n" + "The interest rate you are borrowing at is ");
System.out.print(interestRate[3]=15);
System.out.println(" %.");
System.out.println(interestRate[3]/=100);
}
else
System.out.println("Too much money");
int time=Integer.parseInt (text[1]);
int time1[]=new int[11];
time1[time]=time;
System.out.println("For how long would you like the loan for.");
System.out.println("Your options are 1 year, 2 years, 5 years, or 10 years.");
if (time==1)
{
System.out.print("\n" + "You will have to pay interest for 1 year, compounded monthly, for ");
System.out.print(time1[time]*=12);
System.out.println(" periods.");
}
else if (time==2)
{
System.out.print("\n" + "You will have to pay interest for 2 years, compounded quartly, for ");
System.out.print(time1[time]*=3);
System.out.println(" periods.");
}
else if (time==5)
{
System.out.print("\n" + "You will have to pay interest for 5 years compounded Semi annually, for ");
System.out.print(time1[time]*=2);
System.out.println(" periods.");
}
else if (time==10)
{
System.out.print("\n" + "You will have to pay interest for 10 years, annually, for ");
System.out.print(time1[time]*=1);
System.out.println(" periods.");
}
else
System.out.println("We dont offer that year.");
double payment=Double.parseDouble(text[2]);
System.out.println("\n" + "How much money will you pay each period?");
System.out.println("I would like to pay $ " + payment);
for(int interestPeriod=1; interestPeriod<=time1[time]; interestPeriod++)
{
}
}
} |
|
|
|
|
|
Sponsor Sponsor
|
|
|
TheGuardian001
|
Posted: Thu May 27, 2010 4:00 pm Post subject: Re: keyboard input help |
|
|
1)Use code tags when posting code:
code: |
[code="java"]
Java code goes here
[/code]
|
2)That depends. Is this program console based or GUI based (using awt/swing/etc).
If it's console based, you can create a new java.util.Scanner(System.in), and then use the readln() method to read lines of input.
If your program is GUI based, you can have your class extend java.awt.event.KeyListener, and use addKeyListener(this) to register a keylistener, then override the methods from java.awt.event.KeyListener |
|
|
|
|
|
Unnamed.t
|
Posted: Thu May 27, 2010 5:15 pm Post subject: Re: keyboard input help |
|
|
TheGuardian001 has two good ideas, but if your using RTP IDE then the java package 1.7 won't support those mehods of inputs. My suggestion is to have the System.in IO stream inside a BufferedReader. I'm not sure how it works but the statement should look something like this.
Use the .readLine () method for input. |
|
|
|
|
|
|
|