Q1. 노래를 추천해주는 Song 클래스를 생성하여라


< 조건 >   

1. Song 클래스의 멤버변수는 title(제목), artist(가수), year(발표년도)이다.
2. 노래 정보를 출력하는 show() 메서드를 이용하고, 메서드는 Song의 멤버변수를 파라미터로 가진다.
3. 클래스와 클래스의 메서드를 통해 main 메서드에서 세 곡의 노래를 추천해주세요!
(세 곡의 노래를 출력할 때, 객체를 세 개 생성해주시면 됩니다!)

 

 

 

A1. 달거북씨 리뷰

class Song{
	String title;	// 제목
	String artist;	// 가수
	int year;		// 발표년도
	
	public void show(String title, String artist, int year){	// 노래 정보를 출력하는 메서드
		this.title = title;
		this.artist = artist;
		this.year = year;
		System.out.println("제목 : " + this.title + " / 가수 : " + this.artist 
			+ " / 발표년도 : " + this.year);
	}
}

public class RecommendSong {

	public static void main(String[] args) {
		// 문제에 따라 객체 각각 생성
		Song rs1 = new Song();
		rs1.show("INVO", "태연", 2022);
		
		Song rs2 = new Song();
		rs2.show("I can't control myself", "태연", 2022);
		
		Song rs3 = new Song();
		rs3.show("한숨", "이하이", 2016);
		
		// 파라미터로 값을 주는 경우 객체는 한 번만 생성해도 가능        
		Song rs = new Song();
		rs.show("INVO", "태연", 2022);
		rs.show("I can't control myself", "태연", 2022);
		rs.show("한숨", "이하이", 2016);
		
	}
}
728x90

+ Recent posts