1
1
package algorithms .trading ;
2
2
3
3
import java .text .DecimalFormat ;
4
+ import java .text .NumberFormat ;
4
5
5
6
public class WithoutInvesting {
6
7
public static void main (String [] args ) {
@@ -13,11 +14,16 @@ public static void main(String[] args) {
13
14
14
15
int retirementAmount = 0 ;
15
16
int investedRetirementAmount = 0 ;
17
+ NumberFormat nf = DecimalFormat .getInstance ();
18
+ System .out .printf ("%8s %10s %10s %10s\n " ,"Year" ,"Income" ,"Expense" ,"Cash Retained" );
16
19
for (int i = 2 ; i <= 30 ; i ++) {
17
20
18
21
save *=12 ;
19
22
retirementAmount += save ;
20
23
investedRetirementAmount += save ;
24
+ System .out .printf ("%8d %10s %10s %10s" ,
25
+ i ,nf .format (sal *12 ),nf .format (sal *12 -save ),nf .format (retirementAmount ));
26
+ System .out .println ();
21
27
// System.out.println("salary : " + sal);
22
28
// System.out.println("save : " + save);
23
29
sal = sal + ((sal *inc )/100 );
@@ -26,8 +32,10 @@ public static void main(String[] args) {
26
32
//if he invests in some schemenwith 12 % return.
27
33
investedRetirementAmount +=(investedRetirementAmount *12 /100 );
28
34
35
+
29
36
}
30
37
38
+ System .out .println ();
31
39
System .out .println ("Man saves " + DecimalFormat .getInstance ().format ( retirementAmount ) + " if he does not invest anywhere." );
32
40
System .out .println ("Man saves " + DecimalFormat .getInstance ().format (investedRetirementAmount ) + " if he invests at 12 % per annum." );
33
41
}
0 commit comments