https://github.com/woowacourse-precourse/java-onboarding/pull/1375
https://github.com/woowacourse-precourse/java-onboarding/pull/1084/files
https://github.com/woowacourse-precourse/java-onboarding/pull/657/files
[Java] 래퍼 클래스(Wrapper Class)란 무엇인가? (박싱, 언박싱)
두줄과 밑 java 파일의 final 필드에 대해Google Java Style Guide를 따른다면 Constant(static final)의 경우 _로 합친 전체 대문자 단어로 네이밍을 하고 단순 final(non static)이나 static(non final)의 경우는 lowerCamelCase로 네이밍을 하는게 옳은 것 같습니다!참조 링크: https://google.github.io/styleguide/javaguide.html#s5.2.4-constant-names
package onboarding;
import java.util.List;
class Problem1 {
private static final int EXCEPTION = -1;
private static final int DRAW = 0;
private static final int POBIWINS = 1;
private static final int CRONGWINS = 2;
public static int solution(List<Integer> pobi, List<Integer> crong) {
Spread pobisPages;
Spread crongsPages;
try {
pobisPages = new Spread(pobi);
crongsPages = new Spread(crong);
} catch (IllegalArgumentException e) {
return (EXCEPTION);
}
return result(pobisPages.score(), crongsPages.score());
}
private static int result(int pobi, int crong) {
if (pobi == crong) {
return (DRAW);
}
return (pobi > crong) ? POBIWINS : CRONGWINS;
}
}
class Spread {
private final Page LEFT;
private final Page RIGHT;
Spread(List<Integer> player) {
if (player.size() != 2) {
throw new IllegalArgumentException();
}
int left = player.get(0);
int right = player.get(1);
if (left < 1 || 399 < left || left % 2 == 0 || right != left + 1) {
throw new IllegalArgumentException();
}
LEFT = new Page(left);
RIGHT = new Page(right);
}
int score() {
int leftScore = LEFT.getScore();
int rightScore = RIGHT.getScore();
return Math.max(leftScore, rightScore);
}
private static class Page {
private final int NUMBER;
Page(int number) {
this.NUMBER = number;
}
private int getScore() {
return Math.max(addDigits(), multiplyDigits());
}
private int addDigits() {
int number = NUMBER;
int sum = 0;
while (number > 0) {
sum += number % 10;
number /= 10;
}
return sum;
}
private int multiplyDigits() {
int number = NUMBER;
int product = 1;
while (number > 1) {
product *= number % 10;
number /= 10;
}
return product;
}
}
}
// 함수형 프로그래밍
private static int[] toIntArray(int number) {
String str = String.valueOf(number);
int[] numbers = Arrays.stream(str.split("")).mapToInt(Integer::parseInt).toArray();
return numbers;
}
// 페이지를 입력 받아 각 자리 숫자를 더하는 기능
private static int plusPerSite(int input){
String strInput = Integer.toString(input);
int result = 0;
for(String str: strInput.split("")) {
result += Integer.parseInt(str);
}
return result;
}
// 페이지를 입력 받아 각 자리 숫자를 곱하는 기능
private static int multiplePerSite(int input){
String strInput = Integer.toString(input);
int result = 1;
for(String str: strInput.split("")){
result *= Integer.parseInt(str);
}
return result;
}