1:Book
public class Book {
String[] name = new String[30]; //數(shù)組1存儲圖書名稱數(shù)組
int [] state = new int[30]; //數(shù)組2存儲圖書借出狀態(tài):0已借出/1可借
String[] date = new String[30];//數(shù)組3存儲圖書借出日期
int[] count = new int[30];//借出次數(shù)
2:Shop
public class shop {
Scanner scanner = new Scanner(System.in);
book bk = new book();
public void initial() {
bk.name[0] = "Java基礎(chǔ)教程";
bk.count[0] = 0;
bk.date[0] = "2015-7-1";
bk.state[0] = 0;
bk.name[1] = "數(shù)據(jù)庫技術(shù)";
bk.count[1] = 0;
bk.state[1] = 1;
bk.name[2] = "人月神話";
bk.state[2] = 1;
bk.count[2] = 0;
}
public void kaishi() {
boolean flag = true;
do {
System.out.println("歡 迎 使 用 圖 書 管 理 系 統(tǒng)");
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.print("****************************************\n");
System.out.print("請選擇: ");
int choice = scanner.nextInt();
switch (choice) {
case 1:
System.out.println("--->新增圖書");
xinzeng();
break;
case 2:
System.out.println("--->查看圖書");
chakan();
break;
case 3:
System.out.println("--->刪除圖書");
delete();
break;
case 4:
System.out.println("--->借出圖書");
sell();
break;
case 5:
System.out.println("--->歸還圖書");
gaveme();
break;
case 6:
System.out.println("--->您已退出");
break;
}
} while (flag == true);
}
// 歸還書籍
// 歸還時把state換成 1
// 有大bug
private void gaveme() {
System.out.println("請你輸入你要還的書的名字");
String name = scanner.next();
for (int i = 0; i < bk.name.length; i++) {
if (bk.name[i].equals(name) && bk.state[i] == 0) {
bk.state[i] = 1;
System.out.println("還書成功");
break;
} else if (bk.name[i] == null) {
System.out.println("沒有找到匹配信息");
}
}
}
//借出圖書
//借出之后在圖書的.之后的借出更改為已借出,借出次數(shù)加一涡匀,在輸入借出時間
// 借出[1]書的時候 [2]直接沒有了
private void sell() {
// System.out.println("請輸入你要借的書的編號");
// int bh = scanner.nextInt();
System.out.println("請輸入你要借的書本的名字");
String name = scanner.next();
for (int i = 0; i < bk.name.length; i++) {
if (bk.name[i] == null) {
System.out.println("沒有找到匹配信息");
break;
} else if (bk.name[i].equals(bk.name[i]) && bk.state[i] == 1) {
bk.state[i] = 0;
bk.count[i] = +1;
System.out.println("請輸入借書的時間");
bk.state[i] = scanner.nextInt();
System.out.println("借出《" + name + "》成功!");
break;
} else if (bk.name[i].equals(name) && bk.state[i] == 0) {
System.out.println("不好意思,你要接的書已經(jīng)被別人接走了");
}
}
}
//刪除圖書
//把他的下表跟最后一位空的下表更換位置就行
private void delete() {
boolean flag = true;
System.out.println("請輸入要刪除的書的名字");
String name = scanner.next();
for (int i = 0; i < bk.name.length; i++) {
if((bk.name[i].equalsIgnoreCase(name)&& bk.name[i] !=null)){
int j = i;
while (bk.name[j + 1] != null) {
bk.name[j] = bk.name[j + 1];
bk.state[j] = bk.state[j + 1];
bk.date[j] = bk.date[j + 1];
j++;
}
bk.name[j] = null;
bk.date[j] = null;
flag = true;
break;
} else{
flag = false;
}if( flag){
System.out.println("刪除sb");
}else{
System.out.println("刪除成功");
}
/*if ((bk.name[i] != null) && (bk.name[i].equalsIgnoreCase(name)) && (bk.state[i] == 1)) {
int j = i;
while (bk.name[j + 1] != null) {
bk.name[j] = bk.name[j + 1];
bk.state[j] = bk.state[j + 1];
bk.date[j] = bk.date[j + 1];
j++;
}
System.out.println("刪除《" + name + "》成功溉知!");
} else if ((bk.name[i] != null) && bk.name[i].equals(name) && (bk.state[i] == 0)) {
System.out.println("這本書被人接走了");
} else {
System.out.println("沒有找到匹配信息");
break;
}*/
}
}
//查看圖書
private void chakan() {
System.out.println("序號\t 狀態(tài)\t 名稱\t 借出日期\t");
for (int i = 0; i < bk.name.length; i++) {
if (bk.name[i] == null) {
} else if (bk.state[i] == 0) {
System.out.println((i + 1) + "\t已借出\t" + "<<" + bk.name[i] + "》\t" + bk.date[i]);
// break;
} else if (bk.state[i] == 1) {
System.out.println((i + 1) + "\t可 借\t" + "<<" + bk.name[i] + ">>");
}
}
System.out.println("******************************");
}
//新增圖書
private void xinzeng() {
System.out.println("請輸入要新增的圖書名字");
String name = scanner.next();
for (int i = 0; i < bk.name.length; i++) {
if (bk.name[i] == null) {
bk.name[i] = name;
bk.state[i] = 1;
System.out.println("新增《" + name + "》成功");
break;
}
}
}
3:csshi
public class csshi {
public static void main(String[] args) {
shop sp = new shop();
sp.initial();
sp.kaishi();
}
}