Welcome to the CSC Q&A, on our server named in honor of Ada Lovelace. Write great code! Get help and give help!
It is our choices... that show what we truly are, far more than our abilities.

Categories

+12 votes

If you press the new game button and then press done, even if you didn't fill out any fields related to the team names or the game type, it still prints something and displays it on the game list. I believe that normally it should display an error message, so could this be a bug in the code?

asked in CSC305 Fall 2022 by (1 point)
reshown by

1 Answer

+5 votes

Even if you don't enter anything, there are values being passed into the constructor; an empty TextBox contains an empty String. If you wanted the Game constructor to throw an error if it receives an empty string, you pretty much just tell Java that, like this:

if (homeTeam.equals(""))
    throw new IllegalArgumentException("Home Team cannot be left blank");
this.homeTeam = homeTeam;
answered by (1 point)
+2

Oh I see why! thank you!

...