Java - 공지사항 메뉴 붙이기
Main
import java.sql.SQLException;
import com.lec.app.console.NoticeConsole;
public class program5 {
public static void main(String[] args) throws ClassNotFoundException, SQLException {
NoticeConsole console = new NoticeConsole();
EXIT:
while(true) {
console.printNoticeList();
int menu =console.inputNoticeMenu();
switch(menu) {
case 1: //상세 조회
break;
case 2: //이전
break;
case 3: // 다음
break;
case 4: //글쓰기
break;
case 5:
System.out.println("Bye~~~~");
break EXIT;
default:
System.out.println("메뉴는 1~4번까지 입력하실수있습니다.");
break;
}
}
}
}
NoticeConsole
import java.sql.SQLException;
import java.util.List;
import java.util.Scanner;
import com.lec.app.entity.Notice;
import com.lec.app.service.NoticeService;
public class NoticeConsole {
private NoticeService service;
public NoticeConsole() {
service = new NoticeService();
}
public void printNoticeList() throws ClassNotFoundException, SQLException {
List<Notice> list = service.getList();
System.out.println("────────────────────");
System.out.printf("<공지사항> 총 %d 게시글\n",12);
System.out.println("────────────────────");
for(Notice n:list) {
System.out.printf("%d. %s / %s / %s\n",
n.getId(), n.getTitle(), n.getWirterid(),n.getRegDate());
}
System.out.println("────────────────────");
System.out.printf(" %d/%d pages\n",1,2);
}
public int inputNoticeMenu() {
Scanner scan = new Scanner(System.in);
System.out.printf("1.상세조회/ 2.이전 / 3.다음/ 4.글쓰기 5.종료 >");
String menu_ = scan.nextLine();
int menu = Integer.parseInt(menu_);
return menu;
}
}
항상 실습할때 case 문 안에다가 구현해서 어떻게 하면 뺄지 감이안잡혔는데 ( while 문도 빼고싶었음 ) 저렇게하는거구나 싶었다..
복습하면서 정리하는 연습도 해봐야겠다.!
댓글남기기