제가 사진 찍은 2번 문제 어떻게 푸나요?
public class CurrencyTest {
public static void main(String[] args) {
KRW won = new KRW(1500.00);
USD dollar = new USD(100.50);
EUR euro = new EUR(260.75);
Currency[] arr = { won, dollar, euro };
for (Currency c : arr) {
c.printInfo();
}
}
}
abstract class Currency {
protected double amount; // 금액
public Currency(double amount) {
this.amount = amount;
}
public abstract void printInfo();
}
class KRW extends Currency {
public KRW(double amount) {
super(amount);
}
@Override
public void printInfo() {
System.out.println("KRW: " + amount + " 원");
}
}
class USD extends Currency {
public USD(double amount) {
super(amount);
}
@Override
public void printInfo() {
System.out.println("USD: " + amount + " 달러");
}
}
class EUR extends Currency {
public EUR(double amount) {
super(amount);
}
@Override
public void printInfo() {
System.out.println("EUR: " + amount + " 유로");
}
}