How can we get the boolean expression of a basic singleton with hashsets to return a message in lieu of the original 'true' or 'false'?
public boolean bookLane(String lane) {
return runLane.remove(lane);
}
I want to only replace the true or false return statements with a message.
To help clarify this question, something like below (i know it doesn't work) is the direction I am wanting to go...
public boolean bookLane(String lane) {
if (true)
{
message = "Lane is available. Adding runner...";
//instead of true
}
else
{
message = "Lane unavailable. Please choose another";
//instead of false
}
return runLane.remove(lane);
}
I just tried messing with the code and found that it only returns false now.
public boolean bookLane(String lane) {
String message1 = "Lane Available. Adding runner...";
String message2 = "Lane is Unavailable.";
if (runLane.remove(lane))
{
System.out.println(message1);
}
else
{
System.out.println(message2);
}
return runLane.remove(lane);//
}
Any ideas on fixing it? Not gonna lie, my experience with Java is mainly trial and error with a little help from more experienced programmers. I think this method could work if someone could let me know what I am missing as far as how boolean methods work with more than just the one return type. I am trying to target the return value for displaying the appropriate message with the returned boolean. Is this route even possible? Am I missing some logic in how boolean methods work or something? Please understand my frustration and my need for yalls help. thanks for the guidance given...