섭섭한 개발일지

[명언게시판] level 2 본문

멋쟁이사자처럼/Project

[명언게시판] level 2

Seop 2023. 10. 27. 14:57
구현 요구사항
== 명언 앱 ==
명령) 등록
명언 : 현재를 사랑하라.
작가 : 작자미상
명령) 종료

 

: 명언게시판 2단계는 명언을 등록하는 기능을 구현하는 것이다.

게시물은 n개를 만들 수 있으므로 게시물을 관리하는 객체를 만들고 배열에 저장하도록 하자.

 

구현
// main
public class Application {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        List<WiseModel> wiseArr = new ArrayList<>();

        while (true) {
            System.out.print("명령) ");
            String input = sc.nextLine();

            if (input.equals("등록")) {
                WiseModel wiseModel = new WiseModel();

                System.out.print("명언 : ");
                String addInput = sc.nextLine();
                wiseModel.setSentence(addInput);

                System.out.print("작가 : ");
                addInput = sc.nextLine();
                wiseModel.setAuthor(addInput);

                wiseArr.add(wiseModel);
            }

            if (input.equals("종료")) {
                break;
            }
        }
    }
}
    
    // model
    public class WiseModel {
    String sentence;
    String author;

    public String getSentence() {
        return sentence;
    }

    public void setSentence(String sentence) {
        this.sentence = sentence;
    }

    public String getAuthor() {
        return author;
    }

    public void setAuthor(String author) {
        this.author = author;
    }
}

 

 

 

'멋쟁이사자처럼 > Project' 카테고리의 다른 글

[명언게시판] level 6  (0) 2023.10.27
[명언게시판] level 5  (0) 2023.10.27
[명언게시판] level 4  (0) 2023.10.27
[명언게시판] level 3  (0) 2023.10.27
[명언게시판] level 1  (0) 2023.10.27
Comments