-
Notifications
You must be signed in to change notification settings - Fork 1
/
UserInput.java
168 lines (131 loc) · 5.13 KB
/
UserInput.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
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
import java.util.*;
// Gets user input
// Is the front for the terminal, all user inputs are gathered here and then transferred to other classes
//To compile in the terminal
//javac -cp /home/thegasian/Public/'Imported Libraries'/gson-2.8.5.jar *.java
//To run in the terminal
//java -cp .:/home/thegasian/Public/'Imported Libraries'/gson-2.8.5.jar UserInput.java
public class UserInput{
private static String function;
private static String symbol;
private static String stockURL;
private static Scanner userInput = new Scanner(System.in);
private static Calendar c = Calendar.getInstance();
private static String currencyFrom;
private static String currencyTo;
public static void main(String arg[]){
//ENTER GREETING HERE
findAction();
//CallAPI.getJSON(stockURL);
}
private static void findAction(){
while(true){
System.out.println("What would you like me to do? Options include the following: \n1)Estimate Closing \n2)Find stats \n3)Exchange rates");
String action = userInput.nextLine();
if(action.toLowerCase().equals("estimate closing") || action.equals("1")){
System.out.println("What Symbol would you like to look at?");
symbol = userInput.nextLine();
estimateClosing();
break;
}
else if(action.toLowerCase().equals("find stats") || action.equals("2")){
System.out.println("What Symbol would you like to look at?");
symbol = userInput.nextLine();
findStats();
break;
}
else if(action.toLowerCase().equals("exchange rates") || action.equals("3")) {
function = "CURRENCY_EXCHANGE_RATE";
exchangeRates();
break;
}
/*else if(action.toLowerCase().equals("create graph") || action.equals("4")){
activateGraph();
}*/
else{
System.out.println("Please provide a valid response. \n");
}
}
}
private static void estimateClosing(){
while(true){
System.out.println("For what time period? Options include the following: \n1)Past week \n2)Past month \n3)Past year");
String period = userInput.nextLine();
if(period.toLowerCase().equals("past week") || period.equals("1")){
function = "TIME_SERIES_DAILY";
stockURL = GenerateURL.getURL(function, symbol);
System.out.println(AnalyzeValues.estimateTomorrowClosing(CallAPI.getJSON(stockURL),0));
break;
}
else if(period.toLowerCase().equals("past month") || period.equals("2")){
function = "TIME_SERIES_WEEKLY";
stockURL = GenerateURL.getURL(function, symbol);
System.out.println(AnalyzeValues.estimateTomorrowClosing(CallAPI.getJSON(stockURL),1));
break;
}
else if(period.toLowerCase().equals("past year") || period.equals("3")){
function = "TIME_SERIES_MONTHLY";
stockURL = GenerateURL.getURL(function, symbol);
System.out.println(AnalyzeValues.estimateTomorrowClosing(CallAPI.getJSON(stockURL),2));
break;
}
else{
System.out.println("Please provide a valid response");
}
}
}
private static void findStats(){
while(true){
System.out.println("What stats would you like to find? Options include the following: \n1)Last Trading Day Stats \n2)Current price");
String chosenStat = userInput.nextLine();
function = "TIME_SERIES_DAILY";
stockURL = GenerateURL.getURL(function, symbol);
if(chosenStat.toLowerCase().equals("last trading day stats") || chosenStat.equals("1")){
if(c.get(Calendar.DAY_OF_WEEK) == 1 || c.get(Calendar.DAY_OF_WEEK) == 7){
System.out.println("The stock market is closed today! Here is the information for Friday.");
}
System.out.println(AnalyzeValues.lastTradingDayStats(CallAPI.getJSON(stockURL)));
break;
}
else if(chosenStat.toLowerCase().equals("current price") || chosenStat.equals("2")) {
if(c.get(Calendar.DAY_OF_WEEK) == 1 || c.get(Calendar.DAY_OF_WEEK) == 7){
System.out.println("The stock market is closed today! Here is the summary of prices on Friday.");
System.out.println(AnalyzeValues.lastTradingDayStats(CallAPI.getJSON(stockURL)));
break;
}
else
{
function = "TIME_SERIES_INTRADAY";
stockURL = GenerateURL.getURL(function, symbol);
System.out.println(AnalyzeValues.intradayStats(CallAPI.getJSON(stockURL)));
break;
}
}
else{
System.out.println("Please provide a valid response.");
}
}
}
// Requests input for the two currencies to find the exchange rate to
private static void exchangeRates()
{
while(true)
{
System.out.println("Please provide the currency you wish to exchange from");
currencyFrom = userInput.nextLine();
System.out.println("Please provide the currency you wish to exchange to");
currencyTo = userInput.nextLine();
stockURL = GenerateURL.getURLExchange(function, currencyFrom, currencyTo);
// prints the information returned by AnalyzeValues.foreignExchange, with the information gathered from stockURL
System.out.println(AnalyzeValues.foreignExchange(CallAPI.getJSON(stockURL)));
break;
}
}
// activates the graph activator with the information from stockURL
private static void activateGraph()
{
function = "TIME_SERIES_DAILY";
stockURL = GenerateURL.getURL(function, symbol);
//AnalyzeValues.generateGraph(stockURL);
}
}