문서의 선택한 두 판 사이의 차이를 보여줍니다.
양쪽 이전 판 이전 판 다음 판 | 이전 판 | ||
프로그램:java:ㄴhomework:ㄴhomework [2022/02/03 15:29] clayeryan@gmail.com [과제 91] |
프로그램:java:ㄴhomework:ㄴhomework [2025/06/27 16:04] (현재) |
||
---|---|---|---|
줄 3: | 줄 3: | ||
[[https:// | [[https:// | ||
- | [[programmer: | + | [[프로그램: |
- | [[programmer: | + | [[프로그램: |
- | [[programmer: | + | [[프로그램: |
===== Hello World 출력 ===== | ===== Hello World 출력 ===== | ||
줄 9066: | 줄 9066: | ||
++++ | ++++ | ||
- | ==== 과제 92 ==== | + | ==== Banking Project (J2SE 버전, 품질2단계) |
- | ++++title| | + | |
+ | ++++SavingsAccount| | ||
<code java> | <code java> | ||
- | java code | + | public class SavingsAccount { |
+ | private double balance; | ||
+ | private String name; | ||
+ | private double interestRate; | ||
+ | |||
+ | public SavingsAccount(double initBalance, | ||
+ | balance = initBalance; | ||
+ | this.interestRate = interestRate; | ||
+ | } | ||
+ | |||
+ | public SavingsAccount(String name) { | ||
+ | balance = 0; | ||
+ | this.name = name; | ||
+ | this.interestRate = 5.0; | ||
+ | } | ||
+ | |||
+ | public double getBalance() { | ||
+ | return balance; | ||
+ | } | ||
+ | |||
+ | public boolean deposit(double amt) { | ||
+ | balance = balance + amt; | ||
+ | return true; | ||
+ | } | ||
+ | |||
+ | public boolean withdraw(double amt) { | ||
+ | boolean result = false; | ||
+ | if(amt <= balance) { | ||
+ | balance = balance - amt; | ||
+ | result = true; | ||
+ | } | ||
+ | return result; | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | ++++ | ||
+ | |||
+ | ++++CheckingAccount| | ||
+ | < | ||
+ | public class CheckingAccount { | ||
+ | private double balance; | ||
+ | private String name; | ||
+ | private double overdraftAmount = 0; | ||
+ | |||
+ | public CheckingAccount(double initBalance, | ||
+ | balance = initBalance; | ||
+ | this.overdraftAmount = overdraftAmount; | ||
+ | } | ||
+ | |||
+ | public CheckingAccount(double initBalance) { | ||
+ | this(initBalance, | ||
+ | } | ||
+ | |||
+ | public CheckingAccount(String name) { | ||
+ | balance = 0; | ||
+ | this.name = name; | ||
+ | } | ||
+ | |||
+ | public double getBalance() { | ||
+ | return balance; | ||
+ | } | ||
+ | |||
+ | public boolean deposit(double amt) { | ||
+ | balance = balance + amt; | ||
+ | return true; | ||
+ | } | ||
+ | |||
+ | public boolean withdraw(double amount) { | ||
+ | boolean result = true; | ||
+ | |||
+ | if(balance < amount) { | ||
+ | double overdraftNeeded = amount - balance; | ||
+ | if(overdraftAmount < overdraftNeeded) { | ||
+ | result = false; | ||
+ | } else { | ||
+ | balance = 0.0; | ||
+ | overdraftAmount -= overdraftNeeded; | ||
+ | } | ||
+ | } else { | ||
+ | balance = balance - amount; | ||
+ | } | ||
+ | |||
+ | return result; | ||
+ | } | ||
+ | |||
+ | } | ||
+ | </code> | ||
+ | ++++ | ||
+ | |||
+ | ++++TestSafety| | ||
+ | <code java> | ||
+ | import java.util.ArrayList; | ||
+ | import java.util.List; | ||
+ | |||
+ | public class TestSafety { | ||
+ | public static void main(String[] args) { | ||
+ | List< | ||
+ | List< | ||
+ | |||
+ | lc.add(new CheckingAccount(" | ||
+ | ls.add(new SavingsAccount(" | ||
+ | |||
+ | CheckingAccount ca = lc.get(0); | ||
+ | SavingsAccount sa = ls.get(0); | ||
+ | |||
+ | System.out.println(" | ||
+ | System.out.println(" | ||
+ | System.out.println(" | ||
+ | System.out.println(" | ||
+ | System.out.println(" | ||
+ | |||
+ | System.out.println(" | ||
+ | |||
+ | System.out.println(" | ||
+ | System.out.println(" | ||
+ | System.out.println(" | ||
+ | System.out.println(" | ||
+ | System.out.println(" | ||
+ | } | ||
+ | |||
+ | } | ||
</ | </ | ||
++++ | ++++ |