1.自己做的
package BOOk;
public class Book {
private String name;
private String author;
private double price;
private int store;
private String publishDate;
public Book(String name, String author, double price, int store, String publishDate) {
this.name = name;
this.author = author;
this.price = price;
this.store = store;
this.publishDate = publishDate;
}
public Book() {
super();
// TODO Auto-generated constructor stub
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAuthor() {
return author;
}
public void setAuthor(String author) {
this.author = author;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
public int getStore() {
return store;
}
public void setStore(int store) {
this.store = store;
}
public String getPublishDate() {
return publishDate;
}
public void setPublishDate(String publishDate) {
this.publishDate = publishDate;
}
public void add(){
}
}
主代码
package BOOk;
import java.util.Scanner;
public class newBook {
public static void main(String[] args) {
System.out.println("欢迎使用图书书店");
System.out.println("请输入用户名:");
Scanner input = new Scanner(System.in);
String userName = input.nextLine();
String trueUserNamer = "admin";
System.out.println("请输入密码:");
String mima = input.nextLine();
String password = "admin";
if ((userName.equals(trueUserNamer)) && (mima.equals(password)))
System.out.println("登录成功");
else
System.out.println("登录失败");
Book[] book = new Book[5];
Book b1 = new Book("鬼吹灯", "天下霸唱", 33, 6, "2004-2-12");
Book b2 = new Book("魔界", "莫尔斯", 45, 4, "2001-1-1");
Book b3 = new Book("时间机器", "威尔", 64, 5, "2000-1-22");
Book b4 = new Book("哈利波特", "罗一梦", 12, 3, "1998-4-12");
Book b5 = new Book("暂无", "暂无", 0, 0, "暂无");
book[0] = b1;
book[1] = b2;
book[2] = b3;
book[3] = b4;
book[4] =b5;
do {
System.out.println("~~~~~~~~欢迎使用本图书管理系统~~~~~~~~");
System.out.println("\t1.查看图书");
System.out.println("\t2.图书入库");
System.out.println("\t3.图书出库");
System.out.println("\t4.新增图书");
System.out.println("\t5.退出");
System.out.println("请进行你的操作");
int num = input.nextInt();
switch (num) {
case 1:// 查询
System.out.println("书名\t作者\t价格\t库存\t出版日期");
for (int i = 0; i < book.length; i++) {
Book b = book[i];
System.out.println(b.getName() + "\t" + b.getAuthor() + "\t" + b.getPrice() + "\t" + b.getStore()
+ "\t" + b.getPublishDate());
}
break;
case 2:
// 图书入库;
System.out.println("请输入书名");
String name = input.next();
if (name.equals("鬼吹灯") || name.endsWith("魔界") || name.endsWith("哈利波特") || name.endsWith("时间机器"))
System.out.println("请输入增加库存");
int store = input.nextInt();
for (int i = 0; i <= book.length; i++) {
if (name.equals(book[i].getName())) {
book[i].setStore(book[i].getStore() + store);
break;
}
}
break;
case 3:// 出库
System.out.println("请输入书名");
String name1 = input.next();
if (name1.equals("鬼吹灯") || name1.endsWith("魔界") || name1.endsWith("哈利波特") || name1.endsWith("时间机器"))
System.out.println("请输入要借的数量");
int store1 = input.nextInt();
for (int i = 0; i <= book.length; i++) {
if (name1.equals(book[i].getName())) {
book[i].setStore(book[i].getStore() - store1);
break;
}
}
break;
case 4:
System.out.println("请输入书名");
String name2=input.next();
System.out.println("请输入作者");
String author2=input.next();
System.out.println("请输入价格");
double price2=input.nextDouble();
System.out.println("请输入库存");
int store2=input.nextInt();
System.out.println("请输入出版日期");
String publicDate=input.next();
b5.setName(name2);b5.setAuthor(author2);b5.setPrice(price2);b5.setStore(store2);
b5.setPublishDate(publicDate);
break;
case 5:
return;
}
} while (true);
}
}
public class Book {
//书号 书名 作者 发布日期 价格 库存
private int id;
private String name;
private String author;
private String date;
private double price;
private int count;
public Book(int id, String name, String author, String date, double price, int count) {
super();
this.id = id;
this.name = name;
this.author = author;
this.date = date;
this.price = price;
this.count = count;
}
public Book() {
super();
// TODO Auto-generated constructor stub
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAuthor() {
return author;
}
public void setAuthor(String author) {
this.author = author;
}
public String getDate() {
return date;
}
public void setDate(String date) {
this.date = date;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
public int getCount() {
return count;
}
public void setCount(int count) {
this.count = count;
}
}
public class Admin {
private static String userName;
private static String password;
private static String realName;
static{
userName = "admin";
password = "admin";
realName = "金庸";
}
public static String getUserName() {
return userName;
}
public static String getPassword() {
return password;
}
public static String getRealName() {
return realName;
}
}
主代码
import java.util.Arrays;
import java.util.Scanner;
import com.sxt.bms.entity.Admin;
import com.sxt.bms.entity.Book;
public class TestBook {
static Scanner sc = new Scanner(System.in); //打印对象
//初始化图书数组
static Book[] book = new Book[5];
static{
book[0] = new Book(10001,"鬼吹灯","天下霸唱","2008-7-1",27.8,87);
book[1] = new Book(10002,"盗墓笔记","三叔","2008-7-1",35,100);
book[2] = new Book(10003,"西游记","吴承恩","2008-7-1",27.8,87);
book[3] = new Book(10004,"水浒传","罗贯中","2008-7-1",50,87);
book[4] = new Book(10005,"三国演义","施耐庵","2008-7-1",89,120);
}
/**
* 管理员登录
*/
public static void login(){
System.out.println("请输入用户名:");
String userName = sc.nextLine();
System.out.println("请输入密码:");
String password = sc.nextLine();
if(Admin.getUserName().equals(userName)&&Admin.getPassword().equals(password)){
System.out.println("登陆成功");
//跳转到主界面
index();
}else{
System.out.println("用户名或密码错误");
login();
}
}
/**
* 主界面功能
*/
public static void index(){
//请选择进行的操作:1.图书入库 2.图书出库 3.查询全部图书 4.新增图书 5.退出
System.out.println("*********欢迎【"+Admin.getRealName()+"】登录库存管理系统**********");
queryAllBook();//查询全部图书
System.out.println("1.图书入库");
System.out.println("2.图书出库");
System.out.println("3.查询全部图书");
System.out.println("4.新增图书");
System.out.println("5.退出");
System.out.println("请选择:");
int num = Integer.parseInt(sc.nextLine());
switch(num){
case 1:enterBook();index();break;//入库
case 2:outBook();index();break; //出库
case 3:queryAllBook();index();break;//查询全部图书
case 4:addBook();index();break; //添加图书
case 5:logout();return;//退出
default:System.out.println("输入错误");index();break;
}
}
/**
* 查询所有图书
*/
public static void queryAllBook(){
System.out.println("书号\t书名\t作者\t发布日期\t\t价格\t库存");
for(int i = 0;ibCount){
System.out.println("出库的数量不能大于本书的库存");
outBook();
}else{
//出库
book[index].setCount(bCount-count);
}
}else{
System.out.println("图书编号不存在");
outBook();
}
}
/**
* 新增图书
* @param args
*/
public static void addBook(){
System.out.println("请输入图书信息");
System.out.println("请输入书名:");
String name = sc.nextLine();
System.out.println("请输入作者");
String author = sc.nextLine();
System.out.println("请输入出版时间:");
String date = sc.nextLine();
System.out.println("请输入价格:");
double price = Double.parseDouble(sc.nextLine());
System.out.println("请输入库存:");
int count = Integer.parseInt(sc.nextLine());
//图书编号自增
int id = book[book.length-1].getId()+1;
//1 先封装到书籍对象
Book newBook = new Book(id, name, author, date, price, count);
//2 把书籍对象封装到数组中
book = Arrays.copyOf(book, book.length+1);
book[book.length-1] = newBook;
}
/**
* 登出
* @param args
*/
public static void logout(){
System.out.println("欢迎下次光临!!!");
}
public static void main(String[] args) {
System.out.println("----欢迎使用尚学堂图书书店----");
login();
}
}