主程序代码:
package bms;
import java.io.IOException;
import java.util.*;
import bms.book;
import bms.ms;
public class SYS {
private static Scanner input;
public static book B3 = new book("", "", "", "", "", 0, 0, 0);
public static void main(String args[]) {
ms cz = new ms();
for(int i=0;i<50;i++){
cz.B[i]=B3;
}
int dz = 1, gk = 1, xt = 1,ns=-1;
String x;
book B1 = new book("万历十五年", "978-7-108-00982-2", "黄仁宇", "三联书店", "历史", 1, 20, 58.8);
book B2 = new book("万历十年", "978-7-108-00982-1", "黄二宇", "二联书店", "历史", 50, 20, 58.8);
cz.B[0] = B1;
cz.B[1] = B2;
input = new Scanner(System.in);
do {
dz = 1;gk = 1;
System.out.println("请输入你的身份序号或退出:\n1.店主\n2.顾客\n3.退出");
int i = input.nextInt();
switch (i) {
case 1:
do {
System.out.println("尊敬的店主,请选择你的操作序号:\n1.查找书籍\n2.进货\n3.显示所有书籍信息\n4.退出");
i = input.nextInt();
input.nextLine();
switch (i) {
case 1:
System.out.println("请输入需要查找的书名、书号或作者:");
String a = input.nextLine();
x = cz.cs(a, cz);
if (x!=null) {
System.out.println("请选择接下来要进行的操作:\n1.下架这本书\n2.给这本书调整价格\n3.返回\n4.退出");
i = input.nextInt();
switch (i) {
case 1:
cz.xj(x,cz);
break;
case 2:
System.out.println("请输入你要调整后的价格:");
double jg=input.nextDouble();
cz.tj(x,cz,jg);
break;
case 3:
break;
case 4:
dz=0;
break;
default:
break;
}
}
break;
case 2:
cz.jh(cz);
break;
case 3:
cz.ShowAll(cz);
break;
case 4:
dz = 0;
break;
default:
System.out.println("您好,我想您应该输错了吧");
break;
}
} while (dz == 1);
break;
case 2:
do{
System.out.println("尊敬的顾客,请选择你的操作序号:\n1.查找书籍\n2.显示所有书籍\n3.退出");
i = input.nextInt();
input.nextLine();
switch (i) {
case 1:
System.out.println("请输入需要查找的书名、书号或作者:");
String a = input.nextLine();
x = cz.cs(a, cz);
if (x!=null) {
System.out.println("请选择接下来要进行的操作:\n1.归还这本书\n2.买这本书\n3.借这本书\n4.返回\n5.退出");
i = input.nextInt();
switch (i) {
case 1:
cz.gh(x,cz);
break;
case 2:
cz.buy(x,cz);
break;
case 3:
cz.js(x,cz);
break;
case 4:
break;
default:
System.out.println("您好,我想您应该输错了吧");
break;
}
}
break;
case 2:
cz.ShowAll1(cz);
break;
case 3:
gk=0;
break;
default:
System.out.println("您好,我想您应该输错了吧");
break;
}
} while (gk == 1);
break;
case 3:
xt = 0;
break;
default:
System.out.println("您好,我想您应该输错了吧");
}
}while(xt==1);System.out.println("感谢使用!");
}
}
书籍类代码块:
package bms;
public class book {
String Name,ISBN,Author,PublishingHouse,Classify;
int Inventory,Loan;
double Price;
public book(String a,String b,String c,String d,String e,int f,int g,double h) {
Name=a;
ISBN=b;
Author=c;
PublishingHouse=d;
Classify=e;
Inventory=f;
Loan=g;
Price=h;
}
public String getName() {
return Name;
}
public void setName(String name) {
Name = name;
}
public String getISBN() {
return ISBN;
}
public void setISBN(String iSBN) {
ISBN = iSBN;
}
public String getAuthor() {
return Author;
}
public void setAuthor(String author) {
Author = author;
}
public String getPublishingHouse() {
return PublishingHouse;
}
public void setPublishingHouse(String publishingHouse) {
PublishingHouse = publishingHouse;
}
public String getClassify() {
return Classify;
}
public void setClassify(String classify) {
Classify = classify;
}
public int getInventory() {
return Inventory;
}
public void setInventory(int inventory) {
Inventory = inventory;
}
public int getLoan() {
return Loan;
}
public void setLoan(int loan) {
Loan = loan;
}
public double getPrice() {
return Price;
}
public void setPrice(double price) {
this.Price = price;
}
public void Show(){
System.out.println("书名:"+Name);
System.out.println("书号:"+ISBN);
System.out.println("作者:"+Author);
System.out.println("出版社:"+PublishingHouse);
System.out.println("库存数:"+Inventory);
System.out.println("借出数:"+Loan);
System.out.println("价格"+Price);
}
}
功能区代码块:
package bms;
import java.util.*;
import bms.book;
public class ms {
private static Scanner input;
public static book B3 = new book("", "", "", "", "", 0, 0, 0);
static public book B[] = new book[50];
int n, x = -1;
String y;
public void js(ms b) {//计算有多少种书
for (int i = 0; i < 50; i++) {
if (b.B[i].Name == "") {
n = i;
break;
}
}
}
public String cs(String a, ms b) {//查书
b.js(b);
for (int j = 0; j <= n; j++) {
if (b.B[j].Name.equals(a) || b.B[j].ISBN.equals(a) || b.B[j].Author.equals(a)) {
B[j].Show();
x++;
y = b.B[j].ISBN;
System.out.println();
}
}
if (x == -1) {
System.out.println("不好意思,本店没有这本书。");
}
return y;
}
public void xj(String a, ms b) {//下架
book ks;
int xb = -1;
for (int i = 0; i < 50; i++) {
if (b.B[i].Name == "") {
n = i;
break;
}
}
for (int j = 0; j <= n; j++) {
if (b.B[j].ISBN.equals(a)) {
b.B[j] = B3;
xb = j;
System.out.println("下架成功!");
}
}
for (int i = xb; i < n - 1; i++) {
b.B[i] = b.B[i + 1];
xb = i + 1;
}
b.B[xb] = B3;
}
public void tj(String a, ms b, double c) {//调价
b.js(b);
for (int j = 0; j <= n; j++) {
if (b.B[j].ISBN.equals(a)) {
b.B[j].Price = c;
System.out.println("调整成功!");
}
}
}
public void ShowAll(ms cz) {//显示所以书籍【店主】
cz.js(cz);
System.out.println("书名\t\t书号\t\t\t作者\t出版社\t分类\t库存数\t借出数\t价格");
for (int j = 0; j < n; j++) {
System.out.println(cz.B[j].getName() + " \t" + cz.B[j].getISBN() + "\t" + cz.B[j].getAuthor() + "\t"
+ cz.B[j].getPublishingHouse() + "\t" + cz.B[j].getClassify() + "\t" + cz.B[j].getInventory() + "\t"
+ cz.B[j].getLoan() + "\t" + cz.B[j].getPrice());
}
}
public void jh(ms cz) {//进货
input = new Scanner(System.in);
cz.js(cz);
System.out.println("请输入您进货书的书名:");
String sm = input.nextLine();
System.out.println("请输入您进货书的书号:");
String sh = input.nextLine();
System.out.println("请输入您进货书的作者:");
String zz = input.nextLine();
System.out.println("请输入您进货书的出版社:");
String cbs = input.nextLine();
System.out.println("请输入您进货书的分类:");
String fl = input.nextLine();
System.out.println("请输入您进货书的库存数:");
int kcs = input.nextInt();
System.out.println("请输入您进货书的价格:");
double jg = input.nextDouble();
book sl = new book(sm, sh, zz, cbs, fl, kcs, 0, jg);
cz.B[n] = sl;
}
public void ShowAll1(ms cz) {//显示所有书籍【顾客】
cz.js(cz);
System.out.println("书名\t\t书号\t\t\t作者\t出版社\t分类\t库存数\t价格");
for (int j = 0; j < n; j++) {
System.out.println(cz.B[j].getName() + " \t" + cz.B[j].getISBN() + "\t" + cz.B[j].getAuthor() + "\t"
+ cz.B[j].getPublishingHouse() + "\t" + cz.B[j].getClassify() + "\t" + cz.B[j].getInventory() + "\t"
+ cz.B[j].getPrice());
}
}
public void gh(String a, ms b) {//归还
b.js(b);
for (int j = 0; j < n; j++) {
if (b.B[j].ISBN.equals(a)) {
if (b.B[j].getLoan() != 0) {
b.B[j].setInventory(b.B[j].getInventory() + 1);
b.B[j].setLoan(b.B[j].getLoan() - 1);
System.out.println("归还成功!");
} else {
System.out.println("这本书没有被借出。");
}
}
}
}
public void buy(String a, ms b) {//买书
b.js(b);
for (int j = 0; j < n; j++) {
if (b.B[j].ISBN.equals(a)) {
if (b.B[j].getInventory() != 0) {
b.B[j].setInventory(b.B[j].getInventory() - 1);
System.out.println("购买成功!");
} else {
System.out.println("购买失败,这本书卖光了!");
}
}
}
}
public void js(String a, ms b) {//借书
b.js(b);
for (int j = 0; j < n; j++) {
if (b.B[j].ISBN.equals(a)) {
if (b.B[j].getInventory() != 0) {
b.B[j].setInventory(b.B[j].getInventory() - 1);
b.B[j].setLoan(b.B[j].getLoan() + 1);
System.out.println("借书成功!");
} else {
System.out.println("借书失败,这本书没有了!");
}
}
}
}
}