[1번] 다음 main() 메소드와 실행 결과를 참고하여
TV를 상속받은 ColorTV 클래스를 작성하라.
public static void main(String[] args) {
ColorTV myTV = new ColorTV(32, 1024);
myTV.printProperty();
}
//결과 32인치 1024컬러
public class TV {
private int size;
public TV(int size) {
this.size = size;
}
protected int getSize() {
return size;
}
}
public class ColorTV extends TV {
private int color;
public ColorTV(int inch, int color) {
super(inch);
this.color = color;
}
public void printProperty() {
System.out.println(this.getSize() + "인치 " + this.color + "컬러");
}
}
class A{
public A(){
}
}
class B extends A{
public B(){
show();
}
}
게임시작 1
게임종료 2
1
숫자를 입력해주세요 : 50
Down ===> 9번 남아 있습니다.
숫자를 입력해주세요 : 30
Down ===> 8번 남아 있습니다.
숫자를 입력해주세요 : 15
Down ===> 7번 남아 있습니다.
숫자를 입력해주세요 : 8
Up ====> 6번 남아 있습니다.
숫자를 입력해주세요 : 9
Up ====> 5번 남아 있습니다.
숫자를 입력해주세요 : 10
Up ====> 4번 남아 있습니다.
숫자를 입력해주세요 : 11
Up ====> 3번 남아 있습니다.
숫자를 입력해주세요 : 12
Up ====> 2번 남아 있습니다.
숫자를 입력해주세요 : 13
Up ====> 1번 남아 있습니다.
숫자를 입력해주세요 : 14
일치
게임시작 1
게임종료 2
public class Game extends RandomNumber {
private int num;
private String x;
public Game(int num) {
this.num = num;
// matching();
}
String matching() {
if (num == this.value) {
// System.out.println("일치");
x = "일치";
} else if (num > this.value) {
// System.out.println("Down");
x = "Down";
} else if(num < this.value) {
// System.out.println("Up");
x = "Up";
}return x;
}
}
import java.util.Random;
public class RandomNumber {
int value;
public RandomNumber() {
Random random = new Random();
value = (int) (random.nextInt(100) + 1);
}
}
import java.util.Scanner;
public class UpDownGame {
public static void main(String[] args) {
int count = 10;
Scanner sc = new Scanner(System.in);
System.out.println("1 게임 시작" + "\t" + "2 게임 종료");
int play = sc.nextInt();
if (play == 1) {
while (count > 0) {
int num = sc.nextInt();
Game game = new Game(num);
System.out.println(game.matching());
count--;
System.out.println("남은 횟수 = "+count);
}
} else if (play == 2) {
System.out.println("게임을 종료합니다");
System.exit(0);
}
}
}