4399 - Account 클래스

Time Limit: 1s Memory Limit: 128MB

Snippet Judge Submissions: 907 Solved: 453
Description

다음 특징을 가지는 Account 클래스를 만들기 바랍니다.

  • int형의 id 필드를 가진다.
  • double형의 balance 필드를 가진다.
  • double형을 인자로 가지고 현재 이자율을 저장하는 annualInterestRate를 가진다. 모든 계좌는 같은 이자율을 가진다고 가정한다.
  • 계좌가 만들어졌을 때 데이터를 저장하는 dateCreated 필드를 가진다.
  • 계좌를 default로 만드는 무(無)인자(no-arg) 생성자를 가진다.
  • 특정한 id와 초기 balance를 가진 계좌를 만드는 생성자를 가진다.
  • id와 balance, 연이자율에 대한 accessor 메소드(값을 반환하는 메소드)와 mutator 메소드(값을 변경시키는 메소드)를 가진다.
  • dateCreatead에 대한 accessor 메소드를 가진다.
  • 월이자율을 반환하는 getMonthlyInterestRate() 메소드를 가진다.
  • 월이자를 반환하는 getMonthlyInterest() 메소드를 가진다.
  • 계좌에서 일정한 금액을 인출하는 withdraw 메소드를 가진다.
  • 계좌에 일전한 금액을 입금하는 deposit 메소드를 가진다.
  • getMonthlyInterest () 메소드는 금리가 아닌 월간이자를 반환하는 것입니다. 월간이자는 잔액 * 월간 이자율입니다. monthlyInterestRate는 annualInterestRate / 12입니다. annualInterestRate는 백분율입니다 (예 : 4.5 %). 그것을 100으로 나눌 필요가 있습니다.

The class contains:

  • A private int data field named id for the account (default 0).
  • A private double data field named balance for the account (default 0).
  • A private double data field named annualInterestRate that stores the current interest rate (default 0). Assume all accounts have the same interest rate. 
  • A private Date data field named dateCreated that stores the date when the account was created.
  • A no-arg constructor that creates a default account.
  • A constructor that creates an account with the specified id and initial balance.
  • The accessor and mutator methods for id, balance, and annualInterestRate.
  • The accessor method for dateCreated.
  • A method named getMonthlyInterestRate() that returns the monthly interest rate.
  • A method named getMonthlyInterest() that returns the monthly interest.
  • A method named withdraw that withdraws a specified amount from the account.
  • A method named deposit that deposits a specified amount to the account.
  • The method getMonthlyInterest() is to return monthly interest, not the interest rate. Monthly interest is balance * monthlyInterestRate. monthlyInterestRate is annualInterestRate / 12. Note that annualInterestRate is a percentage, e.g., like 4.5%. You need to divide it by 100.

여러분이 작성한 코드는 아래 샘플코드의 YOUR_CODE 부분에 들어가 컴파일 됩니다. 

Input

샘플 코드 참조

Output

샘플 코드 참조

- 출금 금액이 잔액 보다 클경우 출금하지 않는다.  

Sample Code
import java.util.*;

public class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);

        Account account = new Account(sc.nextInt(), sc.nextInt());
        Account.setAnnualInterestRate(sc.nextDouble());

        System.out.printf("Balance : %.2f\n", account.getBalance());
        System.out.printf("Monthly interest : %.2f\n", account.getMonthlyInterest());

        account.withdraw(sc.nextDouble());

        System.out.printf("Balance : %.2f\n", account.getBalance());
        System.out.printf("Monthly interest : %.2f\n", account.getMonthlyInterest());

        account.deposit(sc.nextDouble());

        System.out.printf("Balance : %.2f\n", account.getBalance());
        System.out.printf("Monthly interest : %.2f\n", account.getMonthlyInterest());
    }
}

YOUR_CODE
Sample Input
1
1000
10
20000
100
Sample Output
Balance : 1000.00
Monthly interest : 8.33
Balance : 1000.00
Monthly interest : 8.33
Balance : 1100.00
Monthly interest : 9.17
Source

JAVA2015 PE9.7