KangMoo
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    ## 과제_1 : 은행 계좌 관리 시스템의 예외 처리 개선 목표 : OOP 특징과 예외 처리 기법을 활용하여, 기존의 은행 계좌 관리 시스템의 예외 처리를 개선한다. 요구사항 : 1. **예외 처리 클래스 설계**: - 은행 계좌 관리 시스템에 대한 예외 처리를 위한 사용자 정의 예외 클래스를 설계한다. - 다음과 같은 상황에서 발생할 수 있는 예외들에 대해 각각 별도의 예외 클래스를 정의한다: - 음수 금액 입금 시도(`NegativeDepositException`) - 음수 금액 출금 시도(`NegativeWithdrawException`) - 음수 금액 대출 시도(`NegativeLoanException`) - 대출 금액이 최대 대출 가능 금액을 초과하는 경우(`ExceedCreditLimitException`) - 상환 금액이 현재 대출 잔액을 초과하는 경우(`ExceedLoanBalanceException`) - 각 예외 클래스는 적절한 에러 메시지를 포함해야 한다. 2. **예외 처리 로직 구현**: - `SavingsAccount`와 `CheckingAccount` 클래스 내의 메서드들에서, 위에서 정의된 예외들을 적절하게 던지도록 한다. - 예외 상황이 발생할 경우, 예외를 던지고 해당 예외를 적절히 처리하는 로직을 구현한다. - 예외 처리는 `try-catch` 블록을 사용하여 구현하며, 예외 발생 시 사용자에게 적절한 피드백을 제공해야 한다. ## 과제_2 : 프로그래머스 문제 풀기 1. [숨어있는 숫자의 덧셈 (1)](https://school.programmers.co.kr/learn/courses/30/lessons/120851) 2. [숨어있는 숫자의 덧셈 (2)](https://school.programmers.co.kr/learn/courses/30/lessons/120864) 3. [연속된 수의 합](https://school.programmers.co.kr/learn/courses/30/lessons/120923) --- ## 과제_1 : 은행 계좌 관리 시스템의 예외 처리 개선 모범 답안 ```java // 사용자 정의 예외 클래스 class NegativeDepositException extends Exception { public NegativeDepositException(String message) { super(message); } } class NegativeWithdrawException extends Exception { public NegativeWithdrawException(String message) { super(message); } } class NegativeLoanException extends Exception { public NegativeLoanException(String message) { super(message); } } class ExceedCreditLimitException extends Exception { public ExceedCreditLimitException(String message) { super(message); } } class ExceedLoanBalanceException extends Exception { public ExceedLoanBalanceException(String message) { super(message); } } // AbstractAccount 클래스 변경사항 public abstract class AbstractAccount implements Account { // 기존 필드 및 메서드 생략... @Override public void deposit(double amount) throws NegativeDepositException { if (amount < 0) { throw new NegativeDepositException("입금 금액은 음수가 될 수 없습니다."); } balance += amount; } @Override public void withdraw(double amount) throws NegativeWithdrawException { if (amount < 0) { throw new NegativeWithdrawException("출금 금액은 음수가 될 수 없습니다."); } balance -= amount; } } // SavingsAccount 클래스 변경사항 public class SavingsAccount extends AbstractAccount { // 기존 필드 및 메서드 생략... // 이자 추가 메서드는 예외 처리가 필요하지 않으므로 변경사항 없음 } // CheckingAccount 클래스 변경사항 public class CheckingAccount extends AbstractAccount { // 기존 필드 및 메서드 생략... @Override public void loan(double amount) throws NegativeLoanException, ExceedCreditLimitException { if (amount < 0) { throw new NegativeLoanException("대출 금액은 음수가 될 수 없습니다."); } if (amount > creditLimit) { throw new ExceedCreditLimitException("대출 금액이 한도를 초과합니다."); } loanBalance += amount; deposit(amount); // 예외 전파 } @Override public void repayLoan(double amount) throws NegativeWithdrawException, ExceedLoanBalanceException { if (amount < 0) { throw new NegativeWithdrawException("상환 금액은 음수가 될 수 없습니다."); } if (amount > loanBalance) { throw new ExceedLoanBalanceException("상환 금액이 대출 잔액을 초과합니다."); } loanBalance -= amount; withdraw(amount); // 예외 전파 } } // Main 클래스 변경사항 public class Main { public static void main(String[] args) { try { SavingsAccount sa = new SavingsAccount("123-45-67890", "홍길동", 100000, 0.05); sa.deposit(-100); // NegativeDepositException 시뮬레이션 } catch (NegativeDepositException e) { System.err.println(e.getMessage()); } catch (Exception e) { e.printStackTrace(); } // 이하 다른 메서드 호출 및 예외 처리 로직 생략... } } ``` --- ## 과제_2 : 프로그래머스 문제 풀기 모범 답안 1. 숨어있는 숫자의 덧셈 (1) ```java class Solution { public int solution(String my_string) { int answer = 0; // 문자열을 순회하면서 각 문자가 숫자인지 확인 for (int i = 0; i < my_string.length(); i++) { char c = my_string.charAt(i); // 문자가 숫자인 경우에만 answer에 더함 if ('0' <= c && c <= '9') { answer += c - '0'; // 문자를 정수로 변환하여 더함 } } return answer; } } ``` 2. 숨어있는 숫자의 덧셈 (2) ```java class Solution { public int solution(String my_string) { int answer = 0; // 숫자를 저장할 임시 문자열 변수 String temp = "0"; // 문자열을 순회하면서 각 문자 처리 for (int i = 0; i < my_string.length(); i++) { char c = my_string.charAt(i); // 문자가 숫자인 경우 temp에 추가 if ('0' <= c && c <= '9') { temp += c; } else { // 숫자가 아닌 경우 기존에 누적된 숫자를 answer에 더하고 temp를 초기화 answer += Integer.parseInt(temp); temp = "0"; } } // 마지막에 누적된 숫자 처리 answer += Integer.parseInt(temp); return answer; } } ``` 3. 연속된 수의 합 ```java class Solution { public int[] solution(int num, int total) { int middle = total / num; int start = middle - num / 2; if (num % 2 == 0) { start += 1; } int[] result = new int[num]; for (int i = 0; i < num; i++) { result[i] = start + i; } return result; } } ```

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully