#각국 통화 화폐
## CODE <a class='btn btn-default' href='/codes/12395'>Link</a>
```
public class Main {
public static void main(String[] args) {
// 객체 생성
KRW krw = new KRW(1500, "원");
USD usd = new USD(100.50, "달러");
EUR eur = new EUR(260.87, "유로");
JPY jpy = new JPY(1400, "엔");
// 부모 클래스를 통한 그룹화
Currency[] currencies = { krw, usd, eur, jpy };
// 모든 화폐정보를 출력
for (Currency c : currencies) {
System.out.println(c.toString());
}
}
}
class Currency{
protected double amount; // 수량(1000)
protected String notation; // 표기법(원)
public Currency(double amount, String notation){
this.amount = amount;
this.notation = notation;
}
public String toString(){
return String.format("화폐: %.2f %s",amount,notation);
}
}
class KRW extends Currency{
/*
private double amount; // 수량(1000)
private String notation; // 표기법(원)
*/
public KRW(double amount, String notation) {
/*
this.amount = amount;
this.notation = notation;
*/
super(amount,notation);
}
public String toString(){
return String.format("KRW: %.2f %s",amount,notation);
}
}
class USD extends Currency{
/*
private double amount;
private String notation;
*/
public USD(double amount, String notation) {
/*
this.amount = amount;
this.notation = notation;
*/
super(amount,notation);
}
public String toString(){
return String.format("USD: %.2f %s",amount,notation);
}
}
class EUR extends Currency{
/*
private double amount;
private String notation;
*/
public EUR(double amount, String notation) {
/*
this.amount = amount;
this.notation = notation;
*/
super(amount,notation);
}
public String toString(){
return String.format("EUR: %.2f %s",amount,notation);
}
}
class JPY extends Currency{
/*
private double amount;
private String notation;
*/
public JPY(double amount, String notation) {
/*
this.amount = amount;
this.notation = notation;
*/
super(amount,notation);
}
public String toString(){
return String.format("JPY: %.2f %s\n",amount,notation);
}
}
```
## INPUT
```
```
## OUPUT
```
KRW: 1500.00 원
USD: 100.50 달러
EUR: 260.87 유로
JPY: 1400.00 엔
```
의도한 코드가 맞는지 궁금합니다.
소소한 오타도 발견했습니다
출력예는 6400.00엔
뼈대코드에는 1400.00엔
항상 많은 도움이 되고 있습니다 감사합니다!
sehongpark님의 답변
# 부모 클래스를 통한 업캐스팅!
상속을 통한 그룹화! 굳잡!
## PS.
오타 제보 항상 감사합니다 :D