-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAnnuities.java
More file actions
197 lines (181 loc) · 7.43 KB
/
Copy pathAnnuities.java
File metadata and controls
197 lines (181 loc) · 7.43 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
import java.util.*;
import java.lang.*;
import java.io.*;
public class Annuities {
private static Scanner input = new Scanner(System.in);
private static ArrayList<String[]> annuities = new ArrayList<String[]>();
public static void menu() throws IOException{
System.out.println("--------------------");
System.out.println("What would like to do?");
int choice = 0;
do{
System.out.println("1. Buy An Annuity (Non Tradable)");
System.out.println("2. View Owned Annuities");
System.out.println("3. Go Back.");
System.out.print("Enter Choice: ");
choice = input.nextInt();
}
while(choice < 0 || choice > 3);
if(choice == 1){
annuitiesmain();
}
else if(choice == 2){
viewannuities();
}
else if(choice == 3){
InvestorsAccount.investormenu();
}
}
public static void annuitiesmain() throws IOException{
System.out.println("--------------------");
System.out.println("What would like to name this annuity? ");
String name = input.next();
System.out.println("--------------------");
System.out.println("Here are our insurance investment options:");
System.out.println("1. Insurance 1:");
System.out.println(" - Rate (Interest rate) - 4%");
System.out.println(" - Years (Time for payout) - 1 year");
System.out.println();
System.out.println("2. Insurance 2:");
System.out.println(" - Rate (Interest rate) - 5.15%");
System.out.println(" - Years (Time for payout) - 1 year");
System.out.println();
System.out.println("3. Insurance 3:");
System.out.println(" - Rate (Interest rate) - 3.8%");
System.out.println(" - Years (Time for payout) - 2 years");
System.out.println("");
int choice = -1;
input.nextLine();
while(choice < 0 || choice > 3){
System.out.print("Please enter the number of the insurance option you would like to pick: ");
choice = input.nextInt();
System.out.println("--------------------");
}
Boolean overDraft = false;
double investment = 0.0;
do{
System.out.print("How much do you want to invest: $");
investment = input.nextDouble();
Transactions.amount = investment;
overDraft = Transactions.overdraft();
}
while(overDraft == true);
Double finalinvestment = 0.0;
int term = 0;
double interest = 0.0;
if(choice == 1){
term = 1;
interest = 4;
finalinvestment = Math.round((investment * Math.pow((1 + .04), 1))*100.00)/100.00;
}
else if(choice == 2){
term = 1;
interest = 5.15;
finalinvestment = Math.round((investment * Math.pow((1 + .0515), 1))*100.00)/100.00;
}
else{
term = 2;
interest = 3.8;
finalinvestment = Math.round((investment * Math.pow((1 + .038), 2))*100.00)/100.00;
}
System.out.print("Confirm (y/n)? ");
String confirm = input.next();
if(confirm.contains("y")){
System.out.println("Confirming Your Investment...");
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("--------------------");
System.out.println("Your investment was successful! Your investment will be worth $" + finalinvestment + " after the term is over.");
System.out.println("--------------------");
MoneyMarket.name = name;
MoneyMarket.typeOfInvestment = "Annuities";
MoneyMarket.investmentamount = Math.round(investment * 100.00)/100.00;
MoneyMarket.term = term;
MoneyMarket.interest = interest;
MoneyMarket.totalinvestment = Math.round(finalinvestment*100.00)/100.00;
MoneyMarket.tradeable = "no";
try {
MoneyMarket.investments();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Transactions.investmenttype = "Annuity";
try {
Transactions.investmentclass();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("--------------------");
}
else{
System.out.println("Canceling your investment...");
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("Your investment was canceled.");
System.out.println("--------------------");
InvestorsAccount.investormenu();
}
}
public static void viewannuities() throws IOException{
readfile();
System.out.println("--------------------");
if(annuities.size() != 0){
int i = 1;
for(String annuity[]: annuities){
System.out.println(i + ". " + annuity[0]);
i++;
}
int choice = 0;
do{
System.out.print("Which annuity would you like to see: ");
choice = input.nextInt();
}
while(choice < 0 || choice > i);
System.out.println("--------------------");
System.out.println("Name: " + annuities.get(choice - 1)[0]);
System.out.println("Investment Amount: $" + annuities.get(choice - 1)[2]);
System.out.println("Term: " + annuities.get(choice - 1)[3] + " Years");
System.out.println("Interest: " + annuities.get(choice - 1)[4] + "%");
System.out.println("Final Investment Amount: $" + annuities.get(choice - 1)[5]);
System.out.println("Tradable? " + annuities.get(choice - 1)[6]);
System.out.println("--------------------");
menu();
}
else{
System.out.println("--------------------");
System.out.println("You do not own any annuities.");
System.out.println("--------------------");
menu();
}
}
public static void readfile() throws IOException{
annuities.clear();
String filename = Data.generaldata.get(0) + "Investments.csv"; //names csv file based on username
File file = new File(filename); //describing the file
FileWriter fw = new FileWriter(file , true);
FileReader fr = new FileReader(file);
BufferedWriter bw = new BufferedWriter(fw);
BufferedReader br = new BufferedReader(fr);
String line = "";
while((line = br.readLine()) != null){
String values[] = line.split(",");
if(values[1].equals("Annuities")){
annuities.add(values);
}
}
br.close();
bw.close();
fr.close();
fw.close();
}
}