-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJava073_class.java
More file actions
66 lines (56 loc) · 1.45 KB
/
Copy pathJava073_class.java
File metadata and controls
66 lines (56 loc) · 1.45 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package java0828_class;
/*
* show()메소드를 아래와 같이 출력이 되도록 구현하세요.
*
* [실행 결과]
* 노래 제목: Dancing Queen
* 가수 : ABBA
* 앨범 : Arrival
* 작곡가 : Benny Andersson, Bjorn Ulvaeus
* 년도 : 1977
* 트랙 번호 : 2
*/
class Song {
String title;
String artist;
String album;
String[] composer;
int year;
int track;
public Song() {
}
public Song(String title, String artist, String album, String[] composer, int year, int track) {
super();
this.title = title;
this.artist = artist;
this.album = album;
this.composer = composer;
this.year = year;
this.track = track;
}
public void show() {
System.out.println("노래 제목 : " + title);
System.out.println("가수 : " + artist);
System.out.println("앨범 : " + album);
System.out.print("작곡가 : ");
for (int i = 0; i < composer.length; i++) {
/*
* System.out.printf("%s", composer[i]);
*
* if (i < composer.length - 1) { System.out.print(", "); } else {
* System.out.println(); }
*/
String chk = i < composer.length - 1 ? ", " : "\n";
System.out.printf("%s%s", composer[i], chk);
}
System.out.println("년도 : " + year);
System.out.println("트랙 번호 : " + track);
}
}
public class Java073_class {
public static void main(String[] args) {
Song s = new Song("Dancing Queen", "ABBA", "Arrival", new String[] { "Benny Andersson", "Bjorn Ulvaeus" }, 1977,
2);
s.show();
}
}