···
package com.company;
import java.util.Scanner;
public class BookManage {
BookSet bookSet = new BookSet();
public BookManage() {
}
public void initial() {
Book jichujiaochen = new Book();
jichujiaochen.setBook("java基础教程", 0, 2007.0D);
Book shuju = new Book();
shuju.setBook("数据库技术", 1, 0.0D);
Book renyue = new Book();
shuju.setBook("人月神话", 1, 0.0D);
this.bookSet.books[0] = jichujiaochen;
this.bookSet.books[1] = shuju;
this.bookSet.books[2] = renyue;
}
public void startMenu() {
boolean flag = true;
do {
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("*********************");
Scanner scanner = new Scanner(System.in);
System.out.println("请选择");
int gongnengbianhao = scanner.nextInt();
switch(gongnengbianhao) {
case 1:
System.out.println("查看图书信息");
this.chakan();
break;
case 2:
System.out.println("新增图书信息");
this.add();
break;
case 3:
System.out.println("删除图书信息");
this.delete();
break;
case 4:
System.out.println("借出图书");
break;
case 5:
System.out.println("归还图书");
break;
case 6:
System.out.println("退出系统");
this.exit();
flag = false;
break;
default:
System.out.println("你输入的有误");
}
} while(flag);
}
public void exit() {
System.out.println("退出");
}
public void sell() {
System.out.println("输入你要卖出的商品名称:");
Scanner scanner = new Scanner(System.in);
String name = scanner.next();
for(int i = 0; i < this.bookSet.books.length; ++i) {
if (this.bookSet.books[i].name.equals(name)) {
System.out.println("输入卖出的数量");
int shoumai = scanner.nextInt();
if (shoumai < this.bookSet.books[i].state) {
this.bookSet.books[i].state -= shoumai;
this.bookSet.books[i].state += shoumai;
}
System.out.println("售卖成功");
break;
}
}
}
public void delete() {
System.out.println("亲输入你要删除的商品编号");
Scanner scanner = new Scanner(System.in);
int delNo = scanner.nextInt();
for(int i = 0; i < this.bookSet.books.length; ++i) {
if (this.bookSet.books[i] != null && i + 1 == delNo) {
for(int j = i; this.bookSet.books[j + i] != null; ++j) {
this.bookSet.books[j] = this.bookSet.books[j + i];
}
this.bookSet.books[i] = null;
System.out.println("删除成功!");
} else {
System.out.println("删除失败!");
}
}
}
public void chakan() {
System.out.println("编号:\t 名称 \t 状态 \t 日期");
for(int i = 0; i < this.bookSet.books.length; ++i) {
if (this.bookSet.books[i] != null) {
this.bookSet.books[i].print(i + 1);
}
}
}
public void add() {
System.out.println("请输入图书名称");
Scanner scanner = new Scanner(System.in);
String name = scanner.next();
System.out.println("请输入状态");
double zt = scanner.nextDouble();
System.out.println("请输入日期");
int riqi = scanner.nextInt();
Book newBook = new Book();
newBook.setBook(name, (int)zt, (double)riqi);
for(int i = 0; i < this.bookSet.books.length; ++i) {
if (this.bookSet.books[i] == null) {
this.bookSet.books[i] = newBook;
break;
}
}
}
}
···