Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | |||||
| 3 | 4 | 5 | 6 | 7 | 8 | 9 |
| 10 | 11 | 12 | 13 | 14 | 15 | 16 |
| 17 | 18 | 19 | 20 | 21 | 22 | 23 |
| 24 | 25 | 26 | 27 | 28 | 29 | 30 |
| 31 |
Tags
- 자바
- 건강
- 코테
- binary search
- 시뮬레이션
- 백준
- COS PRO
- oracle
- 알고리즘
- SQL
- 이분탐색
- BFS
- 운동기록
- 문제해결
- 코딩테스트
- math
- priorityqueue
- greedy
- db
- 프로그래머스
- SWEA
- 문제풀이
- 문자열
- MySQL
- 러닝일지
- DP
- Java
- dfs
- 투포인터
- BOJ
Archives
- Today
- Total
슈콩
COS PRO 1급 JAVA 도서 대여점 운영 본문
[문제]




[소스 코드]
class Main {
interface Book{
public int getRentalPrice(int day);
}
class ComicBook implements Book {
public int getRentalPrice(int day) {
int cost = 500;
day -= 2;
if(day > 0)
cost += 200 * day;
return cost;
}
}
class Novel implements Book {
public int getRentalPrice(int day) {
int cost = 1000;
day -= 3;
if(day > 0)
cost += 300 * day;
return cost;
}
}
public int solution(String[] bookTypes, int day) {
Book[] books = new Book[50];
int length = bookTypes.length;
for(int i = 0; i < length; ++i){
if(bookTypes[i].equals("comic"))
books[i] = new ComicBook();
else if(bookTypes[i].equals("novel"))
books[i] = new Novel();
}
int totalPrice = 0;
for(int i = 0; i < length; ++i)
totalPrice += books[i].getRentalPrice(day);
return totalPrice;
}
}