카테고리 없음

게시판 기능 프로그램 구현, 문제 1

zmcokse 2020. 5. 7. 11:44

-소스코드

import java.util.Scanner;

public class Main{
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);

Board board = new Board();
board.setScanner(scanner);
board.start();

scanner.close();
}

}

class Board{
Article[] articles;
int articlesLastIndex;
Scanner scanner;

Board(){
articles=new Article[100];
articlesLastIndex = -1;
}

void showHelp() {
System.out.printf("== 명령어 리스트 ==\n");
System.out.printf("help : 명령어 리스트\n");
System.out.printf("list : 게시물 리스팅\n");
System.out.printf("add : 게시물 추가\n");
System.out.printf("exit : 종료\n");
System.out.printf("detail {&게시물 번호} : 게시물 상세보기\n");

}

void start() {
showHelp();

while (true) {
System.out.printf("게시판) ");
String command = scanner.next().trim();

if ( command.equals("exit")) {
System.out.printf("== 게시판 종료 ==\n");
break;
} else if (command.equals("add")) {
scanner.nextLine();
doCommandAdd();
} else if ( command.equals("help")) {
showHelp();
} else if ( command.equals("list")) {
if (articles==null) {
System.out.printf("게시물이 존재하지 않습니다.\n");
}
else {
System.out.println("== 게시물 리스트 ==");
System.out.println("번호  |   날짜        | 제목");
}

} else if ( command.equals("detail")) {

}
else {
System.out.printf("일치하는 명령어가 없습니다. \n");

}
}
}

private void doCommandAdd() {
Article article = new Article();

Article lastArticle=null;

if (articlesLastIndex >= 0) {
lastArticle = articles[articlesLastIndex];
}

int newId;

if( lastArticle == null) {
newId=1;
}
else {
newId = lastArticle.id + 1;
}

article.id=newId;
article.regDate= "2020-05-06 12:12:12";
System.out.printf("제목 : ");
article.title = scanner.nextLine();
System.out.printf("내용 : ");
article.body = scanner.nextLine();

int articlesNewIndex = articlesLastIndex+1;
articles[articlesNewIndex] = article;

System.out.printf("%d번 글이 생성되었습니다.\n", article.id);

articlesLastIndex++;
}

void setScanner(Scanner scanner) {
this.scanner = scanner;

}



}

class Article {
int id;
String regDate;
String title;
String body;
}

-완료된 기능 목록

 1.명령어 리스트 출력

 2.게시물 추가

 3. help로 명령어 리스트 반복 출력

 4.게시물 종료

-완료하지 못한 기능들

 -게시물 조회

 -게시물 상세보기

 -그 외의 기타기능들

-이 문제를 풀면서 발견한 부족한 부분

 1.scanner 개념과 활용도

 2.매개변수와 리턴문

 3.클래스 활용법

 4.리모컨의 개념이 부족함

 5.메서드를 어떻게 활용하고 응용해야하는지 호출을 어떻게하는지 개념이 안잡혀있다.