blob: 7639bc818a233fa59a759307e23ffa85e8c2a40a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
package javatest.e0501;
import java.util.Scanner;
interface Soundable {
void makeSound();
void turnUpVolumn();
void turnDownVolumn();
}
class Radio implements Soundable {
private int volumn = 5;
@Override
public void makeSound() {
System.out.println("Radio sound...");
}
@Override
public void turnUpVolumn() {
volumn++;
}
@Override
public void turnDownVolumn() {
volumn--;
}
}
class Walkman implements Soundable {
private int volumn = 5;
@Override
public void makeSound() {
System.out.println("Walkman sound...");
}
@Override
public void turnUpVolumn() {
volumn++;
}
@Override
public void turnDownVolumn() {
volumn--;
}
}
class Mobilephone implements Soundable {
private int volumn = 5;
@Override
public void makeSound() {
System.out.println("Mobilephone sound...");
}
@Override
public void turnUpVolumn() {
volumn++;
}
@Override
public void turnDownVolumn() {
volumn--;
}
}
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String t = scanner.next();
Soundable soundable = null;
switch (t) {
case "radio":
soundable = new Radio();
break;
case "walkman":
soundable = new Walkman();
break;
case "mobilephone":
soundable = new Mobilephone();
break;
default:
System.out.println("Unknown device.");
System.exit(1);
}
soundable.makeSound();
}
}
|