zoukankan      html  css  js  c++  java
  • 图书管理系统 简易版(JAVA)

    自己参照某租车系统写的一个图书管理系统
    代码如下:
    BOOK抽象类

    package com.BookSystem;

    public abstract class Book {
    int id;
    String name;
    int price;
    int must_learn;
    int select_learn;

    public Book(int id,String name, int price,int must_learn, int select_learn){
    this.id= id;
    this.name=name;
    this.price=price;
    this.must_learn=must_learn;
    this.select_learn=select_learn;

    }
    public abstract void pri();
    }


    story类

    package com.BookSystem;

    public class Story extends Book{


    public Story(int id, String name, int price,int select_learn) {
    super(id, name, price, 0, select_learn);
    // TODO Auto-generated constructor stub
    }

    @Override
    public void pri() {
    // TODO Auto-generated method stub
    System.out.println(id+" " +name +" " +price+"元 " +select_learn);
    }

    }


    profession类

    package com.BookSystem;

    public class Profession extends Book{

    public Profession(int id, String name, int price,int must_learn) {
    super(id, name, price, must_learn,0);
    // TODO Auto-generated constructor stub
    }

    @Override
    public void pri() {
    // TODO Auto-generated method stub
    System.out.println(id +" " +name +" " +price+"元 "+must_learn);
    }

    }


    book_Admin

    package com.BookSystem;

    import java.util.Scanner;

    public class Book_Admin {
    int sum_price=0;
    int sum_must = 0;
    int sum_select = 0;

    StringBuilder pri_must = new StringBuilder();
    StringBuilder pri_select = new StringBuilder();
    Scanner in = new Scanner(System.in);



    public Book[] book_message() {
    Book[] books = {
    new Story(1,"简爱",45, 1),
    new Story(2,"悲惨世界",56,1),
    new Story(3,"安娜",34,1),
    new Profession(4,"计算机基础",43,1),
    new Profession(5,"JAVA基础",65,1),

    };
    System.out.println("您可租借的书目及价格表");
    System.out.println("ID 名称 价格 数量");
    for(int i = 0; i<books.length; i++) {
    books[i].pri();
    }
    return books;
    }




    public void book_admin_function(Book[] books) {
    //客户选择书籍、数量
    System.out.println("请输入需要借的数量");
    int number = in.nextInt();

    for (int i = 0; i<number;i++)
    {
    System.out.println("请输入"+(i+1)+"书籍序号");

    int id = in.nextInt();
    //用户输入从1开始 数组下标从0开始
    sum_must +=books[id-1].must_learn;
    sum_select+=books[id-1].select_learn;
    sum_price+=books[id-1].price;

    if (books[id-1].must_learn>0)
    {
    pri_must.append(books[id-1].name+" ");
    }
    if (books[id-1].select_learn>0)
    {
    pri_select.append(books[id-1].name +" ");
    }
    }

    System.out.println("---------租书明细-----------");
    System.out.println("专业课书籍:"+pri_must);
    System.out.println("课外书籍:"+pri_select);
    System.out.println("书籍数量:" +(sum_must+sum_select));

    this.pri_bill(sum_price);

    }



    private void pri_bill(int sum_price2) {
    // TODO Auto-generated method stub
    System.out.println("请输入需要借的天数");
    int num = in.nextInt();
    System.out.println("-----租书总价格-----");
    System.out.println("您的借书费用为:"+ num*sum_price2+"元");
    }

    }


    TestSystem主函数

    package com.BookSystem;

    import java.util.Scanner;

    public class TestSystem {

    Scanner in = new Scanner(System.in);
    public static void main(String[] args) {
    // TODO Auto-generated method stub
    TestSystem testSystem = new TestSystem();


    }


    public TestSystem() {
    System.out.println("欢迎使用图书管理系统:");
    System.out.println("是否进入此系统:Y/N");
    while(true) {
    String enter;
    enter = in.next();
    enter = enter.toUpperCase();
    if(enter.equals("Y")) {
    Book_Admin book_admin = new Book_Admin();
    Book[] book = book_admin.book_message();
    book_admin.book_admin_function(book);
    }

    else
    {
    System.out.println("感谢您的使用:请输入'N'退出此系统");
    String str ;
    str = in.next();
    str = str.toUpperCase();
    if (str.equals("N")) {
    break;
    }
    }
    }
    }

    }

  • 相关阅读:
    [Silverlight]App.Current Events中的Startup,UnhandledException以及Exit事件
    [Silverlight]使用DoubleAnimation为对象添加动画效果
    [翻译]ASP.NET MVC Tip #39 – 在ASP.NET MVC中使用分布式缓存
    [翻译]ASP.NET MVC CodePlex Preview 5 更新细节(未完成)
    [Silverlight]打造具有放大缩小效果的图片导航
    [Silverlight]Silverlight2中打造SplashScreen 1
    [Silverlight]如何创建超链接
    [Silverlight]TextBlock控件全攻略
    [转]ajax框架比较
    MonoRail学习之源码放送
  • 原文地址:https://www.cnblogs.com/lixia0604/p/15433058.html
Copyright © 2011-2022 走看看