자바 은행 입금 클래스
조회수 350회
[국제 은행] 아래는 원화, 엔화, 달러 세 가지 통화로 입금만 가능한 은행 계좌 관리 프로그램의 뼈대 코드이다. 통화를 의미하는 Currency 클래스와 은행 계좌를 의미하는 BankAccount 클래스가 있다. 다음은 Currency 클래스 명세표이다.
생성자
Currency(double initial_amount) : 원화 단위의 금액 initial_amount를 받아서 객체 초기화. initial_amount 가 음수이면 0으로 처리.
속성
double dollars : 달러 단위로 표시되는 금액
double won : 원화 단위로 표시되는 금액
double yen : 엔화 단위로 표시되는 금액
메소드
add(Currency other): Currency : 다른 Currency객체를 받아서 더하기를 수행한 후 새로운 Currency 객체 반환
getDollars(): double : 달러 단위의 금액 반환
getWon(): double : 원화 단위의 금액 반환
getYen(): double : 엔화 단위의 금액 반환
아래 뼈대코드의 Currency 클래스 정의를 완성하고, Currency 클래스를 사용하는 BankAccount 클래스 또한 완성하라. 참고로, 1 달러 = 1000원 100엔 = 1000원 의 환율을 적용한다.
class Currency { private double dollars; private double won; private double yen;
public Currency(double initial_amount) {
// initial_amount is given in won
// fill here!
}
public Currency add(Currency other) {
// fill here!
}
public double getDollars() {
// fill here!
}
public double getWon() {
// fill here!
}
public double getYen() {
// fill here!
}
}
class BankAccount { private Currency balance;
public BankAccount(Currency initial_amount) {
// fill here!
}
public Currency getBalance() {
// fill here!
}
public boolean deposit(Currency money) {
// fill here!
}
}
public class Q5 { public static void main(String[] args) { Currency money = new Currency(100); BankAccount account = new BankAccount(money); account.deposit(money); System.out.println("balance = " + account.getBalance().getDollars()); // balance = 0.2 } }
댓글 입력