java——图书管理系统


package tushuguananli;

import java.text.SimpleDateFormat;

import java.util.Date;

public class TuShu {

    // 状态  名称  借出时间

    public  String state;

    public  String name;

    public  Date date;

public  void setTuShu(String zhuangtai , String mingzi, Date riqi){

    state=zhuangtai;

    name=mingzi;

    date=riqi;

}

    public void print( int index){

        System.out.println(index+"\t"+name+"\t"+state+"\t"+date);

    }

}

package tushuguananli;

public class TuShuSet {

    TuShu[] tushus=new TuShu[30];

}

package tushuguananli;

import sun.util.calendar.BaseCalendar;

import java.text.DateFormat;

import java.text.ParseException;

import java.text.SimpleDateFormat;

import java.util.Date;

import java.util.Scanner;

public class TuShuManage {

    TuShuSet tushuset=new TuShuSet();

    //仓库初始化  放入商品

    public void initila(){

        TuShu  tushu1=new TuShu();

        tushu1.setTuShu( "已借出" ,"<>", new Date());

          TuShu tushu2=new TuShu();

          tushu2.setTuShu("可借", "<<数据库技术>>", null);

          TuShu tushu3=new TuShu();

          tushu3.setTuShu("可借",  "<<人与神话>>" ,null);

          tushuset.tushus[0]=tushu1;

          tushuset.tushus[1]=tushu2;

          tushuset.tushus[2]=tushu3;

    }

    //菜单

    public  void  startMenu() throws ParseException {

        System.out.println("欢迎使用图书管理系统");

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

        boolean flag=true;

        do{

        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("请选择:");

        Scanner scanner=new Scanner(System.in);

        int num=scanner.nextInt();

        switch (num){

            case 1:

                System.out.println("--->新增图书");

                xinzeng();

                break;

            case 2:

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

                chakan();

                break;

            case 3:

                System.out.println("--->删除图书");

                shanchu();

                break;

            case 4:

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

                jiechu();

                break;

            case 5:

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

                guihuan();

                break;

            case 6:

                System.out.println("--->退出");

                flag=false;

                break;

            default:

                System.out.println("请再次输入");

        }

        }while(flag);

    }

    public void xinzeng(){

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

            Scanner scanner=new  Scanner(System.in);

            String mingzi1=scanner.next();

            System.out.println("新增"+mingzi1+"成功");

            TuShu tuShu4=new TuShu();

            tuShu4.setTuShu("可借",mingzi1,null);

        for (int i = 0; i < tushuset.tushus.length; i++) {

            if (tushuset.tushus[i] == null) {

                tushuset.tushus[i] = tuShu4; // 把新建的对象放在数组中的第一个空位置

                break; // 后续的空位置直接跳过

            }

        }

    }

    public  void chakan(){

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

          for(int i=0;i

你可能感兴趣的:(java——图书管理系统)