图书管理系统(ArrayList和LinkedList)--versions3.0
目录
一、项目要求:
二、项目环境
三、项目使用的知识点
四、项目代码
五、项目运行结果
六、项目难点分析
图书管理系统--versions1.0:
图书管理系统--versions1.0-CSDN博客文章浏览阅读981次,点赞29次,收藏17次。本文使用了变量,数据类型,顺序,选择,循环,数组实现了一个简单的小项目--图书管理系统,其中包括用户管理,图书管理,不同权限管理的内容不同。https://blog.csdn.net/qq_53483101/article/details/135583634?spm=1001.2014.3001.5501
图书管理系统--versions2.0:
图书管理系统--versions2.0-CSDN博客文章浏览阅读1k次,点赞35次,收藏19次。本文使用了变量,数据类型,顺序,选择,循环,数组,对象及属性的封装实现了一个简单的小项目--图书管理系统,其中包括用户管理,图书管理,不同权限管理的内容不同。https://blog.csdn.net/qq_53483101/article/details/135728923?spm=1001.2014.3001.5501
图书管理系统--versions3.0:
图书管理系统(ArrayList和LinkedList)--versions3.0-CSDN博客本文使用了变量,数据类型,顺序,选择,循环,对象及属性的封装,使用ArrayList和LinkedList集合,实现了一个简单的小项目--图书管理系统,其中包括用户管理,图书管理,不同权限管理的内容不同。https://blog.csdn.net/qq_53483101/article/details/135939196?spm=1001.2014.3001.5501
一、项目要求:
1)通过账号控制图书管理系统,账号分为管理员账号和普通用户账号
1. 管理员账号和普通用户账号都可以使用手机号码+密码、身份证号码+密码的形式登录,登录方式二选一2.管理员账号和普通账号除了手机号码、身份中号码、密码三个数据之外,还有姓名、性别、专业、住址信息
2)启动系统后,显示登录账号、注册账号、退出登录三个模块
a)登录账号:
1、显示管理员登录
2、用户登录两个模块b)注册账号:
1、显示注册管理员
2、注册用户两个模块
c)退出登录:结束程序运行
3)登录账号成功后,根据账号的性质来显示不同的模块:
登录管理员账号成功后,显示如下模块:1、查看所有图书,图书显示哪些信息,这里设计的信息有书名,书的价格,书的数量
2、添加图书
3、修改图书
4、删除图书
5、查看所有普通用户信息
6、查看管理员账号信息
7、修改管理员账号信息
8、退出系统
登录普通账号成功后,显示如下模块:
1、查看所有图书,图书显示哪些信息,你自行设计
2、借阅图书
3、归还图书
4、显示用户信息(只能查看自己的用户信息)
5、修改用户信息(只能修改自己的用户信息)
6、退出系统
4)使用对象对不同类及其各自属性进行封装与功能实现
二、项目环境
(1)开发工具:IDEA、JDK17
(2)开发语言:Java
三、项目使用的知识点
(1)理解程序基本概念——程序、变量、数据类型
(2)顺序、选择、循环、跳转语句(3)使用对象的思想对图书管理系统--versions1.0进行改造
这里使用了对象封装的思想,将其分为管理员用户类,普通用户,书类,工具类,系统主页面类,将各自的类的属性功能封装,在系统页面类里面调用这些属性方法实现各个功能的开发。
(4) 加入集合的操作,取代数组对数据的存储。
(5) 数据的转型(多态)
四、项目代码
这里说明一下,为了快速写出项目,前面的用户管理的八个属性均采用String类型存储,方便自己后续代码的编写及相关功能的实现,有不足或者想要自己实现的功能部分读者可以自行修改代码实现。
AdminUser类:
package com.threecode;public class AdminUser {private String adminUser;private String adminPhoneNumber;private String adminIdentityNumber;private String adminPassword;private String adminName;private String adminSex;private String adminCareer;private String adminAddress;public AdminUser() {}public AdminUser(String adminUser, String adminPhoneNumber, String adminIdentityNumber, String adminPassword, String adminName, String adminSex, String adminCareer, String adminAddress) {this.adminUser = adminUser;this.adminPhoneNumber = adminPhoneNumber;this.adminIdentityNumber = adminIdentityNumber;this.adminPassword = adminPassword;this.adminName = adminName;this.adminSex = adminSex;this.adminCareer = adminCareer;this.adminAddress = adminAddress;}public String getAdminUser() {return adminUser;}public void setAdminUser(String adminUser) {this.adminUser = adminUser;}public String getAdminPhoneNumber() {return adminPhoneNumber;}public void setAdminPhoneNumber(String adminPhoneNumber) {this.adminPhoneNumber = adminPhoneNumber;}public String getAdminIdentityNumber() {return adminIdentityNumber;}public void setAdminIdentityNumber(String adminIdentityNumber) {this.adminIdentityNumber = adminIdentityNumber;}public String getAdminPassword() {return adminPassword;}public void setAdminPassword(String adminPassword) {this.adminPassword = adminPassword;}public String getAdminName() {return adminName;}public void setAdminName(String adminName) {this.adminName = adminName;}public String getAdminSex() {return adminSex;}public void setAdminSex(String adminSex) {this.adminSex = adminSex;}public String getAdminCareer() {return adminCareer;}public void setAdminCareer(String adminCareer) {this.adminCareer = adminCareer;}public String getAdminAddress() {return adminAddress;}public void setAdminAddress(String adminAddress) {this.adminAddress = adminAddress;}@Overridepublic String toString() {returnadminUser + "\t\t\t" +adminPhoneNumber + "\t\t\t" +adminIdentityNumber + "\t\t\t" +adminPassword + "\t\t\t" +adminName + "\t\t\t" +adminSex + "\t\t\t" +adminCareer + "\t\t\t" +adminAddress + "\t\t\t" ;}
}
AdminUserList类:
package com.threecode;import java.util.ArrayList;public class AdminUserList {private ArrayList<AdminUser> adminUsers = new ArrayList<AdminUser>();public AdminUserList() {adminUsers.add( new AdminUser("root","1111","2222","123456","张三","男","计算机","安徽"));}public ArrayList<AdminUser> getAdminUsers() {return adminUsers;}public void setAdminUsers(ArrayList<AdminUser> adminUsers) {this.adminUsers = adminUsers;}}
AdminUserAction类:
package com.threecode;import java.util.ArrayList;
import java.util.Scanner;/*** @Author 南初* @Create 2024/1/28 14:04* @Version 1.0*/
public class AdminUserAction {Scanner scan = new Scanner(System.in);//管理员用户登录验证public int loginCheck(AdminUserList adminUser){ArrayList<AdminUser> adminUsers = adminUser.getAdminUsers();System.out.print("请输入你要登录的形式(1.手机号码+密码 2.身份证号码+密码):");int verifyNum = scan.nextInt(); //verifyNum 验证方式数字//只能选择一种登录方式while (true) {if (verifyNum == 1 || verifyNum == 2) {break;} else {System.out.print("\n输入错误,请输入要选择要操作的序号(只能输入1,2):");verifyNum = scan.nextInt();}}// 1.手机号码+密码 2.身份证号码+密码System.out.print("请输入你要登录的管理员序号(0,1,2):");int adminId = scan.nextInt(); // 登录管理员账号序号while(true){if(adminId<=adminUsers.size()-1){break;}else {System.out.print("你输入的管理员账户不存在,请重新输入你要登录的管理员序号(0,1,2):");adminId = scan.nextInt(); // 登录管理员账号序号}}if (verifyNum == 1) { // 管理员用户// 管理员登录验证 手机号码+密码System.out.println("\n请输入你的验证信息:");while(true){if(adminUsers.get(adminId)==null){System.out.print("\n你输入的管理员用户不存在,请重新输入,");adminId = scan.nextInt();}else{break;}}System.out.print("\n请输入管理员账号(默认root):");String adminUser1 = scan.next();System.out.print("\n请输入手机号码");String adminPhoneNumber1 = scan.next();System.out.print("\n请输入密码:");String adminPassword1 = scan.next();AdminUser a1= adminUsers.get(adminId);while (true) {if (adminUser1.equals(a1.getAdminUser()) && adminPhoneNumber1.equals(a1.getAdminPhoneNumber()) && adminPassword1.equals(a1.getAdminPassword())) {break;} else {System.out.println("输入信息错误,请重新输入信息!");System.out.print("请输入管理员账号序号(默认root):");adminUser1 = scan.next();System.out.print("\n请输入手机号码:");adminPhoneNumber1 = scan.next();System.out.print("\n请输入密码:");adminPassword1 = scan.next();}}} else if (verifyNum == 2) { // 管理员登录验证 身份证号码+密码System.out.print("请输入账号(默认root):");String adminUser2 = scan.next();System.out.print("\n请输入身份证号码:");String adminIdentityNumber2 = scan.next();System.out.print("\n请输入密码:");String adminPassword2 = scan.next();AdminUser a1= adminUsers.get(adminId);while (true) {if (adminUser2.equals(a1.getAdminUser()) && adminIdentityNumber2.equals(a1.getAdminIdentityNumber()) && adminPassword2.equals(a1.getAdminPassword())) {break;} else {System.out.println("输入信息错误,请重新输入信息!");System.out.print("请输入账号(默认root):");adminUser2 = scan.next();System.out.print("\n请输入身份证号码:");adminIdentityNumber2 = scan.next();System.out.print("\n请输入密码:");adminPassword2 = scan.next();}}}return adminId;}// 注册管理员用户public void addAdminUser(AdminUserList adminUser){ArrayList<AdminUser> adminUsers = adminUser.getAdminUsers();System.out.print("\n请输入新的管理员账户名:");String user = scan.next();System.out.print("\n请输入新的手机号码:");String phonenumber = scan.next();System.out.print("\n请输入新的身份证号码:");String identitynumber = scan.next();System.out.print("\n请输入新的密码:");String password = scan.next();System.out.print("\n请输入新的姓名:");String name = scan.next();System.out.print("\n请输入新的性别:");String sex= scan.next();System.out.print("\n请输入新的专业:");String career= scan.next();System.out.print("\n请输入新的住址信息:");String address = scan.next();AdminUser au =new AdminUser(user,phonenumber,identitynumber,password ,name,sex,career,address);boolean add = adminUsers.add(au);if (add) {System.out.println("注册管理员用户成功!");}else{System.out.println("注册失败!");}}//查看管理员账号信息public void adminInfo(AdminUserList adminUser){System.out.println("序号\t\t\t"+"账户名\t\t\t"+"手机号\t\t\t"+"身份证号\t\t\t"+"密码\t\t\t"+"姓名\t\t\t"+"性别\t\t\t"+"专业\t\t\t"+"住址\t\t\t");ArrayList<AdminUser> adminUsers = adminUser.getAdminUsers();for(int i=0;i<adminUsers.size();i++){AdminUser a1= adminUsers.get(i);System.out.println(i+"\t\t\t"+a1.toString());}}//修改管理员账号信息// num 修改信息序号 id 登录的是第几个管理员public void adminAlter(int num,int id,AdminUserList adminUser) {ArrayList<AdminUser> adminUsers = adminUser.getAdminUsers();AdminUser a1 = adminUsers.get(id);if (num == 1) { // 管理员账号名System.out.print("\n请输入新的管理员账户名:");String user = scan.next();a1.setAdminUser(user);} else if (num == 2) { // 手机号码System.out.print("\n请输入新的手机号码:");String phonenumber = scan.next();a1.setAdminPhoneNumber(phonenumber);} else if (num == 3) { // 身份证号码System.out.print("\n请输入新的身份证号码:");String identitynumber = scan.next();a1.setAdminIdentityNumber(identitynumber);} else if (num == 4) { // 密码System.out.print("\n请输入新的密码:");String password = scan.next();a1.setAdminPassword(password);} else if (num == 5) { // 姓名System.out.print("\n请输入新的姓名:");String name = scan.next();a1.setAdminName(name);} else if (num == 6) { // 性别System.out.print("\n请输入新的性别:");String sex = scan.next();a1.setAdminSex(sex);} else if (num == 7) { // 专业System.out.print("\n请输入新的专业:");String career = scan.next();a1.setAdminCareer(career);} else if (num == 8) { // 住址信息System.out.print("\n请输入新的住址信息:");String address = scan.next();a1.setAdminAddress(address);}}
}
NormalUser类:
package com.threecode;import java.util.Scanner;public class NormalUser {private String normalUser;private String normalPhoneNumber;private String normalIdentityNumber;private String normalPassword;private String normalName;private String normalSex;private String normalCareer;private String normalAddress;Scanner scan = new Scanner(System.in);public NormalUser() {}public NormalUser(String normalUser, String normalPhoneNumber, String normalIdentityNumber, String normalPassword, String normalName, String normalSex, String normalCareer, String normalAddress) {this.normalUser = normalUser;this.normalPhoneNumber = normalPhoneNumber;this.normalIdentityNumber = normalIdentityNumber;this.normalPassword = normalPassword;this.normalName = normalName;this.normalSex = normalSex;this.normalCareer = normalCareer;this.normalAddress = normalAddress;}public String getNormalUser() {return normalUser;}public void setNormalUser(String normalUser) {this.normalUser = normalUser;}public String getNormalPhoneNumber() {return normalPhoneNumber;}public void setNormalPhoneNumber(String normalPhoneNumber) {this.normalPhoneNumber = normalPhoneNumber;}public String getNormalIdentityNumber() {return normalIdentityNumber;}public void setNormalIdentityNumber(String normalIdentityNumber) {this.normalIdentityNumber = normalIdentityNumber;}public String getNormalPassword() {return normalPassword;}public void setNormalPassword(String normalPassword) {this.normalPassword = normalPassword;}public String getNormalName() {return normalName;}public void setNormalName(String normalName) {this.normalName = normalName;}public String getNormalSex() {return normalSex;}public void setNormalSex(String normalSex) {this.normalSex = normalSex;}public String getNormalCareer() {return normalCareer;}public void setNormalCareer(String normalCareer) {this.normalCareer = normalCareer;}public String getNormalAddress() {return normalAddress;}public void setNormalAddress(String normalAddress) {this.normalAddress = normalAddress;}@Overridepublic String toString() {return normalUser + "\t\t\t" +normalPhoneNumber + "\t\t\t" +normalIdentityNumber + "\t\t\t" +normalPassword + "\t\t\t" +normalName + "\t\t\t" +normalSex + "\t\t\t" +normalCareer + "\t\t\t" +normalAddress + "\t\t\t" ;}
}
NormalUserList类:
package com.threecode;import java.util.ArrayList;public class NormalUserList {private ArrayList<NormalUser> normalUsers = new ArrayList<NormalUser>();public NormalUserList() {normalUsers.add(new NormalUser("normal", "9999", "123321", "123456", "李四", "男", "艺术", "北京"));}public ArrayList<NormalUser> getNormalUsers() {return normalUsers;}public void setNormalUsers(ArrayList<NormalUser> normalUsers) {this.normalUsers = normalUsers;}
}
NormalUserAction类:
package com.threecode;import java.util.ArrayList;
import java.util.Scanner;public class NormalUserAction {Scanner scan = new Scanner(System.in);// 验证普通用户登录public int loginCheck(NormalUserList normalUser) {ArrayList<NormalUser> normalUsers = normalUser.getNormalUsers();// 普通用户登录验证System.out.print("请输入你要登录的形式(1.手机号码+密码 2.身份证号码+密码):");int verifyNum = scan.nextInt(); //verifyNum 验证方式数字//只能选择一种登录方式while (true) {if (verifyNum == 1 || verifyNum == 2) {break;} else {System.out.print("\n输入错误,请重新输入要选择要操作的序号(只能输入1,2):");verifyNum = scan.nextInt();}}System.out.print("请输入你要登录的普通用户序号(0,1,2,3...):");int normalID = scan.nextInt(); // 登录普通用户账号序号// 1.手机号码+密码 2.身份证号码+密码while(true){if(normalID<=normalUsers.size()-1){break;}else {System.out.print("你输入的管理员账户不存在,请重新输入你要登录的普通用户序号(0,1,2,3...):");normalID = scan.nextInt(); // 登录管理员账号序号}}if (verifyNum == 1) { // 普通用户// 普通用户登录验证 手机号码+密码System.out.print("\n请输入管理员账号(默认normal):");String normalUser1 = scan.next();System.out.print("\n请输入手机号码");String normalPhoneNumber1 = scan.next();System.out.print("\n请输入密码:");String normalPassword1 = scan.next();NormalUser n1=normalUsers.get(normalID);while (true) {if (normalUser1.equals(n1.getNormalUser()) && normalPhoneNumber1.equals(n1.getNormalPhoneNumber()) && normalPassword1.equals(n1.getNormalPassword())) {break;} else {System.out.println("输入信息错误,请重新输入!");System.out.print("\n请输入管理员账号序号(默认normal):");normalUser1 = scan.next();System.out.print("\n请输入手机号码:");normalPhoneNumber1 = scan.next();System.out.print("\n请输入密码:");normalPassword1 = scan.next();}}} else if (verifyNum == 2) { // 普通用户登录验证 身份证号码+密码System.out.print("\n请输入账号(默认normal):");String normalUser2 = scan.next();System.out.print("\n请输入身份证号码:");String normalIdentityNumber2 = scan.next();System.out.print("\n请输入密码:");String normalPassword2 = scan.next();NormalUser n1=normalUsers.get(normalID);while (true) {if (normalUser2.equals(n1.getNormalUser()) && normalIdentityNumber2.equals(n1.getNormalIdentityNumber()) && normalPassword2.equals(n1.getNormalPassword())) {break;} else {System.out.println("输入信息错误,请重新输入!");System.out.print("\n请输入账号:");normalUser2 = scan.next();System.out.print("\n请输入身份证号码:");normalIdentityNumber2 = scan.next();System.out.print("\n请输入密码:");normalPassword2 = scan.next();}}}return normalID;}// 注册普通用户public void addNormalUser(NormalUserList normalUser){ArrayList<NormalUser> normalUsers = normalUser.getNormalUsers();System.out.print("\n请输入新的用户账户名:");String user = scan.next();System.out.print("\n请输入新的手机号码:");String phonenumber = scan.next();System.out.print("\n请输入新的身份证号码:");String identitynumber = scan.next();System.out.print("\n请输入新的密码:");String password = scan.next();System.out.print("\n请输入新的姓名:");String name = scan.next();System.out.print("\n请输入新的性别:");String sex= scan.next();System.out.print("\n请输入新的专业:");String career= scan.next();System.out.print("\n请输入新的住址信息:");String address = scan.next();NormalUser n = new NormalUser(user,phonenumber,identitynumber,password,name,sex,career,address);boolean add = normalUsers.add(n);if (add) {System.out.println("注册普通用户成功!");}else{System.out.println("注册失败!");}}// 查看所有普通用户信息public void allNormal(NormalUserList normalUser){ArrayList<NormalUser> normalUsers = normalUser.getNormalUsers();System.out.println("所有普通用户信息如下:");System.out.println("序号\t\t\t"+"账户名\t\t\t"+"手机号\t\t\t"+"身份证号\t\t\t"+"密码\t\t\t"+"姓名\t\t\t"+"性别\t\t\t"+"专业\t\t\t"+"住址\t\t\t");for(int i=0;i<normalUsers.size();i++){NormalUser n1=normalUsers.get(i);System.out.println(i+"\t\t\t"+n1.toString());}}// 修改用户信息// num 修改信息序号 id 登录的是第几个管理员public void normalAlter(int num,int normalid,NormalUserList normalUser){ArrayList<NormalUser> normalUsers = normalUser.getNormalUsers();NormalUser n1=normalUsers.get(normalid);if(num ==1){ // 管理员账号名System.out.print("\n请输入新的管理员账户名:");String user = scan.next();n1.setNormalUser(user);} else if (num ==2) { // 手机号码System.out.print("\n请输入新的手机号码:");String phonenumber = scan.next();n1.setNormalPhoneNumber(phonenumber);} else if (num ==3) { // 身份证号码System.out.print("\n请输入新的身份证号码:");String identitynumber = scan.next();n1.setNormalIdentityNumber(identitynumber);} else if (num ==4) { // 密码System.out.print("\n请输入新的密码:");String password = scan.next();n1.setNormalPassword(password); ;} else if (num ==5) { // 姓名System.out.print("\n请输入新的姓名:");String name = scan.next();n1.setNormalName(name);} else if (num ==6) { // 性别System.out.print("\n请输入新的性别:");String sex= scan.next();n1.setNormalSex(sex);} else if (num ==7) { // 专业System.out.print("\n请输入新的专业:");String career= scan.next();n1.setNormalCareer(career);} else if (num ==8) { // 住址信息System.out.print("\n请输入新的住址信息:");String address = scan.next();n1.setNormalAddress(address);}}// 显示用户信息(只能查看自己的用户信息)public void myInformation(int normalid,NormalUserList normalUser){ArrayList<NormalUser> normalUsers = normalUser.getNormalUsers();NormalUser n1=normalUsers.get(normalid);System.out.println("个人信息如下:");System.out.println("账户名\t\t\t"+"手机号\t\t\t"+"身份证号\t\t\t"+"密码\t\t\t"+"姓名\t\t\t"+"性别\t\t\t"+"专业\t\t\t"+"住址\t\t\t");System.out.println(n1.toString());}
}
Book类:
package com.threecode;import java.util.Scanner;public class Book {private String bookName;private double bookPrice;private int bookNum;Scanner scan = new Scanner(System.in);public Book() {}public Book(String bookName, double bookPrice, int bookNum) {this.bookName = bookName;this.bookPrice = bookPrice;this.bookNum = bookNum;}public String getBookName() {return bookName;}public double getBookPrice() {return bookPrice;}public int getBookNum() {return bookNum;}public void setBookName(String bookName) {this.bookName = bookName;}public void setBookPrice(double bookPrice) {this.bookPrice = bookPrice;}public void setBookNum(int bookNum) {this.bookNum = bookNum;}@Overridepublic String toString() {return bookName + "\t\t\t" + bookPrice+"\t\t\t" + bookNum ;}
}
BookList类:
package com.threecode;import java.util.LinkedList;public class BookList {private LinkedList<Book> books = new LinkedList<Book>();public BookList() {books.add(new Book("C语言", 50.0, 40));books.add(new Book("Python", 40.0, 20));books.add(new Book("Java", 20.0, 35));books.add(new Book("Go", 45.0, 44));books.add(new Book("C++", 38.0, 47));}public LinkedList<Book> getBooks() {return books;}public void setBooks(LinkedList<Book> books) {this.books = books;}
}
BookAction类:
package com.threecode;import java.util.LinkedList;
import java.util.Scanner;public class BookAction {Scanner scan = new Scanner(System.in);// 查看所有图书public void viewAllBook(BookList bookList){System.out.println("序号\t\t\t书名\t\t\t价格\t\t\t数量");LinkedList<Book> books = bookList.getBooks();int i=0;for(Book book : books){System.out.println(i+"\t\t\t"+book);i++;}}// 添加图书public void addBook(BookList bookList){System.out.print("\n请输入图书名:");String name = scan.next();System.out.print("\n请输入图书价格:");double price = scan.nextDouble();System.out.print("\n请输入图书数量:");int num = scan.nextInt();Book book1 = new Book(name,price,num);LinkedList<Book> book= bookList.getBooks();boolean add = book.add(book1);if (add) {System.out.println("添加图书信息如下:");System.out.println("序号\t\t\t书名\t\t\t价格\t\t\t数量");System.out.println(book.size()-1+"\t\t\t"+book.getLast().toString());System.out.println("添加成功!");}else{System.out.println("添加图书失败!");}}// 修改图书public void alterBook(BookList bookList){LinkedList<Book> book= bookList.getBooks();System.out.print("请输入修改图书序号:");int bookID=scan.nextInt(); //修改图书序号while(true){if(bookID>=0&&bookID<book.size()){break;}else {System.out.println("输入错误,请输入(0~"+(book.size()-1)+")内数字:");bookID=scan.nextInt();}}Book b1 = book.get(bookID);System.out.print("\n请输入图书名:");String name = scan.next();b1.setBookName(name);System.out.print("\n请输入图书价格:");double price = scan.nextDouble();b1.setBookPrice(price);System.out.print("\n请输入图书数量:");int num = scan.nextInt();b1.setBookNum(num);}// delete 删除图书public void deleteBook(BookList bookList) {LinkedList<Book> book= bookList.getBooks();System.out.println("请输入删除图书序号:");int bookID=scan.nextInt(); //修改图书序号while(true){if (bookID >= 0 &&bookID < book.size()) {book.remove(bookID);System.out.println("删除成功!");break;}else {System.out.println("输入错误,请重新输入删除图书序号:");bookID=scan.nextInt(); //修改图书序号}}}// 借阅图书public void borrowBook(BookList bookList){LinkedList<Book> book= bookList.getBooks();System.out.print("\n请输入你要借阅图书序号:");int numbook = scan.nextInt();Book b1 = book.get(numbook);System.out.print("\n该图书还有"+b1.getBookNum()+"本");System.out.print("\n请输入你要借的图书数量:");int nums = scan.nextInt(); // 借阅数量if((b1.getBookNum()-nums)>=0){b1.setBookNum(b1.getBookNum()-nums);int num = b1.getBookNum();System.out.print("\n恭喜你借阅成功,该图书还剩余"+num+"本\n");}else{System.out.print("\n很遗憾,该图书已经全被借阅!");}}// 归还图书public void giveBackBook(BookList bookList){LinkedList<Book> book= bookList.getBooks();System.out.print("\n请输入你要归还图书序号:");int bk = scan.nextInt();Book b1 = book.get(bk);System.out.print("\n该图书目前剩余"+b1.getBookNum()+"本");System.out.print("\n请输入归还书本数目:");int givenum = scan.nextInt();b1.setBookNum(b1.getBookNum()+givenum);int num =b1.getBookNum();System.out.print("\n恭喜你归还成功,现剩余该图书"+num+"本");}
}
Tool类:
package com.threecode;public class Tool {public void page1(){System.out.println("----------------请选择登录方式----------------");System.out.println(" 1、登录账号");System.out.println(" 2、注册账号");System.out.println(" 3、退出登录");}public void page2(){System.out.println("********欢迎进入登录账号页面********");System.out.println("1.管理员登录:");System.out.println("2.普通用户登录:");}public void page3(){System.out.println("\n-----------欢迎进入管理员账号页面-----------");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("7、修改管理员账号信息");System.out.println("8、退出系统");}public void page4(){System.out.println("\n-----------普通用户登录成功-----------");System.out.println("1.查看所有图书");System.out.println("2.借阅图书");System.out.println("3.归还图书");System.out.println("4.显示用户信息(只能查看自己的用户信息)");System.out.println("5.修改用户信息(只能修改自己的用户信息)");System.out.println("6.退出系统");}public void page5(){System.out.println("********欢迎进入注册账号页面********");System.out.println("1.管理员注册:");System.out.println("2.普通用户注册:");}}
BooksManagementSystemThree类:
package com.threecode;import java.util.Scanner;public class BooksManagementSystemThree {public static void main(String[] args) {Scanner scan = new Scanner(System.in);Tool tool = new Tool();AdminUserList adminUserList = new AdminUserList();AdminUserAction adminUserAction = new AdminUserAction();NormalUserList normalUserList = new NormalUserList();NormalUserAction normalUserAction = new NormalUserAction();BookList bookList = new BookList();BookAction bookAction = new BookAction();while(true){while(true) {tool.page1();System.out.print("请输入要选择要操作的序号(只能输入1,2,3):");int loginNum = scan.nextInt();// 校验输入的序号,只能是1到3while (true) {if (loginNum == 1 || loginNum == 2 || loginNum == 3) {break;} else {System.out.print("请输入要选择要操作的序号(只能输入1,2,3):");loginNum = scan.nextInt();}}switch(loginNum){case 1:tool.page2();System.out.print("请输入要选择要操作的序号(只能输入1,2):");int enterNum =scan.nextInt(); //enterNum登录数字 1.管理员 2.用户while(true){if(enterNum == 1||enterNum == 2 ){break;}else{System.out.print("输入错误,请从从新输入要选择要操作的序号(只能输入1,2):");enterNum =scan.nextInt();}}if(enterNum==1){int adminID = adminUserAction.loginCheck(adminUserList);while(true) {tool.page3();System.out.print("请输入你选择的功能:");int adminnum = scan.nextInt(); // adminnum 管理员账号页面功能查看while(true){if(adminnum>=1&&adminnum<=8){break;}else{System.out.print("输入错误,请重新输入你选择的功能:");adminnum = scan.nextInt();}}if(adminnum ==1){ //1、查看所有图书bookAction.viewAllBook(bookList);continue;} else if (adminnum==2) { //2、添加图书bookAction.addBook(bookList);continue;} else if (adminnum==3) { //3、修改图书 //这里设计的是符合图书序号的所有图书信息都可以修改bookAction.alterBook(bookList);continue;} else if (adminnum==4) { //4、删除图书bookAction.deleteBook(bookList);continue;} else if (adminnum==5) { //5、查看所有普通用户信息normalUserAction.allNormal(normalUserList);continue;} else if (adminnum==6) { //6、查看管理员账号信息adminUserAction.adminInfo(adminUserList);continue;} else if (adminnum==7) { //7、修改管理员账号信息System.out.println("请输入要修改管理员账号的的信息(1管理员账号名2手机号码3" +"身份证号码4密码5姓名6性别7专业8住址信息):");int adID =scan.nextInt(); // adID 修改序号adminUserAction.adminAlter(adID, adminID,adminUserList);continue;}else if (adminnum==8){ //8、退出系统System.out.println("谢谢使用,欢迎下次光临!");System.exit(0);;}}} else if (enterNum == 2) {int normalID = normalUserAction.loginCheck(normalUserList);while(true){tool.page4();System.out.print("请输入你需要操作功能的数字:");int onetwo1 = scan.nextInt(); // 选择功能数字if(onetwo1==1){ // 1.查看所有图书bookAction.viewAllBook(bookList);continue;} else if (onetwo1==2) { // 2.借阅图书bookAction.borrowBook(bookList);continue;} else if (onetwo1==3) { // 3.归还图书bookAction.giveBackBook(bookList);continue;} else if (onetwo1==4) { // 4.显示用户信息(只能查看自己的用户信息)normalUserAction.myInformation(normalID,normalUserList);continue;} else if (onetwo1==5) { // 5.修改用户信息(只能修改自己的用户信息)System.out.print("\n请输入你要修改的信息的选项(1普通用户账号名2手机号码" +"3身份证号码4密码5姓名6性别7专业8住址信息):");int num=scan.nextInt(); // normalchange 修改序号normalUserAction.normalAlter( num, normalID,normalUserList);continue;} else if (onetwo1==6) { // 6.退出系统System.out.print("\n谢谢使用,欢迎下次光临!");System.exit(0);;}}}case 2:tool.page5();System.out.print("请输入要选择要操作的序号(只能输入1,2):");int registernum = scan.nextInt(); //注册管理员或者普通用户while(true){if(registernum>0||registernum<3){break;}else {System.out.println("输入序号错误,请重新输入要操作的序号(只能输入1,2):");registernum = scan.nextInt();}}if(registernum==1){adminUserAction.addAdminUser(adminUserList);continue;} else if (registernum==2) {normalUserAction.addNormalUser(normalUserList);continue;}case 3:System.out.println("谢谢使用,欢迎下次光临!");System.exit(0);;}}}}
}
五、项目运行结果
说明一下:这里并没有校验输入数据限制,是没写,太麻烦了,读者想要校验输入格式可以自行实现。
这里输入的数字均是int类型,输入其他类型数据可能直接报错退出程序。
说明:功能没有截图完全,其余功能实现,读者可以自行运行实现查看。
六、项目难点分析
1、校验功能数字是自己规定的数字
使用while(true){}循环实现,在循环体中设置只有输入规定数字才能跳出循环,执行后面的代码。
System.out.print("请输入要选择要操作的序号(只能输入1,2):");int enterNum =scan.nextInt(); //enterNum登录数字 1.管理员 2.用户while(true){if(enterNum == 1||enterNum == 2 ){break;}else{System.out.print("输入错误,请从从新输入要选择要操作的序号(只能输入1,2):");enterNum =scan.nextInt();}}
2、明确变量的定义域
要清楚自己定义的变量作用的范围:
在Java中,变量的作用域决定了变量在程序中可见的范围。如果一个变量被定义在一个代码块内部,那么它的作用域就被限制在该代码块内部。如果一个变量被定义在方法内部,那么它的作用域就被限制在该方法内部。如果一个变量被定义在类内部但方法之外,那么它的作用域就是整个类。
这里要注意的是,作用范围大的变量,例如adminUser、bookName...等等,要定义在整个循环体的外面,若是定义在while(){}、for(;;){}、do{}while()三种循环和if(){}else{}、switch(){}选择语句中变量,作用域只能在循环体或者选择语句中,只用在循环体或者选择语句中使用,此范围之外,不能使用,或者可能出现操作该变量失效的现象。
3、将其划分为不同的类,在不同类里面进行不同类单独的属性方法的开发与封装。
4、加入集合的操作,取代数组对数据的存储。
根据集合的特点使用:
a)ArrayList 底层是数组实现的,方便查询操作
这里管理员用户和普通用户类,基本很少涉及增删,所以使用ArrayList 集合
b)LinkedList 底层是双向链表实现的,方便增加和删除
这里的Book类可能涉及多次的增删,所以使用LinkedList集合
5、数据的转型(多态)
例如, 这里的
ArrayList<NormalUser> normalUsers = normalUser.getNormalUsers();
在NormalUserAction类中,想要使用NormalUser类中的属性,必须要从集合中取出目标操作类,将其转换为NormalUser,才可以使用其定义的特有方法。
NormalUser n1=normalUsers.get(normalid);
相关文章:

图书管理系统(ArrayList和LinkedList)--versions3.0
目录 一、项目要求: 二、项目环境 三、项目使用的知识点 四、项目代码 五、项目运行结果 六、项目难点分析 图书管理系统--versions1.0: 图书管理系统--versions1.0-CSDN博客文章浏览阅读981次,点赞29次,收藏17次。本文使用…...

游戏开发丨基于Pygame的AI版贪吃蛇小游戏
文章目录 写在前面需求分析程序设计程序分析运行结果系列文章写在后面 写在前面 本期内容 基于pygame的AI版贪吃蛇小游戏 所需环境 pythonpycharm或anacondapygame 下载地址 https://download.csdn.net/download/m0_68111267/88789665 需求分析 本游戏使用Pygame模块开…...

qt-C++笔记之QStringList、QList<QString>、QString、QChar、QList<QChar>区别
qt-C笔记之QStringList、QList、QString、QChar、QList区别 —— 杭州 2024-01-30 凌晨0:27 参考博文:qt-C笔记之QStringList code review! 文章目录 qt-C笔记之QStringList、QList<QString>、QString、QChar、QList<QChar>区别1.Qt的字符容器类1.QSt…...
python爬虫学习之解析_BeautifulSoup
目录 一、bs4的基本使用 (1)导入 (2)创建对象 二、节点定位 1、根据标签名查找节点 2、基本函数使用 (1)find (2)find_all (3)select 三、节点信息 1、获取节…...
2024美赛数学建模赛题解读常用模型算法
回归拟合预测 拟合预测是建立一个模型去逼近实际数据序列的过程,适用于发展性的体系。建立模型时,通常都要指定一个有明确意义的时间原点和时间单位。而且,当t趋向于无穷大时,模型应当仍然有意义。将拟合预测单独作为一类体系研究…...
NoSQL 数据库管理系统和模型的比较
前些天发现了一个人工智能学习网站,通俗易懂,风趣幽默,最重要的屌图甚多,忍不住分享一下给大家。点击跳转到网站。 NoSQL 数据库管理系统和模型的比较 介绍 当大多数人想到数据库时,他们通常会想到传统的关系数据库…...
数据库(SQL)
目录 1 触发器 1.1 触发器简介 1.2 触发器的创建 语法 说明 1.3 示例 2 存储过程 2.1 什么是存储过程(函数) 2.1.1 存储过程和存储函数的区别 2.2 优势 2.3 应用场景 2.4 存储过程的创建和使用 说明 各参数类型所实现的存储过程 无参数无返…...

如何用Docker+jenkins 运行 python 自动化?
1.在 Linux 服务器安装 docker 2.创建 jenkins 容器 3.根据自动化项目依赖包构建 python 镜像(构建自动化 python 环境) 4.运行新的 python 容器,执行 jenkins 从仓库中拉下来的自动化项目 5.执行完成之后删除容器 前言 环境准备 Linux 服务器一台(我的是 CentOS7)…...

uniapp瀑布流实现
1. 图片瀑布流: 不依赖任何插件,复制即可见效: <template><view class"page"><view class"left" ref"left"><image class"image" v-for"(item,i) in leftList" :k…...

鸿蒙:@Link装饰器-父子双向同步
子组件中被Link装饰的变量与其父组件中对应的数据源建立双向数据绑定。从API version 9开始,该装饰器支持在ArkTS卡片中使用。 需要注意:Link装饰的变量与其父组件中的数据源共享相同的值。Link装饰器不能在Entry装饰的自定义组件中使用。 一、装饰器使…...
Leetcode--27
给你一个数组 nums 和一个值 val,你需要 原地 移除所有数值等于 val 的元素,并返回移除后数组的新长度。 不要使用额外的数组空间,你必须仅使用 O(1) 额外空间并 原地 修改输入数组。 元素的顺序可以改变。你不需要考虑数组中超出新长度后面…...

使用Eclipse搞Android项目报错
相信现在都没什么人还会用Eclipse来开发的了。 不过安装完后,打开Eclipse会提示我的Jdk版本不符合 --------------------------- Incompatible JVM --------------------------- Version 1.8.0_391 of the JVM is not suitable for this product. Version: 17 or g…...
import sys是什么
import sys语句 允许你使用sys模块提供的各种功能,从而更好地与Python解释器和操作系统底层进行交互。通过熟练掌握sys模块的使用,可以大大提高Python开发的效率和灵活性。 sys模块 是Python的内置模块之一,用于与Python解释器和系统环境交…...

Python爬虫:XPath基本语法
XPath(XML Path Language)是一种用于在XML文档中定位元素的语言。它使用路径表达式来选择节点或节点集,类似于文件系统中的路径表达式。 不啰嗦,讲究使用,直接上案例。 导入 pip3 install lxmlfrom lxml import etr…...

UML/SysML建模工具更新情况(截至2024年1月)(1)UModel 2024
最近一段时间更新的工具有: 工具最新版本:Umple 1.33.0 更新时间:2024年1月10日 工具简介 自称“Model-Oriented Programming”,把图形和文本结合起来,支持Java、PHP和Ruby代码生成,可以在线使用…...

ubuntu20-github不通问题
github不通 一直在github下载失败 Git报错fatal unable to connect to github.com: github.com[0: 20.205.243.166] >>> alsa-ucm-conf v1.2.6.3 Downloading(卡在这里,很烦啊) 然后搜了很多文档,然后以下操作: 1.GitHub.com - GitHub: Lets build from here Git…...

【MAC】Multi-Level Monte Carlo Actor-Critic阅读笔记
基本思想: 利用多层次蒙特卡洛方法(Multi-Level Monte Carlo,MLMC)和Actor-Critic算法,解决平均奖励强化学习中的快速混合问题。 快速混合? 在强化学习中,当我们说一个策略"混合得快"…...

[GN] 设计模式—— 创建型模式
文章目录 创建型模式单例模式 -- 确保对象唯一性例子优化饿汉式懒汉式 优缺点使用场景 简单工厂模式例子:优化优缺点适用场景 工厂方法模式 -- 多态工厂的实现例子优缺点优化适用场景 抽象工厂模式 -- 产品族的创建例子优缺点适用场景 总结 创建型模式 单例模式 –…...

链表——超详细
一、无头单向非循环链表 1.结构(两个部分): typedef int SLTDataType; typedef struct SListNode {SLTDataType data;//数据域struct SListNode* next;//指针域 }SLNode; 它只有一个数字域和一个指针域,里面数据域就是所存放的…...

【刷题】 leetcode 面试题 08.05.递归乘法
递归乘法 1 题目描述2 思路一(返璞归真版)3 思路二(二进制乘法器版)4 思路三(变态版)Thanks♪(・ω・)ノ谢谢阅读下一篇文章见!!! 1 题目…...
SkyWalking 10.2.0 SWCK 配置过程
SkyWalking 10.2.0 & SWCK 配置过程 skywalking oap-server & ui 使用Docker安装在K8S集群以外,K8S集群中的微服务使用initContainer按命名空间将skywalking-java-agent注入到业务容器中。 SWCK有整套的解决方案,全安装在K8S群集中。 具体可参…...

8k长序列建模,蛋白质语言模型Prot42仅利用目标蛋白序列即可生成高亲和力结合剂
蛋白质结合剂(如抗体、抑制肽)在疾病诊断、成像分析及靶向药物递送等关键场景中发挥着不可替代的作用。传统上,高特异性蛋白质结合剂的开发高度依赖噬菌体展示、定向进化等实验技术,但这类方法普遍面临资源消耗巨大、研发周期冗长…...
【论文笔记】若干矿井粉尘检测算法概述
总的来说,传统机器学习、传统机器学习与深度学习的结合、LSTM等算法所需要的数据集来源于矿井传感器测量的粉尘浓度,通过建立回归模型来预测未来矿井的粉尘浓度。传统机器学习算法性能易受数据中极端值的影响。YOLO等计算机视觉算法所需要的数据集来源于…...
【Go】3、Go语言进阶与依赖管理
前言 本系列文章参考自稀土掘金上的 【字节内部课】公开课,做自我学习总结整理。 Go语言并发编程 Go语言原生支持并发编程,它的核心机制是 Goroutine 协程、Channel 通道,并基于CSP(Communicating Sequential Processes࿰…...

k8s业务程序联调工具-KtConnect
概述 原理 工具作用是建立了一个从本地到集群的单向VPN,根据VPN原理,打通两个内网必然需要借助一个公共中继节点,ktconnect工具巧妙的利用k8s原生的portforward能力,简化了建立连接的过程,apiserver间接起到了中继节…...
[Java恶补day16] 238.除自身以外数组的乘积
给你一个整数数组 nums,返回 数组 answer ,其中 answer[i] 等于 nums 中除 nums[i] 之外其余各元素的乘积 。 题目数据 保证 数组 nums之中任意元素的全部前缀元素和后缀的乘积都在 32 位 整数范围内。 请 不要使用除法,且在 O(n) 时间复杂度…...

自然语言处理——循环神经网络
自然语言处理——循环神经网络 循环神经网络应用到基于机器学习的自然语言处理任务序列到类别同步的序列到序列模式异步的序列到序列模式 参数学习和长程依赖问题基于门控的循环神经网络门控循环单元(GRU)长短期记忆神经网络(LSTM)…...
代理篇12|深入理解 Vite中的Proxy接口代理配置
在前端开发中,常常会遇到 跨域请求接口 的情况。为了解决这个问题,Vite 和 Webpack 都提供了 proxy 代理功能,用于将本地开发请求转发到后端服务器。 什么是代理(proxy)? 代理是在开发过程中,前端项目通过开发服务器,将指定的请求“转发”到真实的后端服务器,从而绕…...
React---day11
14.4 react-redux第三方库 提供connect、thunk之类的函数 以获取一个banner数据为例子 store: 我们在使用异步的时候理应是要使用中间件的,但是configureStore 已经自动集成了 redux-thunk,注意action里面要返回函数 import { configureS…...

uniapp 小程序 学习(一)
利用Hbuilder 创建项目 运行到内置浏览器看效果 下载微信小程序 安装到Hbuilder 下载地址 :开发者工具默认安装 设置服务端口号 在Hbuilder中设置微信小程序 配置 找到运行设置,将微信开发者工具放入到Hbuilder中, 打开后出现 如下 bug 解…...