package KindMethod2;
// 属性块
public class Library {
private String name; //图书名称
private int state; //借阅状态,0:可借阅,1:已借出
private int date; //借出日期
private int count; //借出次数
public Library() {
}
public Library(String name, int state, int date, int count) {
this.name = name;
this.state = state;
this.date = date;
this.count = count;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getState() {
return state;
}
public void setState(int state) {
this.state = state;
}
public int getDate() {
return date;
}
public void setDate(int date) {
this.date = date;
}
public int getCount() {
return count;
}
public void setCount(int count) {
this.count = count;
}
}
- package KindMethod2;
-
- public class BookRealize {
- private Library[] librarie; //存储图书数组
- private int total; //数组下标
-
- public Library[] getLibrarie() {
- return librarie;
- }
-
- public void setLibrarie(Library[] librarie) {
- this.librarie = librarie;
- }
-
- public int getTotal() {
- return total;
- }
-
- public void setTotal(int total) {
- this.total = total;
- }
- public BookRealize(int tota){
- librarie=new Library[tota];
- }
- // 新增图书
- public boolean addBook(Library library){
- if(total<0 || total>librarie.length){
- return false;
- }else{
- librarie[total++]=library;
- return true;
- }
- }
- // 查看图书
- public Library[] showBook(){
- Library[] newlibraries= new Library[total];
- for(int i=0 ;i
- newlibraries[i]=librarie[i];
- }
- return newlibraries;
- }
-
-
- // 删除图书
- public boolean deleteBook(int num){
- if(num>total || num<0){
- return false;
- }else{
- Library[] newLibraries=new Library[total];
- for(int i=num;i
- librarie[i]=newLibraries[i];
- }
- librarie[--total]=null;
- return true;
- }
- }
- // 借出图书
- public boolean borrow(int num){
- if(num>total || num<0 || librarie[num].getState()==1){
- return false;
- }else{
- librarie[num].setState(1);
- librarie[num].setCount(librarie[num].getCount()+1);
- return true;
- }
- // Library[] newlibraries1 = new Library[total];
- // int num=0;
- // for(int j=0;j
- // if (newlibraries1[j].getState()==0){
- // newlibraries1[num++]=newlibraries1[j];
- // }
- // }
- // return newlibraries1;
- }
-
- // 归还图书
- public boolean retur(int num){
- if(num>total || num<0 || librarie[num].getState()==0){
- return false;
- }else{
- librarie[num].setState(0);
- return true;
- }
- }
- }
- package KindMethod2;
-
- import java.util.Scanner;
-
- public class Test {
- BookRealize bookRealize = new BookRealize(6);
- public Test(){
- Library library =new Library("三国演义",0,21,23);
- bookRealize.addBook(library);
- }
- Scanner sc =new Scanner(System.in);
- public void setting(){
- boolean bool=true;
- do{
- System.out.println("----------------------迷你图书管理系统---------------------");
- System.out.println("\t\t1、新增图书");
- System.out.println("\t\t2、查看图书");
- System.out.println("\t\t3、删除图书");
- System.out.println("\t\t4、借出图书");
- System.out.println("\t\t5、归还图书");
- System.out.println("\t\t6、退出图书系统");
- System.out.print("请选择:");
- int choose = sc.nextInt();
- switch (choose){
- case 1:
- addBook();
- break;
- case 2:
- showBook();
- break;
- case 3:
- deleteBook();
- break;
- case 4:
- borrowBook();
- break;
- case 5:
- retueBook();
- break;
- case 6:
- bool=false;
- System.out.println("已退出");
- }
- }while(bool);
- }
- // 增加
- public void addBook(){
- System.out.println("--------------------新增图书----------------------");
- System.out.print("图书名称");
- String name = sc.next();
- System.out.print("借阅状态(0:可借阅,1:已借出)");
- int state = sc.nextInt();
- System.out.print("借出日期(当月1-31号)");
- int date = sc.nextInt();
- System.out.print("借出次数");
- int count = sc.nextInt();
- Library library=new Library(name,state,date,count);
- boolean boole=bookRealize.addBook(library);
- if(boole==true){
- System.out.println("\t添加成功");
- }else{
- System.out.println("\t添加失败");
- }
- }
- // 查看图书
- public void showBook(){
- Library[] books = bookRealize.showBook();
- if(books==null){
- System.out.println("你没有任何图书");
- return;
- }
- System.out.println("编号"+"\t\t名字"+"\t\t借阅状态"+"\t\t借出日期"+"\t借出次数");
- for(int i=0;i
- System.out.println((i+1)+"\t\t"+books[i].getName()+"\t\t"+books[i].getState()+"\t\t"+
- books[i].getDate()+"\t\t"+books[i].getCount());
- }
- return;
- }
- // 删除图书
- public void deleteBook(){
- Library[] books = bookRealize.showBook();
- System.out.println("编号"+"\t\t名字"+"\t\t借阅状态"+"\t\t借出日期"+"\t\t借出次数");
- for(int i=0;i
- System.out.println((i+1)+"\t\t"+books[i].getName()+"\t\t"+books[i].getState()+"\t\t"+
- books[i].getDate()+"\t\t"+books[i].getCount());
- }
- System.out.print("请输入要删除图书的编号:");
- int num= sc.nextInt();
- boolean boole =bookRealize.deleteBook(num-1);
- if (boole==true){
- System.out.println("删除图书成功");
- }else{
- System.out.println("删除图书失败");
- }
- return;
- }
- // 借出图书
- public void borrowBook(){
- Library[] books = bookRealize.showBook();
- System.out.println("编号"+"\t\t名字"+"\t\t借阅状态"+"\t\t借出日期"+"\t\t借出次数");
- for(int i=0;i
- System.out.println((i+1)+"\t\t"+books[i].getName()+"\t\t"+books[i].getState()+"\t\t"+
- books[i].getDate()+"\t\t"+books[i].getCount());
- }
- System.out.print("请输入要借书的书号:");
- int num = sc.nextInt();
- boolean boole=bookRealize.borrow(num-1);
- if(boole==true){
- System.out.println("借书成功");
- }else{
- System.out.println("借书失败,输入有误或已经借出去了");
- }
- return;
- }
- // 归还图书
- public void retueBook(){
- Library[] books = bookRealize.showBook();
- System.out.println("编号"+"\t\t名字"+"\t\t借阅状态"+"\t\t借出日期"+"\t\t借出次数");
- for(int i=0;i
- System.out.println((i+1)+"\t\t"+books[i].getName()+"\t\t"+books[i].getState()+"\t\t"+
- books[i].getDate()+"\t\t"+books[i].getCount());
- }
- System.out.print("请输入要还书的书号:");
- int num = sc.nextInt();
- boolean boole=bookRealize.borrow(num-1);
- if(boole==true){
- System.out.println("还书成功");
- }else{
- System.out.println("还书失败,输入的书号有误");
- }
- return;
- }
- public static void main(String[] args) {
- Test test = new Test();
- test.setting();
- }
- }
-
相关阅读:
手机如何压缩照片?压缩方法分享
【面试题-Java】2022面试题干货汇总(持续更新)
excel导入导出demo笔记
Lombok注解的简单使用
JAVA电视设备租借系统计算机毕业设计Mybatis+系统+数据库+调试部署
Java毕业设计 基于springboot vue大学新生报到系统
Harris/Shi-Tomasi角点检测
k8s--基础--23.6--认证-授权-准入控制--通过kubeconfig登陆dashboard
第一个 Python 程序
比较一个5点的结构对平面的分割
-
原文地址:https://blog.csdn.net/fool_Java/article/details/126234767