본문 바로가기

자바(java)

노트 테이킹 앱: 메모를 작성하고 관리하는 간단한 노트 애플리케이션을 개발합니다.

반응형

여기에 간단한 노트 테이킹 앱을 개발하는 Java 코드와 설명을 제공하겠습니다.

1. 내용 설명

이 노트 테이킹 앱은 사용자가 메모를 작성하고 관리하는 간단한 애플리케이션입니다. 사용자는 메모를 추가, 조회, 수정, 삭제할 수 있습니다.

2. 프로그램 간 사용 함수 설명

  • addNote(): 사용자에게 입력을 받아 새로운 메모를 추가합니다.
  • viewNotes(): 저장된 모든 메모를 조회합니다.
  • editNote(): 사용자에게 편집할 메모를 선택하고 내용을 수정합니다.
  • deleteNote(): 사용자에게 삭제할 메모를 선택하고 메모를 삭제합니다.

3. 코딩 내용

 

import java.util.ArrayList;
import java.util.Scanner;

public class NoteTakingApp {
    private static ArrayList<String> notes = new ArrayList<>();
    private static Scanner scanner = new Scanner(System.in);

    public static void main(String[] args) {
        boolean isRunning = true;

        while (isRunning) {
            System.out.println("1. 메모 추가");
            System.out.println("2. 메모 조회");
            System.out.println("3. 메모 수정");
            System.out.println("4. 메모 삭제");
            System.out.println("5. 종료");
            Systehttp://m.out.print("선택: ");

            int choice = scanner.nextInt();
            scanner.nextLine(); // Consume the newline character

            switch (choice) {
                case 1:
                    addNote();
                    break;
                case 2:
                    viewNotes();
                    break;
                case 3:
                    editNote();
                    break;
                case 4:
                    deleteNote();
                    break;
                case 5:
                    isRunning = false;
                    break;
                default:
                    System.out.println("올바른 옵션을 선택하세요.");
            }
        }
    }

    private static void addNote() {
        Systehttp://m.out.print("메모 내용을 입력하세요: ");
        String note = scanner.nextLine();
        notes.add(note);
        System.out.println("메모가 추가되었습니다.");
    }

    private static void viewNotes() {
        System.out.println("메모 목록:");
        for (int i = 0; i < notes.size(); i++) {
            System.out.println((i + 1) + ". " + notes.get(i));
        }
    }

    private static void editNote() {
        viewNotes();
        Systehttp://m.out.print("편집할 메모 번호를 입력하세요: ");
        int noteIndex = scanner.nextInt() - 1;
        scanner.nextLine(); // Consume the newline character

        if (noteIndex >= 0 && noteIndex < notes.size()) {
            Systehttp://m.out.print("새로운 내용을 입력하세요: ");
            String newNote = scanner.nextLine();
            notes.set(noteIndex, newNote);
            System.out.println("메모가 수정되었습니다.");
        } else {
            System.out.println("올바른 메모 번호를 입력하세요.");
        }
    }

    private static void deleteNote() {
        viewNotes();
        Systehttp://m.out.print("삭제할 메모 번호를 입력하세요: ");
        int noteIndex = scanner.nextInt() - 1;
        scanner.nextLine(); // Consume the newline character

        if (noteIndex >= 0 && noteIndex < notes.size()) {
            notes.remove(noteIndex);
            System.out.println("메모가 삭제되었습니다.");
        } else {
            System.out.println("올바른 메모 번호를 입력하세요.");
        }
    }
}

 

 

4. 전문 용어

  • 메모 추가: 사용자가 새로운 메모를 입력하여 목록에 추가하는 기능.
  • 메모 조회: 저장된 모든 메모를 사용자에게 표시하는 기능.
  • 메모 수정: 사용자가 특정 메모를 선택하고 해당 메모의 내용을 수정하는 기능.
  • 메모 삭제: 사용자가 특정 메모를 선택하고 해당 메모를 목록에서 삭제하는 기능.

5. 라이브러리 추가 및 실행 방법

이 코드는 Java의 기본 라이브러리만 사용하므로 추가 라이브러리가 필요하지 않습니다.

실행 방법:

  1. Java 개발 환경이 설치되어 있어야 합니다.
  2. 위의 코드를 복사하여 Java 파일로 저장합니다.
  3. 명령 프롬프트 또는 터미널에서 해당 디렉토리로 이동한 후 다음 명령을 실행합니다.

컴파일

javac -encoding UTF-8 NoteTakingApp.java

 

실행

java NoteTakingApp

반응형