期末小作业-图书馆管理系统
立即下载
资源介绍:
很普通的的初学者se代码,考虑很多学生懒得写期末作业,或者想要改的更快,直接打包看就行,非常容易看懂,0基础也是直接能改。
package MangerBook;
import java.util.Scanner;
public class BookDaoLmpl implements BookDao
{
Book books[]= new Book[10];
Scanner scanner = new Scanner(System.in);
@Override
public void uilogin()
{
//工号默认2024007
//密码默认123
System.out.println("*******************");
System.out.println("图书管理系统登录");
System.out.println("*******************");
System.out.println("请输入工号:");
String idlogin = scanner.next();
System.out.println("请输入密码:");
String namelogin = scanner.next();
if (idlogin.equals("2024007") && namelogin.equals("123")){
System.out.println("登陆成功......");
ui();
}
else {
System.out.println("密码错误");
}
}
@Override
public void ui()
{
while (true){
System.out.println("*******************");
System.out.println("学生信息管理系统");
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.println("7- 查询所有图书信息");
System.out.println("8- 退出系统");
System.out.println("*******************");
System.out.println("请输入你的选择:");
int choose = scanner.nextInt();
if (choose==1){
add();
}
else if (choose==2) {
update();
}
else if (choose==3) {
delete();
}
else if (choose==4) {
selectById();
}
else if (choose==5) {
selectByName();
}
else if (choose==6) {
selectByPrice();
}
else if (choose==7) {
selectAll();
}
else if (choose==8) {
System.out.println("是否退出系统?");
System.out.println("1. 退出 2.取消");
int chooseexit = scanner.nextInt();
if (chooseexit == 1) {
System.out.println("正在退出......");
break;
}
else if (chooseexit==2){
System.out.println("取消退出!");
}else {
System.out.println("非法字符,请重新输入!");
}
}
else {
System.out.println("非法字符,请重新输入!");
}
}
}
@Override
public void add()
{
int id1;
String name1;
String author1;
double price1;
System.out.println("请输入你要录入图书信息的编号");
id1 = scanner.nextInt();
if (isOnly(id1)==false){
System.out.println("没有该编号的图书信息,请录入!");
System.out.println("请输入图书的名称");
name1 = scanner.next();
System.out.println("请输入图书的作者");
author1 = scanner.next();
System.out.println("请输入图书的价格");
price1 = scanner.nextInt();
for (int i = 0; i < books.length; i++) {
if (books[i]==null){
books[i] = new Book(id1,name1,author1,price1);
System.out.println("录入成功");
books[i].show();
break;
}
}
}
else {
System.out.println("已经存在此编号的图书信息!重新核对编号");
}
}
@Override
public void delete()
{
System.out.println("请输入你要删除的图书的编号!");
int id = scanner.nextInt();
if (isOnly(id)==true){
for (int i = 0; i < books.length; i++) {
if (books[i]!=null){
if (books[i].getId()==id){
System.out.println("信息如下:");
books[i].show();
System.out.println("是否删除此信息?");
System.out.println("1. 确认 2.取消");
int choosedelete = scanner.nextInt();
if (choosedelete==1){
System.out.println("正在删除......");
books[i] = null;
System.out.println("删除成功!");
}
else if (choosedelete==2) {
System.out.println("已取消!");
}
else {
System.out.println("请输入合法数字!");
}
}
}
}
}
else {
System.out.println("不存在这个编号的图书信息,无法删除");
}
}
@Override
public void update()
{
System.out.println("请输入你要修改的图书的编号!");
int id = scanner.nextInt();
if (isOnly(id)==true){
for (int i = 0; i < books.length; i++) {
if (books[i]!=null){
if (books[i].getId()==id){
System.out.println("旧信息如下:");
books[i].show();
System.out.println("是否更新此信息?");
System.out.println("1. 确认 2.取消");
int choosedelete = scanner.nextInt();
if (choosedelete==1){
System.out.println("开始更新......");
System.out.println("请输入新的书名:");
String name = scanner.next();
System.out.println("请输入新的作者:");
String author = scanner.next();
System.out.println("请输入新的价格:");
double price = scanner.nextInt();
Book bookupdate = new Book(id,name,author,price);
books[i] = bookupdate;
System.out.println("更新成功!");
}
else if (choosedelete==2) {
System.out.println("已取消!");
}
else {
System.out.println("请输入合法数字!");
}
}
}
}
}
else {
System.out.println("不存在这个编号的图书信息,无法修改");
System.out.println("如需要添加此信息字段,请在主界面选择添加学生信息!");
}
}
@Override
public void selectByName() {
int countIndex = -1;
boolean isSelect = false;
System.out.println("书名模糊查询,请输入书名:");
String input = scanner.next();
for (int i = 0; i < books.length; i++) {
if (books[i] != null) {
if (books[i].getName().