forked from samuelstacey/Financial-Tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRewards.java
More file actions
48 lines (41 loc) · 1.65 KB
/
Rewards.java
File metadata and controls
48 lines (41 loc) · 1.65 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
import java.io.IOException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
//trophy
public class Rewards {
private boolean running;
/**
* Will show all options when managing their savings pools and prompt for them to choose one
*/
public void mainMenu() throws IOException {
ResultSet rs = RetrieveAndStore.readAllRecords("tblSavings");
int count = 0;
ArrayList<String> savingNames = new ArrayList<String>();
try {
while (rs.next()) {
//Store each budget record to print
double goal = rs.getDouble("SavingsGoal");
double currentSavings = rs.getDouble("CurrentSavings");
double leftToGo = goal-currentSavings; // How far they are from their goal in £
if (currentSavings > goal) {
count++;
savingNames.add(rs.getString("SavingsAccountName"));
}
}
} catch (SQLException e) {
e.printStackTrace();
System.out.println("Error with DB");
}
if (count != 0) {
System.out.println("\nGood job, you managed to exceed your savings in the following pools:");
System.out.println(String.join(", ", savingNames));
System.out.println("\nTrophy Count \uD83C\uDFC6:" + count);
} else {
System.out.println("Oh no, looks like you haven't exceeded any savings");
System.out.println(new Tips().getTipMotivation("tip"));
}
System.out.println("Press enter to return to main menu...");
App.userIn.readLine();
}
}