-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInvest.java
64 lines (56 loc) · 1.63 KB
/
Invest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import java.io.*;
class Invest
{
public static void main(String args[])
{
Float principalAmount=new Float(0); //Converting number to object
Float interestRate=new Float(0);
int numYears=0;
try
{
DataInputStream in=new DataInputStream(System.in);
System.out.print("Enter Principal Amount : ");
System.out.flush( );
String principalString=in.readLine( );
principalAmount=Float.valueOf(principalString); //String object to number object
System.out.print("Enter Interest Rate : ");
System.out.flush( );
String interestString=in.readLine( );
interestRate=Float.valueOf(interestString);
System.out.print("Enter Number of Years : ");
System.out.flush( );
String yearsString=in.readLine( );
numYears=Integer.parseInt(yearsString); //Numeric strings to numbers
}
catch(IOException e)
{
System.out.println("I/O Error");
System.exit(1);
}
float value=loan(principalAmount.floatValue( ),interestRate.floatValue( ),numYears);
printline( );
System.out.println("Final Value = " +value);
printline( );
}
//Method to compute Final Value
static float loan(float p,float r,int n)
{
int year=1;
float sum=p;
while (year <= n)
{
sum=sum*(1+r);
year=year+1;
}
return sum;
}
//Method to draw a line
static void printline( )
{
for(int i=1;i<=30;i++)
{
System.out.print("=");
}
System.out.println(" ");
}
}