首页 > 其他 > 详细

图书馆系统

时间:2020-12-09 21:00:48      阅读:30      评论:0      收藏:0      [点我收藏+]

1.功能调查与系统功能框架图

功能调查:图书馆系统主要功能包括查看馆内藏书,查看书籍借阅状态,借阅图书以及归还图书的基本信息登记。
技术分享图片

2.类的设计

技术分享图片
技术分享图片

3.类的说明

Book类
public class Book {

    private String name; 

    private int state; 

    private String date;

    private int count;

     

    public Book(String name,int state, String date, int count) 

    { 

        this.name = name; 

        this.state = state; 

        this.date = date;

        this.count = count;

    } 

     

    public String getName() { 

        return name; 

    } 

    public int getState() { 

        return state; 

    } 

    public String getDate() { 

        return date; 

    } 

    public int getCount() { 

        return count; 

    } 

    public void setName(String name) { 

        this.name = name; 

       

    } 

    public void setState(int state) { 

        this.state = state; 

       

    } 

    public void setDate(String date) { 

        this.date = date; 

       

    } 

    public void setCount(int count) { 

        this.count = count; 

       

    } 
    
}

bookMgr类
package Library;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Scanner;

public class bookMgr {
	ArrayList<Book> bookList = new ArrayList<Book>();
	public void initial(){

	       //初始化

	       Book book1 = new Book("java程序设计",0,"2020-12-01",1);

	       Book book2 = new Book("python教程",1,"",15);

	       Book book3 = new Book("C语言程序设计",1,"",23);

	       bookList.add(book1);

	       bookList.add(book2);

	       bookList.add(book3);

	    }
	
	public void showBooks(){

	       System.out.println("---->查看图书\n");

	       System.out.println("序号\t状态\t名称\t\t剩余数量\t\t借出日期");

	       for(int i=0;i<bookList.size();i++){

	           if(bookList.get(i).getState()==0){

	              System.out.println((i+1)+"\t已借出\t"+"<<"+bookList.get(i).getName()+">>\t\t\t"

	                +bookList.get(i).getDate());

	           }else if(bookList.get(i).getState()==1){

	              System.out.println((i+1)+"\t可借\t"+"<<"+bookList.get(i).getName()+">>\t"+bookList.get(i).getCount());

	           }

	       }

	       System.out.println("*************************************************");

	       return;

	    }
	
	public void lend(){

	       boolean flag = false;

	       System.out.println("---->借出图书\n");

	       Scanner input = new Scanner(System.in);

	       System.out.println("请输入图书名称:");

	       String wantname = input.next();

	       for(int i=0;i<bookList.size();i++){

	           if(bookList.get(i).getName()==null){

	              System.out.println("没有找到该图书!");

	              break;

	           }else if( bookList.get(i).getName().equals(wantname)

	                  && bookList.get(i).getState()==1){

	              bookList.get(i).setState(0);

	              System.out.println("请输入借书日期(年-月-日):");

	              String date=input.next();

	              bookList.get(i).setDate(date);

	              System.out.println("图书借出成功,欢迎下次使用!");

	              break;

	           }else if( bookList.get(i).getName().equalsIgnoreCase(wantname)

	               && bookList.get(i).getState()==0){

	              System.out.println("《"+wantname+"》已被借出,抱歉!");

	              break;

	           }

	        }

	       System.out.println("*************************************************");

	       return;

	    }
	public void returnBook(){

	       boolean flag = false;

	       Scanner input = new Scanner(System.in);


	       System.out.println("---->归还图书\n");

	       System.out.println("请输入图书名称:");

	       String wantname = input.next();

	       for(int i=0;i<bookList.size();i++){

	           if(bookList.get(i).getName()==null){

	              System.out.println("没有找到该图书!");

	              break;

	           }else if(bookList.get(i).getName().equalsIgnoreCase(wantname)

	                  &&bookList.get(i).getState()==0){

	           bookList.get(i).setState(1);

	           System.out.println("请输入日期(年-月-日):");

	           String returndate = input.next();


	               System.out.println("借出日期为:"+bookList.get(i).getDate());

	               System.out.println("归还日期为:"+returndate);

	              
	               System.out.println("\n归还<<"+wantname+">>成功!");

	              

	               bookList.get(i).setCount(bookList.get(i).getCount()+1); 

	               break;

	           }else if(bookList.get(i).getName().equalsIgnoreCase(wantname)&&bookList.get(i).getState()==1){

	           System.out.println("输入错误!!《"+wantname+"未被借出");

	           break;

	           }

	       }

	       System.out.println("*************************************************");

	       return;

	    }
test类
public class Test {

	 

    public static void main(String[] args) {

    	while(true) {
			System.out.println("-------------------欢迎使用图书馆管理系统-------------------");
			System.out.println("[1].图书列表\n[2].查找图书\n[3].借阅图书\n[4].归还图书\n[5].退出\n");
			System.out.println("请选择:\n");
			Scanner input = new Scanner(System.in);	
			bookMgr mgr=new bookMgr();
			mgr.initial();
			int choice = input.nextInt();
			if(choice == 1) {
				mgr.showBooks();
			}else if(choice ==2) {
				
			}else if(choice ==3) {
				mgr.lend();
			}else if(choice ==4) {
				mgr.returnBook();
			}
		}

    }

}

4.Gitee代码

Gitee代码

5.效果展示

技术分享图片

技术分享图片

技术分享图片

图书馆系统

原文:https://www.cnblogs.com/dcftx/p/14110863.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!