nme.kr

차이

문서의 선택한 두 판 사이의 차이를 보여줍니다.

차이 보기로 링크

양쪽 이전 판 이전 판
다음 판
이전 판
프로그램:java:ㄴhomework:ㄴhomework [2022/02/03 15:29]
clayeryan@gmail.com [과제 91]
프로그램:java:ㄴhomework:ㄴhomework [2025/06/27 16:04] (현재)
줄 3: 줄 3:
 [[https://hashcode.co.kr/code_runners?language=java|자바 웹 컴파일러]] [[https://hashcode.co.kr/code_runners?language=java|자바 웹 컴파일러]]
  
-[[programmer:java:ㄴhomework:quiz|ㄴ과제 퀴즈]]+[[프로그램:java:ㄴhomework:quiz|ㄴ과제 퀴즈]]
  
-[[programmer:java:ㄴhomework:doc|ㄴ개념정리:목차]]+[[프로그램:java:ㄴhomework:doc|ㄴ개념정리:목차]]
  
-[[programmer:java:ㄴhomework:book_source|ㄴ북소스]]+[[프로그램:java:ㄴhomework:book_source|ㄴ북소스]]
 ===== 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, double interestRate) { 
 + 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; 
 +
 +
 +</code> 
 +++++ 
 + 
 +++++CheckingAccount| 
 +<code java
 +public class CheckingAccount { 
 + private double balance; 
 + private String name; 
 + private double overdraftAmount = 0; 
 +  
 + public CheckingAccount(double initBalance, double overdraftAmount) { 
 + balance = initBalance; 
 + this.overdraftAmount = overdraftAmount; 
 +
 +  
 + public CheckingAccount(double initBalance) { 
 + this(initBalance, 0.0); 
 +
 +  
 + 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<CheckingAccount> lc = new ArrayList<CheckingAccount>(); 
 + List<SavingsAccount> ls = new ArrayList<SavingsAccount>(); 
 +  
 + lc.add(new CheckingAccount("Fred")); 
 + ls.add(new SavingsAccount("Fred")); 
 +  
 + CheckingAccount ca = lc.get(0); 
 + SavingsAccount sa = ls.get(0); 
 +  
 + System.out.println("Withdraw 150.00 : " + ca.withdraw(150.00)); 
 + System.out.println("Deposit 22.50 : " + ca.deposit(22.50)); 
 + System.out.println("Withdraw 47.62 : " + ca.withdraw(47.62)); 
 + System.out.println("Withdraw 400.00 : " + ca.withdraw(400.00)); 
 + System.out.println("Balance : " + ca.getBalance()); 
 +  
 + System.out.println("========================================="); 
 +  
 + System.out.println("Withdraw 150.00 : " + sa.withdraw(150.00)); 
 + System.out.println("Deposit 22.50 : " + sa.deposit(22.50)); 
 + System.out.println("Withdraw 47.62 : " + sa.withdraw(47.62)); 
 + System.out.println("Withdraw 400.00 : " + sa.withdraw(400.00)); 
 + System.out.println("Balance : " + sa.getBalance()); 
 +
 + 
 +}
 </code> </code>
 ++++ ++++