java实现简易的图书馆管理系统⽐较适合新⼿练⼿的⼀个简易项⽬
直接上源码
Book
package code;
/**
* @author ztr
* @version创建时间:2021年3⽉4⽇下午8:21:40
* 类说明
*/
public class Book {
private String name;
private String author;
private double price;
private String type;
//    有参构造器
public Book(String name, String author, double price, String type) {
super();
this.name = name;
this.author = author;
this.price = price;
}
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 String getType() {
return type;
}
public void setType(String type) {
}
}
Cuser
package code;
import java.util.Iterator;
import java.util.List;
import java.util.Scanner;
/**
* @author ztr
* @version创建时间:2021年3⽉4⽇下午8:32:15 类说明
*/
public class Cuser extends User {
Scanner sc = new Scanner(System.in);
public Cuser(String name, String sex, int age) {
super(name, sex, age);
}
//    查书籍
@Override
public void serach(List<Book> LibraryBookDate) {
//        Scanner sc = new Scanner(System.in);
System.out.println("请输⼊你想要查询的书籍名称");
String name = sc.next();
for (int i = 0; i < LibraryBookDate.size(); i++) {
if (name != null) {
if ((i).getName().equals(name)) {
System.out.println("查询成功");
System.out.(i).getName() + " "                            + (i).getAuthor() + " "
+ (i).getPrice() + " "
+ (i).getType());
}
} else {
System.out.println("没有此书");
java图书馆最新
}
}
}
//遍历图书
@Override
public void display(List<Book> LibraryBookDate) {
// 使⽤lambda表达式
Iterator<Book> it = LibraryBookDate.iterator();
while (it.hasNext()) {
// 因为it.next()返回的是object类型所以需要进⾏类型强转
Book book = (Book) it.next();
System.out.Name() + " " + Author() + " "                    + Price() + " " + Type());
}
}
//借阅书籍
@Override
public void borrow(List<Book> LibraryBookDate) {
//        Scanner sc = new Scanner(System.in);
System.out.println("请输⼊你想要借阅的书籍书名:");
String name = sc.next();
// 获取集合的迭代器
Iterator<Book> it = LibraryBookDate.iterator();
while (it.hasNext()) {
Book book = (Book) it.next();
if (Name().equals(name)) {
System.out.Name() + " " + Author()                        + " " + Price() + " " + Type());
UserBookDate.userdateBooks.add(book);
} else {
System.out.println("没有该书籍");
}
}
}
//    归还书籍
public void revert(List<Book> LibraryBookDate){
//        Scanner sc = new Scanner(System.in);
System.out.println("请输⼊需要归还的书籍:");
String name = sc.next();
Iterator<Book> it = UserBookDate.userdateBooks.iterator();
while(it.hasNext()){
Book book = (();
Name().equals(name)){
LibraryBookDate.add(book);
}
}
}
}
LibraryBookDate
package code;
import java.util.ArrayList;
import java.util.List;
/**
* @author ztr
* @version创建时间:2021年3⽉4⽇下午9:21:13
* 类说明
*/
public class LibraryBookDate {
static List<Book> LibraryBookDate = new ArrayList<Book>();
}
Menu
ackage code;
import java.util.Scanner;
/**
* @author ztr
* @version创建时间:2021年3⽉6⽇下午4:28:07 类说明
*/
public class Menu {
public void menuRuser() {
Ruser ruser = new Ruser("ztr", "man", 20);
System.out.println("1.查阅书籍" + "/n" + "2.遍历书籍" + "/n" + "3.删除书籍"                + "4.添加书籍" + "5.返回上⼀层");
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
switch (n) {
case 1:
ruser.serach(LibraryBookDate.LibraryBookDate);
menuRuser();
break;
case 2:
ruser.display(LibraryBookDate.LibraryBookDate);
menuRuser();
break;
case 3:
ruser.borrow(LibraryBookDate.LibraryBookDate);
menuRuser();
break;
case 4:
ruser.insert(LibraryBookDate.LibraryBookDate);
menuRuser();
break;
case 5:
menu();
break;
default:
System.out.println("请重新输⼊:");
menuRuser();
break;
}
sc.close();
}
public void menuCuser() {
Cuser cuser = new Cuser("x", "man", 10);
System.out.println("1.查阅书籍" + "/n" + "2.遍历书籍" + "/n" + "3.借阅书籍"                + "4.归还书籍" + "5.返回上⼀层");
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
switch (n) {
case 1:
cuser.serach(LibraryBookDate.LibraryBookDate);
menuCuser();
break;
case 2:
cuser.display(LibraryBookDate.LibraryBookDate);
menuCuser();
break;
case 3:
cuser.borrow(LibraryBookDate.LibraryBookDate);
menuCuser();
break;
case 4:
menuCuser();
break;
case 5:
menu();
break;
default:
System.out.println("请重新输⼊:");
menuCuser();
break;
}
sc.close();
}
public void menu() {
System.out.println("====图书馆管理系统===");
System.out.println("1.⽤户  2.管理员  3.退出");
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
switch (n) {
case 1:
menuCuser();
break;
case 2:
menuRuser();
case 3:
break;
default:
System.out.println("请重新输⼊");
break;
}
sc.close();
}
}
Operate
package code;
import java.util.List;
/**
* @author ztr
* @version创建时间:2021年3⽉4⽇下午8:25:01
* 类说明
*/
public interface Operate {
public void serach(List<Book> LibraryBookDate);
public void display(List<Book> LibraryBookDate);
public void borrow(List<Book> LibraryBookDate);
}
Ruser
package code;
import java.util.Iterator;
import java.util.List;
import java.util.Scanner;
/**
* @author ztr
* @version创建时间:2021年3⽉6⽇下午3:56:25 类说明
*/
public class Ruser extends User {
Scanner sc = new Scanner(System.in);
public Ruser(String name, String sex, int age) {
super(name, sex, age);
}
// 查书籍
@Override
public void serach(List<Book> LibraryBookDate) {
//        Scanner sc = new Scanner(System.in);
System.out.println("请输⼊你想要查的书籍书名:");
String name = sc.next();
// 获取集合的迭代器
Iterator<Book> it = LibraryBookDate.iterator();
while (it.hasNext()) {
Book book = (Book) it.next();
if (Name().equals(name)) {
System.out.Name() + " " + Author()                        + " " + Price() + " " + Type());
UserBookDate.userdateBooks.add(book);
} else {
System.out.println("没有该书籍");
}
}
}
// 遍历图书
@Override
public void display(List<Book> LibraryBookDate) {
// 使⽤lambda表达式
Iterator<Book> it = LibraryBookDate.iterator();
while (it.hasNext()) {
// 因为it.next()返回的是object类型所以需要进⾏类型强转
Book book = (Book) it.next();
System.out.Name() + " " + Author() + " "
+ Price() + " " + Type());
}
}
/
/ 删除图书
@Override
public void borrow(List<Book> LibraryBookDate) {
//        Scanner sc = new Scanner(System.in);
System.out.println("请输⼊你要删除书籍的书名:");
String name = sc.next();
// 获取集合的迭代器
Iterator<Book> it = LibraryBookDate.iterator();
while (it.hasNext()) {
Book book = (Book) it.next();
if (Name().equals(name)) {
System.out.Name() + " " + Author()
+ " " + Price() + " " + Type());
} else {
System.out.println("没有该书籍");
}
}
}
// 添加图书
public void insert(List<Book> libraryBookDate) {
//        Scanner sc = new Scanner(System.in);
System.out.println("请依次输⼊锁添加书籍的信息:1.书名2.作者3价格4类型");        String name = sc.next();
String author = sc.next();
double price = sc.nextDouble();
String type = sc.next();
Book book = new Book(name, author, price, type);
libraryBookDate.add(book);
}
}
User
package code;
/**
* @author ztr
* @version创建时间:2021年3⽉4⽇下午8:24:46
* 类说明
*/
public abstract class User implements Operate{
private String name;
private String sex;
private int age;
public User(String name, String sex, int age) {
super();
this.name = name;
this.sex = sex;
this.age = age;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
}
UserBookDate
package code;

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。