Hexagonal pattern: Improve error handling in console lottery

This commit is contained in:
Ilkka Seppälä 2016-09-14 22:18:42 +03:00
parent 3cf2b34d2a
commit c4c5e78e50

View File

@ -79,6 +79,7 @@ public class ConsoleLottery {
PlayerDetails details = PlayerDetails.create(email, account, phone);
System.out.println("Give 4 comma separated lottery numbers?");
String numbers = readString(scanner);
try {
String[] parts = numbers.split(",");
Set<Integer> chosen = new HashSet<>();
for (int i = 0; i < 4; i++) {
@ -92,11 +93,15 @@ public class ConsoleLottery {
} else {
System.out.println("Failed submitting lottery ticket - please try again.");
}
} catch (Exception e) {
System.out.println("Failed submitting lottery ticket - please try again.");
}
} else if (cmd.equals("4")) {
System.out.println("What is the ID of the lottery ticket?");
String id = readString(scanner);
System.out.println("Give the 4 comma separated winning numbers?");
String numbers = readString(scanner);
try {
String[] parts = numbers.split(",");
Set<Integer> winningNumbers = new HashSet<>();
for (int i = 0; i < 4; i++) {
@ -111,6 +116,9 @@ public class ConsoleLottery {
} else {
System.out.println("Such lottery ticket has not been submitted.");
}
} catch (Exception e) {
System.out.println("Failed checking the lottery ticket - please try again.");
}
} else if (cmd.equals("5")) {
exit = true;
} else {