노래를 나타내는 Song이라는 클래스를 설계하세요.
<필드>
노래제목 title
가수 artist
앨범제목 album
작곡가 composer
노래가 발표된 연도 year
노래가 속한 앨범에서의 트랙 번호를 나타내는 track
<메서드>
노래의 정보를 저장하는 setSongInfo(...) : 관련된 매개변수를 인자로 넘겨줌
노래의 정보를 나타내는 show()
ABBA의 "Dancing Queen"노래를 Song객체로 생성하고
Show()로 출력하세요
package homework;
class Song {
private String title;
private String artist;
private String album;
private String composer;
private int year;
private int track;
void setSongInfo(String titleInfo, String artistInfo, String albumInfo,
String composerInfo, int yearInfo, int trackInfo) {
// 노래 정보를 매개변수로 받아서 저장하는 메소드
title = titleInfo;
artist = artistInfo;
album = albumInfo;
composer = composerInfo;
year = yearInfo;
track = trackInfo;
}
void show() { // 노래 객체에 있는 정보들을 출력하는 메소드
System.out.println("노래 제목: " + title);
System.out.println("가수: " + artist);
System.out.println("앨범 제목: " + album);
System.out.println("작곡가: " + composer);
System.out.println("노래가 발표된 연도: " + year);
System.out.println("트랙 번호: " + track);
}
}
public class SongMain {
public static void main(String[] args) {
Song Dancing_Queen = new Song(); // Dancing Queen이라는 객체를 생성
Dancing_Queen.setSongInfo("Dancing Queen", "ABBA",
"Dancing Queen & That's Me", "베니 안데르손, 비에른 울바에우스",
1976, 6);// setSongInfo 메서드에 곡 정보들을 넘겨준다. // 넘겨줌
Dancing_Queen.show(); // 곡 정보를 출력하는 메서드 호출
}
}
'etc.. > 1' 카테고리의 다른 글
static 예제 (0) | 2020.01.14 |
---|---|
200114_여러개 생성자 호출 예제 (0) | 2020.01.14 |
200114_사각형 클래스 작성 (0) | 2020.01.14 |
200113_소수 판별 (0) | 2020.01.13 |
200113_10진수 입력받아서 2진수로 출력 (0) | 2020.01.13 |