-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
301 lines (286 loc) · 9.86 KB
/
Main.java
File metadata and controls
301 lines (286 loc) · 9.86 KB
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
package zhuyao;
import java.util.ArrayList;
import java.util.Scanner;
import control.Demo;
import model.book;
import model.booklist;
import gongju.InputOutput;
public class Main {
/*
public static final int SIZE = 10;
Book[] booklist = new Book[SIZE];
*/
public Main()
{
Scanner scan = new Scanner(System.in);
InputOutput io = new InputOutput();
io.load();
printMenu();
while(true)
{
//读取用户输入
int choice = scan.nextInt();
if(choice == 5)
{
io.save();
System.out.println("成功退出系统,欢迎再次光临!");
break;
}
switch(choice)
{
case 1: addBook(); break;
case 2: deleteBoo(); break;
case 3: changeBoo(); break;
case 4: findBoo(); break;
default: System.out.println("输入非法"); printMenu(); continue;
}
}
/*
while(true)
{
//根据用户输入调用不同方法
if(choice == 1)
{
addBook();
}
else if(choice == 2)
{
deleteBoo();
}
else if(choice == 3)
{
changeBoo();
}
else if(choice == 4)
{
findBoo();
}
else if(choice == 5)
{
System.out.println("成功退出系统,欢迎再次光临!");
break;
}
}
*/
}
void printMenu()
{
//打印菜单
System.out.println("欢迎...");
System.out.println("增加图书...1");
System.out.println("删除图书...2");
System.out.println("修改图书...3");
System.out.println("查询图书...4");
System.out.println("退出系统...5");
}
void addBook()
{
System.out.println("当前共有:"+booklist.booklist.size()+"本书!");
Scanner scan = new Scanner(System.in);
System.out.println("请输入图书名:");
String bookname = scan.next();
System.out.println("请输入作者:");
String author = scan.next();
System.out.println("请输入单价:");
float price = scan.nextFloat();
Demo operator = new Demo();
boolean isSuccess = operator.addBook(bookname, author, price);
if(isSuccess)
{
System.out.println("增加成功!");
}
else
{
System.out.println("增加失败!");
}
operator.printAllBook();
}
void deleteBoo()
{
Scanner scan = new Scanner(System.in);
while(true)
{
System.out.println("请输入按哪种方法删除图书:1、序号/2、书名/3、返回主菜单");
int choose = scan.nextInt();
if(choose == 1)
{
System.out.println("请输入要删除第几本书:");
int id = scan.nextInt();
Demo operator = new Demo();
id = operator.orderFind(id);
//System.out.println(id);
if(id > -1)
{
/*
for(int i = id; i < count - 1 ; i++)
booklist[i]=booklist[i+1];
*/
boolean isSuccess = operator.deleteBook(id);
if(isSuccess)
System.out.println("删除成功!");
else
System.out.println("删除失败!");
operator.printAllBook();
}
else
{
System.out.println("输入错误!");
}
}
else if(choose == 2)
{
System.out.println("请输入您要删除的书名:");
String name = scan.next();
Demo operator = new Demo();
int id = operator.nameFind(name);
if(id > -1)
{
/*
for(int j = id; j<count-1; j++)
{
booklist[j]=booklist[j+1];
}
*/
boolean isSuccess = operator.deleteBook(id);
if(isSuccess)
System.out.println("删除成功!");
else
System.out.println("删除失败!");
operator.printAllBook();
}
else
{
System.out.println("未查找到您想要的书名");
}
}
else if(choose == 3)
{
printMenu();
break;
}
else
{
System.out.println("输入非法!");
}
}
}
void changeBoo()
{
Scanner scan = new Scanner(System.in);
while(true)
{
System.out.println("请输入按哪种方法修改图书:1、序号/2、书名/3、返回主菜单");
int choose = scan.nextInt();
if(choose == 1)
{
System.out.println("请输入要修改第几本书:");
int number = scan.nextInt();
Demo operator = new Demo();
int id = operator.orderFind(number);
if(id > -1)
{
book book = (book)booklist.booklist.get(id);
//System.out.println("原书名为:"+booklist[id].getBookname()+" 请输入你要修改为什么书名:");
System.out.println("原书名为:"+book.getBookname()+" 请输入你要修改为什么书名:");
String str = scan.next();
System.out.println("请输入作者:");
String author = scan.next();
System.out.println("请输入单价:");
float price = scan.nextFloat();
//booklist[id].setBook(str,author,price);
boolean isSuccess = operator.changeBoo(id,str,author,price);
if(isSuccess)
System.out.println("修改成功!");
else
System.out.println("修改失败!");
operator.printAllBook();
}
else
{
System.out.println("输入错误!");
}
}
else if(choose == 2)
{
System.out.println("请输入您要修改的书名:");
String name = scan.next();
Demo operator = new Demo();
int id = operator.nameFind(name);
if(id > -1)
{
book book = (book)booklist.booklist.get(id);
//System.out.println("原书名为:"+booklist[id].getBookname()+" 请输入你要修改为什么书名:");
System.out.println("原书名为:"+book.getBookname()+" 请输入你要修改为什么书名:");
String str = scan.next();
System.out.println("请输入作者:");
String author = scan.next();
System.out.println("请输入单价:");
float price = scan.nextFloat();
//booklist[id].setBook(str,author,price);
boolean isSuccess = operator.changeBoo(id,str,author,price);
if(isSuccess)
System.out.println("修改成功!");
else
System.out.println("修改失败!");
operator.printAllBook();
}
}
else if(choose == 3)
{
printMenu();
break;
}
else
{
System.out.println("输入非法!");
}
}
}
void findBoo()
{
Scanner scan = new Scanner(System.in);
Demo operator = new Demo();
while(true)
{
System.out.println("请输入按哪种方法查找图书:1、序号/2、书名/3、返回主菜单");
int choose = scan.nextInt();
if(choose == 1)
{
System.out.println("请输入要查找第几本书:");
int number = scan.nextInt();
int id = operator.orderFind(number);
if(id > -1)
{
operator.findBoo(id);
}
else
{
System.out.println("输入错误!");
}
}
else if(choose == 2)
{
System.out.println("请输入您要查找的书名:");
String name = scan.next();
int id = operator.nameFind(name);
if(id > -1)
{
operator.findBoo(id);
}
}
else if(choose == 3)
{
printMenu();
break;
}
else
{
System.out.println("输入非法!");
}
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
new Main();
}
}