문제 1

package com.group.libraryapp.dto.calculator.request;
public class CalculatorRequest {
private final int num1;
private final int num2;
public CalculatorRequest(int num1, int num2) {
this.num1 = num1;
this.num2 = num2;
}
public int getNum1() {
return num1;
}
public int getNum2() {
return num2;
}
}
package com.group.libraryapp.dto.calculator.response;
import com.group.libraryapp.dto.calculator.request.CalculatorRequest;
public class CalculatorResponse {
private final int add;
private final int minus;
private final int multiply;
public CalculatorResponse(CalculatorRequest request) {
this.add = request.getNum1() + request.getNum2();
this.minus = request.getNum1() - request.getNum2();
this.multiply = request.getNum1() * request.getNum2();
}
public int getAdd() {
return add;
}
public int getMinus() {
return minus;
}
public int getMultiply() {
return multiply;
}
}
@GetMapping("/api/v1/calc")
public CalculatorResponse calc(CalculatorRequest request){
return new CalculatorResponse(request);
}
문제2

package com.group.libraryapp.dto.day.response;
import java.time.LocalDate;
import java.time.format.TextStyle;
import java.util.Locale;
public class DayResponse {
private String dayOfTheWeek;
public DayResponse(String dateString) {
LocalDate date = LocalDate.parse(dateString);
this.dayOfTheWeek = date.getDayOfWeek().getDisplayName(TextStyle.SHORT, Locale.US);
}
public String getDayOfTheWeek() {
return dayOfTheWeek;
}
}
@GetMapping("/api/v1/day-of-the-week")
public DayResponse dayOfTheWeek(@RequestParam String day){
return new DayResponse(day);
}
문제3