Programming | Study/Java
스케줄 관리 프로그램
jinju
2021. 3. 23. 03:11
코드
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
import java.util.Scanner;
class Day{
private String work;
public Day() {
// TODO Auto-generated constructor stub
}
public void set(String work) {
this.work=work;
}
public String get() {
return work;
}
public void show() {
if(work==null)
System.out.println("없습니다.");
else System.out.println(work + "입니다 ");
}
}
public class MonthSchedule {
private Scanner sc;
private Day days[];
MonthSchedule(int day) {
this.days = new Day[day];
for(int i=0; i<days.length; i++) {
days[i] = new Day();
}
sc = new Scanner(System.in);
}
private void input() {
System.out.print("날짜(1~31)?");
int day = sc.nextInt();
System.out.print("할일(빈칸없이입력)?");
String work = sc.next();
day--;
if(day < 0 || day > 31) {
System.out.println("날짜를 잘못 입력하였습니다.");
return;
}
days[day].set(work);
}
private void view() {
System.out.print("날짜(1~31)?");
int day = sc.nextInt();
day--;
if(day < 0 || day > 31) {
System.out.println("날짜를 잘못 입력하였습니다.");
return;
}
System.out.print((day+1)+"일의 할 일은 ");
days[day].show();
}
private void finish() {
System.out.println("프로그램을 종료합니다.");
sc.close();
}
public void run() {
System.out.print("3월달 스케줄 관리 프로그램.");
while(true) {
System.out.println();
System.out.print("할일(입력:1, 보기:2, 끝내기:3) >>");
int select = sc.nextInt();
switch(select) {
case 1: input(); break;
case 2: view(); break;
case 3: finish(); return;
}
}
}
public static void main(String[] args) {
MonthSchedule march = new MonthSchedule(31);
march.run();
}
}
|
cs |
input(), view(), finish(), run() 메소드를 만들고 main에서 생성자를 호출하여 메뉴를 출력
결과
-명품 자바 프로그래밍 제 4장 실습문제 7번 인용
-나중에 시간이 된다면 mvc형태로 나누어 보기,,,,,,