: 매일 저녁, 하루를 마무리하며 작성 !
: ⭕ 지식 위주, 학습한 것을 노트 정리한다고 생각하고 작성하면서 머리 속 흩어져있는 지식들을 정리 !
class Solution {
// 최대공약수 구하는 함수 (유클리드 호제법)
int func(int x, int y) {
int num;
while(y > 0) {
num = x % y;
x = y;
y = num;
}
return x;
}
public int[] solution(int x, int y) {
int[] answer = new int[2];
// 큰 수를 n
if(x < y) {
int temp = x;
x = y;
y = temp;
}
// 최대공약수
answer[0] = func(x, y);
// 최소공배수
answer[1] = x * y / answer[0];
return answer;
}
}
public class RamenProgram {
public static void main(String args[]) {
try {
RamenCook ramenCook = new RamenCook(Integer.parseInt(args[0]));
new Thread(ramenCook, "A").start();
new Thread(ramenCook, "B").start();
new Thread(ramenCook, "C").start();
new Thread(ramenCook, "D").start();
} catch (Exception e) {
e.printStackTrace();
}
}
}
class RamenCook implements Runnable {
private int ramenCount; // 남은 라면 수
private String[] burners = {"_", "_", "_", "_", "_"}; // 버너 상태를 나타내는 배열
public RamenCook(int count) {
ramenCount = count; // 주어진 라면 수로 초기화
}
@Override
public void run() {
while (ramenCount > 0) {
synchronized (this) {
ramenCount--; // 라면 수 감소
System.out.println(Thread.currentThread().getName() + ": " + ramenCount + "개 남음");
}
for (int i = 0; i < burners.length; i++) {
if (!burners[i].equals("_")) continue; // 버너가 사용 중이면 다음 버너로
synchronized (this) {
// 버너가 사용 가능하면 해당 버너를 점유하고 상태 출력
burners[i] = Thread.currentThread().getName();
System.out.println(
Thread.currentThread().getName()
+ ": [" + (i + 1) + "]번 버너 ON"
);
showBurners();
}
try {
Thread.sleep(2000); // 요리 시간 시뮬레이션
} catch (Exception e) {
e.printStackTrace();
}
synchronized (this) {
// 요리가 끝난 후 버너를 해제하고 상태 출력
burners[i] = "_";
System.out.println(
Thread.currentThread().getName()
+ ": [" + (i + 1) + "]번 버너 OFF"
);
showBurners();
}
break;
}
try {
Thread.sleep(Math.round(1000 * Math.random())); // 다음 반복 전 랜덤 시간 대기
} catch (Exception e) {
e.printStackTrace();
}
}
}
private void showBurners() {
// 현재 모든 버너의 상태를 출력
String stringToPrint = "";
for (int i = 0; i < burners.length; i++) {
stringToPrint += (" " + burners[i]);
}
System.out.println(stringToPrint);
}
}
Goal: "회원가입, 로그인 기능이 있는 투두앱 백엔드 서버 만들기"
엔티티 | 메서드 | 엔드포인트 | 설명 | 요청 본문 예시 | 응답 예시 |
---|---|---|---|---|---|
User | POST | /users | 사용자 생성 | {"username": "test_username", "password": "test_password", "nickname": "test_nickname", "role": "USER"} | {"id": 1, "username": "test_username", "password": "test_password", "nickname": "test_nickname", "role": "USER", "createdAt": "2024-05-31T00:00:00"} |
User | GET | /users/{id} | ID로 사용자 조회 | 없음 | {"id": 1, "username": "test_username", "password": "test_password", "nickname": "test_nickname", "role": "USER", "createdAt": "2024-05-31T00:00:00"} |
User | GET | /users | 모든 사용자 조회 | 없음 | [{"id": 1, "username": "test_username", "password": "test_password", "nickname": "test_nickname", "role": "USER", "createdAt": "2024-05-31T00:00:00"}, ...] |
User | DELETE | /users/{id} | ID로 사용자 삭제 | 없음 | 없음 |
TodoScheduler | POST | /todoschedulers | TodoScheduler 생성 | {"userId": 1, "title": "test_title", "content": "test_content", "state": false} | {"id": 1, "userId": 1, "title": "test_title", "content": "test_content", "state": false, "createdAt": "2024-05-31T00:00:00"} |
TodoScheduler | GET | /todoschedulers/{id} | ID로 TodoScheduler 조회 | 없음 | {"id": 1, "userId": 1, "title": "test_title", "content": "test_content", "state": false, "createdAt": "2024-05-31T00:00:00"} |
TodoScheduler | GET | /todoschedulers | 모든 TodoScheduler 조회 | 없음 | [{"id": 1, "userId": 1, "title": "test_title", "content": "test_content", "state": false, "createdAt": "2024-05-31T00:00:00"}, ...] |
TodoScheduler | DELETE | /todoschedulers/{id} | ID로 TodoScheduler 삭제 | 없음 | 없음 |
Comment | POST | /comments | Comment 생성 | {"todoSchedulerId": 1, "userId": 1, "content": "test_content"} | {"id": 1, "todoSchedulerId": 1, "userId": 1, "content": "test_content", "createdAt": "2024-05-31T00:00:00"} |
Comment | GET | /comments/{id} | ID로 Comment 조회 | 없음 | {"id": 1, "todoSchedulerId": 1, "userId": 1, "content": "test_content", "createdAt": "2024-05-31T00:00:00"} |
Comment | GET | /comments | 모든 Comment 조회 | 없음 | [{"id": 1, "todoSchedulerId": 1, "userId": 1, "content": "test_content", "createdAt": "2024-05-31T00:00:00"}, ...] |
Comment | DELETE | /comments/{id} | ID로 Comment 삭제 | 없음 | 없음 |