Skip to content

Commit

Permalink
Changing String format for String concatenation on reference resoluti…
Browse files Browse the repository at this point in the history
…ons of concept exercises (#2744)
  • Loading branch information
manumafe98 authored Mar 4, 2024
1 parent 16209ef commit b28dbe2
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public boolean isAfternoonAppointment(LocalDateTime appointmentDate) {

public String getDescription(LocalDateTime appointmentDate) {
var formatter = DateTimeFormatter.ofPattern("EEEE, MMMM d, yyyy, 'at' h:mm a", Locale.ENGLISH);
return String.format("You have an appointment on %s.", formatter.format(appointmentDate));
return "You have an appointment on " + formatter.format(appointmentDate) + ".";
}

public LocalDate getAnniversaryDate() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ public String calculate(int operand1, int operand2, String operation) {
throw new IllegalOperationException("Division by zero is not allowed", e);
}
}
default -> throw new IllegalOperationException(String.format("Operation '%s' does not exist", operation));
default -> throw new IllegalOperationException("Operation '" + operation + "' does not exist");
}

return String.format("%d %s %d = %s", operand1, operation, operand2, result);
return String.valueOf(operand1) + " " + String.valueOf(operation) + " " + operand2 + " = " + result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public void divisionWithLargeOperands() {
@DisplayName("The calculate method throws IllegalOperationException when passing invalid operation")
public void throwExceptionForUnknownOperation() {
String invalidOperation = "**";
String expectedMessage = String.format("Operation '%s' does not exist", invalidOperation);
String expectedMessage = "Operation '" + invalidOperation + "' does not exist";
assertThatExceptionOfType(IllegalOperationException.class)
.isThrownBy(() -> new CalculatorConundrum().calculate(3, 78, invalidOperation))
.withMessage(expectedMessage);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ char randomPlanetClass() {
String randomShipRegistryNumber() {
var start = 1000;
var end = 10000;
return String.format("NCC-%d", start + random.nextInt(end - start));


return "NCC-" + String.valueOf(start + random.nextInt(end - start));
}

double randomStardate() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ public LogLevel getLogLevel() {
}

public String getOutputForShortLog() {
return String.format("%d:%s", this.level.getEncodedLevel(), this.message);
return String.valueOf(this.level.getEncodedLevel()) + ":" + this.message;
}
}

0 comments on commit b28dbe2

Please sign in to comment.