-
Notifications
You must be signed in to change notification settings - Fork 1
/
Profile3.java
257 lines (219 loc) · 5.29 KB
/
Profile3.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
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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
import java.util.ArrayList;
public class Profile3 {
private String username;
private String password;
public int cash = 200;
public ArrayList<Integer[]> memes = new ArrayList<Integer[]>();
private static int date;
public ArrayList<Integer> amounts = new ArrayList<Integer>();
public Profile3(String username, String password)//, int cash, ArrayList<MemeStock> memes, ArrayList<Integer> amounts)
{
this.username = username;
this.password = password;
//this.cash = cash;
//this.memes = memes;
//this.date = date;
//this.amounts = amounts;
}
public ArrayList<Integer[]> getMemeList()
{
return memes;
}
public ArrayList<Integer> getAmounts()
{
return amounts;
}
public static void setDate(int today)
{
date = today;
}
private static boolean equalValues(Integer[] array1, Integer[] array2)
{
for(int i = 0; i < array1.length; i++)
{
//System.out.println(array1[i]);
//System.out.println(array2[i]);
//Integer arr1 = array[i];
//Integer arr2 = array
int arr1 = array1[i].intValue();
int arr2 = array2[i].intValue();
if(arr1 != arr2)
{
return false;
}
else
{
continue;
}
}
return true;
}
private int indexOfMeme(Integer[] other)
{
int index = -1;
for(int i = 0; i < memes.size(); i++)
{
if(Profile3.equalValues(other, memes.get(i)))
{
index = i;
break;
}
else
{
continue;
}
}
return index;
}
public void buy(Integer[] meme, int amount)
{
if(indexOfMeme(meme) > -1)
{
amounts.set(indexOfMeme(meme), amounts.get(indexOfMeme(meme)) + amount);
}
else
{
memes.add(meme);
amounts.add(amount);
}
//cash -= meme.getValue(date)*amount;
cash -= meme[date]*amount;
}
public void sell(int index, int amount)
{
if(index < 0 || index >= memes.size()) {
throw new IndexOutOfBoundsException();
}
else
{
//cash += memes.get(index).getValue(date)*amount;
Integer[] meme = memes.get(index);
cash += meme[date]*amount;
if(amount < amounts.get(index))
{
amounts.set(index, amounts.get(index) - amount);
}
else
{
memes.remove(index);
amounts.remove(index);
}
}
/**
else if(amount < amounts.get(index))
{
//amountIndex = amounts.get(index);
amounts.set(index, amounts.get(index) - amount);
cash += memes.get(index).getValue(date)*amount;
}
else
{
memes.remove(index);
amounts.remove(index);
}
**/
}
private int getPrice(Integer[] meme, int date){
return meme[date];
}
public Boolean correctTransaction(Integer[] meme, int day, int userCash, int shares){
int price = getPrice(meme, day);
int totalCost = price * shares;
if(totalCost >= userCash){
return true;
}
else {
return false;
}
}
public int sellDifference(Integer[] meme, int startDate, int currentDate){
//could implement a percentage value or total difference in price
int ogPrice = getPrice(meme, startDate);
int currentPrice = getPrice(meme, currentDate);
int difference = currentPrice - ogPrice;
return difference;
}
public String getLogin()
{
return username;
}
public String getPassword()
{
return password;
}
public int worth()
{
int worth = cash;
for(int i = 0; i < memes.size(); i++)
{
Integer[] meme = memes.get(i);
worth += meme[date]*amounts.get(i);
}
return worth;
}
/*
public String toString()
{
String memeString = "Meme Stocks:\n";
for (MemeStock meme: memes)
{
memeString += meme;
}
return "Profile for: " + username + "\ncash: " + cash + "\ntotalValue
}
*/
private static String toStr(Integer[] meme)
{
String numString = "{";
for(int num: meme)
{
String str = Integer.toString(num);
numString += str + " ";
}
numString += "}";
return numString;
}
public void printInfo()
{
System.out.println("cash: " + cash);
System.out.println("worth: " + worth());
System.out.println("********MEME STOCKS********");
for(int i = 0; i < memes.size(); i++)
{
System.out.println("\n\tmeme: " + Profile3.toStr(memes.get(i)) + "\n\tshares: " + amounts.get(i));
}
System.out.println("****************************\n");
}
public static void main(String[] args)
{
Integer[] meme1array = {10, 12, 18, 29, 22, 23, 9, 11};
Integer[] meme2array = {5, 9, 25, 39, 27, 15, 15, 7};
Integer[] meme3array = {30, 20, 18, 24, 10, 5, 8, 22};
Integer[] meme4array = {5, 9, 25, 39, 27, 15, 15, 7};
//MemeStock meme1 = new MemeStock("$SP", meme1array);
//MemeStock meme2 = new MemeStock("$DRK", meme2array);
//MemeStock meme3 = new MemeStock("$TOM", meme3array);
//MemeStock meme4 = new MemeStock("$DRK", meme4array);
//ArrayList<MemeStock> memes = new ArrayList<MemeStock>();
//memes.add(meme1);
//memes.add(meme2);
//ArrayList<Integer> amounts = new ArrayList<Integer>();
//amounts.add(4);
//amounts.add(1);
Profile3 p = new Profile3("dyeh", "dyeh");
Profile3.setDate(5);
//p.buy(meme1array, 4);
p.buy(meme1array, 4);
p.printInfo();
p.buy(meme2array, 1);
p.printInfo();
p.buy(meme3array, 3);
p.printInfo();
p.sell(2, 3);
p.printInfo();
p.buy(meme4array, 2);
p.printInfo();
p.sell(0, 2);
p.printInfo();
}
}