-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjava315p_3.java
More file actions
55 lines (55 loc) · 1.36 KB
/
java315p_3.java
File metadata and controls
55 lines (55 loc) · 1.36 KB
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
package ch_java;
import java.util.*;
abstract class Converter{
abstract protected double convert(double src);
abstract protected String getSrcString();
abstract protected String getDestString();
protected double ratio;
public void run() {
Scanner scan = new Scanner(System.in);
System.out.println(getSrcString()+"을"+getDestString()+"로 바꿉니다.");
System.out.println(getSrcString()+"을 입력하세요>> ");
double val = scan.nextDouble();
double res = convert(val);
System.out.println("변환결과: "+res+getDestString()+"입니다.");
scan.close();
}
}
class Won2Dollar extends Converter{
Scanner scan = new Scanner(System.in);
double Dollar;
Won2Dollar(int Dollar){
this.Dollar=Dollar;
}
protected double convert(double src) {
return src/Dollar;
}
protected String getSrcString() {
return "원";
}
protected String getDestString() {
return "달러";
}
}
class Km2Mile extends Converter{
Scanner scan = new Scanner(System.in);
double Mile;
Km2Mile(double Mile){
this.Mile = Mile;
}
protected double convert(double src) {
return src/Mile;
}
protected String getSrcString() {
return "Km";
}
protected String getDestString() {
return "Mile";
}
}
public class java315p_3 {
public static void main(String[] args) {
Km2Mile toMile = new Km2Mile(1.6);
toMile.run();
}
}