public class LibraryManage {
Scanner scanner = new Scanner(System.in);
BookSet bookSet = new BookSet();
SimpleDateFormat outBook = new SimpleDateFormat("yyyy-MM-dd");
public void initial() {
Book java = new Book();
java.bookSet("java基础教程",false,"2015-7-1",1);
Book mysql = new Book();
mysql.bookSet("数据库技术",true,"",0);
Book renYue = new Book();
renYue.bookSet("人月神话",true,"",0);
bookSet.book[0] = java;
bookSet.book[1] = mysql;
bookSet.book[2] = renYue;
}
public void startMenu() {
boolean flag1 = true;
int choose;
int fanhui;
do {
System.out.println("欢迎使用图书管理系统");
System.out.println("——————————————————————————————————————————");
System.out.println("1. 新增图书");
System.out.println("2. 查看图书");
System.out.println("3. 删除图书");
System.out.println("4. 借出图书");
System.out.println("5. 归还图书");
System.out.println("6. 退 出");
System.out.println("请选择:");
choose = scanner.nextInt();
switch (choose) {
case 1:
System.out.println("---> 新增图书");
add();
break;
case 2:
System.out.println("---> 查看图书");
chakan();
break;
case 3:
System.out.println("---> 删除图书");
delete();
break;
case 4:
System.out.println("---> 借出图书");
out();
break;
case 5:
System.out.println("---> 归还图书");
guihuan();
break;
case 6:
System.out.println("---> 退 出");
break;
}
System.out.print("输入0返回:");
fanhui = scanner.nextInt();
}while( fanhui == 0 ) ;
}
private void add() {
System.out.print("请输入图书名称:");
String name = scanner.next();
boolean flagDelete = true;
int count = 0;
String date = "";
Book newBook = new Book();
newBook.bookSet(name,flagDelete,date,count);
for (int i = 0; i < bookSet.book.length; i++) {
if ( bookSet.book[i] == null ) {
bookSet.book[i] = newBook;
break;
}
}
System.out.println("增加" + newBook.name + "成功");
}
private void chakan() {
System.out.println("序号 \t状 态 \t 名称 \t\t借出日期");
for (int i = 0; i < bookSet.book.length; i++) {
if ( bookSet.book[i] != null) {
bookSet.book[i].print(i+1 );
}
}
System.out.println("***********************************");
}
private void delete() {
System.out.println("请输入你要删除图书的名称:");
String deleteBookName = scanner.next();
for (int i = 0; i < bookSet.book.length; i++) {
if ( bookSet.book[i] != null ) {
if ( deleteBookName.equals(bookSet.book[i].name) ) {
if (bookSet.book[i].flag ) {
int j = i;
while ( bookSet.book[j+1] != null ) {
bookSet.book[j] = bookSet.book[j+1];
j++;
}
bookSet.book[j] = null;
System.out.println("删除成功");
}else {
System.out.println("已借出的书不能删除");
break;
}
}else {
System.out.println("图书馆不存在此书");
break;
}
}
}
}
private void out() {
System.out.print("请输入图书名称:");
String bookName = scanner.next();
String outDate;
for (int i = 0; i < bookSet.book.length; i++) {
if ( bookSet.book[i] !=null && bookName.equals(bookSet.book[i].name) ) {
if ( bookSet.book[i].flag ) {
System.out.print("请输入借出日期(年-月-日):");
outDate = scanner.next();
bookSet.book[i].count = bookSet.book[i].count + 1;
bookSet.book[i].bookSet(bookName,false,outDate,bookSet.book[i].count);
System.out.println("借出成功");
break;
}else {
System.out.println("此书已被借走");
}
}
}
}
private void guihuan() {
System.out.print("请输入图书名称:");
String guihuanBook = scanner.next();
String guihuanBookDate;
for (int i = 0; i < bookSet.book.length; i++) {
if ( guihuanBook.equals(bookSet.book[i].name) ) {
if ( bookSet.book[i].flag ) {
System.out.println(bookSet.book[i].name + "未借出");
}else {
System.out.println("请输入归还日期:");
guihuanBookDate = scanner.next();
System.out.println("归还《" + bookSet.book[i].name + "》成功!");
System.out.println("借出日期为:" + bookSet.book[i].date);
System.out.println("归还日期为:" + guihuanBookDate);
System.out.println("应付租金(元)");
}
break;
}else {
System.out.println("图书馆不存在此书");
}
}
}
}
图书管理系统
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...