class Won2Dollar extends Converter {
Won2Dollar(){
}
Won2Dollar(int won) {
super.ratio = won;
}
@Override
protected double convert(double src) {
// TODO Auto-generated method stub
return src / ratio;
}
@Override
protected String getSrcString() {
return "원";
}
@Override
protected String getDestString() {
return "달러";
}
}
public class Main {
public static void main(String[] args) {
Won2Dollar toDollar = new Won2Dollar(1200);
toDollar.run();
}
}
*/
import java.util.Scanner;
abstract class Converter {
abstract protected double convert(double src);
abstract protected String getSrcString();
abstract protected String getDestString();
protected double ratio;
public void run() {
Scanner scanner = new Scanner(System.in);
System.out.println(getSrcString() + "을 " + getDestString() + "로 바꿉니다.");
System.out.print(getSrcString() + "을 입력하세요 >> ");
double val = scanner.nextDouble();
double res = convert(val);
System.out.println("변환 결과: " + res + getDestString() + "입니다");
scanner.close();
}
}
class Km2Mile extends Converter {
public Km2Mile() {
}
public Km2Mile(double n) {
ratio = n;
}
@Override
protected double convert(double src) {
return src / ratio;
}
@Override
protected String getSrcString() {
return "Km";
}
@Override
protected String getDestString() {
return "mile";
}
}
public class Main {
public static void main(String[] args) {
Km2Mile toMile = new Km2Mile(1.6);
toMile.run();
}
}