
+--------------+
| BankAccount | ref1, ref2
| balance: 0 | <--------------+
+--------------+ |
|
|
public static void main(String[] args) {
TV myTV = new TV("LG", 2017, 32); //LG에서 만든 2017년 32인치
myTV.show();
}
//출력
LG에서 만든 2017년형 32인치 TV
public class TV {
String brand;
int year;
int inch;
public TV(String brand, int year, int inch) {
this.brand = brand;
this.year = year;
this.inch = inch;
}
public void show() {
System.out.println(brand + "에서 만든 " + year + "년형 " + inch + "인치 TV");
}
public static void main(String[] args) {
TV myTV = new TV("LG", 2017, 32); // LG에서 만든 2017년 32인치
myTV.show();
}
}
public static void main(String[] args) {
int math, science, english;
math = 90;
science = 80;
english = 80;
Grade me = new Grade(math, science, english);
System.out.println("평균은 " + me.average());
System.out.println(me.getGrade()); //우 입니다.
public class Grade {
int math;
int science;
int english;
public Grade(int math, int science, int english) {
this.math = math;
this.science = science;
this.english = english;
}
public double average() {
return (math + science + english) / 3.0;
}
public String getGrade() {
double avg = average();
if (avg >= 90) {
return "우";
} else {
return "미만";
}
}
public static void main(String[] args) {
int math = 90, science = 80, english = 80;
Grade me = new Grade(math, science, english);
System.out.println("평균은 " + me.average());
System.out.println(me.getGrade()); // 우 입니다.
}
}
또한 Song 클래스에 다음 생성자와 메소드를 작성하라.
Song 객체로 생성하고
show()를 이용하여 노래의 정보를 다음과 같이 출력하라.
출력:
1978년, 스웨덴 국적의 ABBA가 부른 "Dancing Queen"
public class Song {
String title;
String artist;
int year;
String country;
public Song() {
}
public Song(String title, String artist, int year, String country) {
this.title = title;
this.artist = artist;
this.year = year;
this.country = country;
}
public void show() {
System.out.println(year + "년, " + country + " 국적의 " + artist + "가 부른 \"" + title + "\"");
}
public static void main(String[] args) {
Song song = new Song("Dancing Queen", "ABBA", 1978, "스웨덴");
song.show();
}
}