To my knowledge there isn't a standard for this, but since it's a formatting question I'll address my preference for writing what you have and reasoning forbehind it.
String message = (
!isNameBlank
&& !isDestinationBlank
&& isDestinationValid
&& isAmountValid)
? "Have a safe trip!" : "Please try again!";
- variable declaration includes open parentheses and indicates something follows and is reminiscent of similar style for code blocks.
- Each clause is on its own line which makes them both easily readable and modifiable regardless of the statement length.
- The && and || operators are at the beginning of the line, this is conventional and preferable when clause names are long, or nested
- Ternary operator is lined up to initial declaration indicative of its end, and precedes the typical two returns on the same line.
Without more information I can't be too specific, but from the comments below your question, it seems like this would ideally be fully encapsulated into its own Trip
class. In which validate
is a method, or the constructor itself handles validation before instantiating the object.