(Q) 다음 데이터를 요구사항에 맞게 구조화하고 출력하세요
- 재생 수가 10만이 넘어가면 제목 옆에 "베스트"라고 출력
- 좋아요 수가 10만이 넘어가면 제목 옆에 "인기곡"이라고 출력
- 차트 랭킹 계산 공식이 다음과 같을 때 랭킹 점수를 구하여 추가로 출력
** 랭킹 점수 = 재생수 * 2 + 좋아요 / 2
Song 클래스
package day09_oop.method7;
public class Song {
// 멤버 필드
String name;
String singer;
String album;
int play;
int like;
// 세팅 메소드
void setting(String name, String singer, String album, int play, int like) {
this.name = name;
this.singer = singer;
this.album = album;
this.play = play;
this.like = like;
}
// 출력 메소드
void print() {
System.out.print("제목 : " + this.name);
if(this.play >= 100000) {
System.out.print("(베스트)");
}
if(this.like >= 100000) {
System.out.print("(인기곡)");
}
System.out.println();
System.out.println("가수 : " + this.singer);
System.out.println("앨범 : " + this.album);
System.out.println("재생수 : " + this.play);
System.out.println("좋아요수 : " + this.like);
int rankScore = (this.play * 2) + (this.like / 2);
System.out.println("랭킹점수 : " + rankScore);
System.out.println();
}
}
Test01
package day09_oop.method7;
public class Test01 {
public static void main(String[] args) {
// 객체 생성
Song a = new Song();
a.setting("그때 그 순간 그대로(그그그)", "WSG워너비", "WSG워너비 1집", 104250, 91835);
Song b = new Song();
b.setting("보고싶었어", "WSG워너비", "WSG워너비 1집", 83127, 90805);
Song c = new Song();
c.setting("LOVE DIVE", "IVE(아이브)", "LOVE DIVE", 64590, 174519);
Song d = new Song();
d.setting("POP!", "나연(TWICE)", "IM NAYEON", 58826, 70313);
// 출력
a.print();
b.print();
c.print();
d.print();
}
}
'국비교육 > 국비교육 복습' 카테고리의 다른 글
Day10_oop.setter2 : setter의 활용 (★) (0) | 2022.08.07 |
---|---|
Day10_oop.constructor2 : 생성자 연습 + 오버로딩 (★) (0) | 2022.08.07 |
Day09_oop.method6 : 메소드 연습 (5) (0) | 2022.08.07 |
Day09_oop.method5 : 메소드 연습 (4) (0) | 2022.08.07 |
Day09_oop.method4 : 메소드 연습 (3) (0) | 2022.08.07 |