컴퓨터/Java
[Java] 자동차 클래스 만들기, 자동차 객체 사용하기
peridott
2024. 7. 17. 14:30
package _03_tv;
public class T01_api_tv {
String company = "LG";
String model = "울트라 FULL HD";
int inch = 65;
int volume; // 기본값 : 0
int channel = 2;
boolean power; // 기본값 : false
void power() {
power = !power;
if(power)
System.out.println("tv를 켭니다");
else
System.out.println("tv를 끕니다");
}
int channelUp() {
channel++;
return channel;
}
int channelDown() {
channel--;
return channel;
}
int volume(int volumeInput) {
volume = volumeInput;
return volume;
}
}
package _03_tv;
public class T01_main_tv {
public static void main(String[] args) {
T01_api_tv tv1 = new T01_api_tv();
System.out.println("회사명 : " + tv1.company);
System.out.println("모델명 : " + tv1.model);
System.out.println(tv1.inch + "인치");
tv1.power();
//System.out.println("tv상태 : " + tv1.power);
System.out.println("현재 채널 : " + tv1.channelUp());
System.out.println("현재 채널 : " + tv1.channelUp());
System.out.println("현재 채널 : " + tv1.channelDown());
System.out.println("볼륨 : " + tv1.volume(12));
tv1.power();
// System.out.println("tv상태 : " + tv1.power);
}
}