-
Notifications
You must be signed in to change notification settings - Fork 0
/
week10_1.java
132 lines (131 loc) · 2.56 KB
/
week10_1.java
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
import java.util.Scanner;
abstract class Shape{
private Shape next;
public Shape() {next = null;}
public void setNext(Shape obj) {next = obj;}
public Shape getNext() {return next;}
public abstract void draw();
}
class Line extends Shape{
@Override
public void draw() {
System.out.println("Line");
}
}
class Rect extends Shape{
@Override
public void draw() {
System.out.println("Rect");
}
}
class Circle extends Shape{
@Override
public void draw() {
System.out.println("Circle");
}
}
class GraphicEditor{
Shape start;
Shape last;
void run(){
Scanner sc = new Scanner(System.in);
System.out.println("그래픽 에디터 beauty을 실행합니다.");
while(true) {
System.out.print("삽입(1), 삭제(2), 모두 보기(3), 종료(4)>>");
int num = sc.nextInt();
if(num == 1) {
System.out.print("Line(1), Rect(2), Circle(3)>>");
num = sc.nextInt();
insert(num);
}
else if(num == 2) {
System.out.print("삭제할 도형의 위치>>");
num = sc.nextInt();
delete(num);
}
else if(num == 3) {
print();
}
else if(num == 4) {
System.out.println("beauty을 종료합니다.");
break;
}
else {
System.out.println("1~4를 입력해주세요.");
}
}
}
void insert(int num) {
if(start==null)
{
if(num == 1) {
start=new Line();
last=start;
}
else if(num == 2) {
start=new Rect();
last=start;
}
else if(num == 3) {
start=new Circle();
last=start;
}
else {
System.out.println("1~3를 입력해주세요.");
}
}
else
{
if(num == 1) {
Shape s;
s=new Line();
last.setNext(s);
last=s;
}
else if(num == 2) {
Shape s;
s=new Rect();
last.setNext(s);
last=s;
}
else if(num == 3) {
Shape s;
s=new Circle();
last.setNext(s);
last=s;
}
else {
System.out.println("1~3를 입력해주세요.");
}
}
}
void delete(int num) {
Shape temp = null;
for(int i= 1; i <= num + 1; i++) {
temp = start.getNext();
}
if(temp != null) {
for(int i = 1; i < num; i++) {
if(i == num-1) {
start.setNext(temp.getNext());
}
}
}
else {
System.out.println("삭제할 수 없습니다.");
}
}
void print() {
Shape startPos=start;
while(startPos!=null) {
startPos.draw();
startPos = startPos.getNext();
}
}
}
public class week10_1 {
public static void main(String args[]) {
GraphicEditor g = new GraphicEditor();
g.run();
}
}