Skip to content

Commit

Permalink
Merge pull request #215 from NGXZS/DGv2
Browse files Browse the repository at this point in the history
Fix ^D bug in sayHi()
  • Loading branch information
NGXZS authored Apr 16, 2024
2 parents 3cf419c + 4e129d3 commit 9673b22
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/main/java/seedu/duke/Ui.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public class Ui {
private static final String MESSAGE_CHOOSE_TOPIC = "Please choose a topic to play:";
private static final String MESSAGE_RANDOM_TOPIC = "Randomly select a topic for me ;)";
private static final String MESSAGE_ANSWER_FORMAT = "Your answer must be either a, b, c, or d!";
private static final String MESSAGE_UNKNOWN_USER_NAME = "Unknown User";
private static final String ANSWER_TIMEOUT = "You ran out of time!";
private static final String RESUME = "resume";
private static final String INVALID_INPUT = "Invalid input. Please type 'yes' or 'no'";
Expand Down Expand Up @@ -501,6 +502,7 @@ public void sayHi() {

System.out.println("Hello from\n" + logo);

// asks for userName till a valid one is given
String userName = "";
while (true) {
System.out.println(MESSAGE_ASK_FOR_NAME);
Expand All @@ -510,17 +512,22 @@ public void sayHi() {
}
System.out.println(MESSAGE_ASK_FOR_NAME_AGAIN);
}
// process UserName
String trimmedUserName = userName.trim();
String userNameToPrint;
if (isInteger(userName.trim())) {
if (isInteger(userName.trim())) { // if userName is a number
userNameToPrint = MESSAGE_NUMBER_USER_NAME + trimmedUserName;
} else if (trimmedUserName.contentEquals("")) { // handle ^D
userNameToPrint = MESSAGE_UNKNOWN_USER_NAME;
} else {
userNameToPrint = trimmedUserName;
}

System.out.println("Hello " + userNameToPrint);
printLine();
}


/**
* Checks if userName is an Integer
*
Expand Down

0 comments on commit 9673b22

Please sign in to comment.