Java面向对象总结性项目 之 图书馆管理代码

编程入门 行业动态 更新时间:2024-10-26 16:23:07

Java面向对象<a href=https://www.elefans.com/category/jswz/34/1002621.html style=总结性项目 之 图书馆管理代码"/>

Java面向对象总结性项目 之 图书馆管理代码

Java面向对象总结性项目 之 图书馆管理代码

  • 简介
  • 核心需求
  • 类的设计
    • 架构
    • 创建图书相关的类
    • 创建书架相关的类
    • 创建用户相关的类
      • 对于管理员
      • 对于用户
    • 创建 Main 类和 main 方法, 搭建整体逻辑
    • 实现具体的每个 Operation
  • 该Java程序运行结果
    • 用户端
    • 管理员

简介

利用前面所学的知识点:类,抽象类,封装,继承,多态,接口等进行的一个简单的代码练习。

核心需求

  1. 简单的登录功能
  2. 对于管理员,实现以下功能:
    查找书籍
    增加书籍
    删除书籍
    显示所有图书
    退出系统
  3. 对于用户,实现以下功能:
    查询书籍
    借阅书籍
    归还书籍
    退出系统

类的设计

架构

该Java程序架构如下

创建图书相关的类

package book;public class Book {private String name;//书名private String author;//作者private int price;//价格private String type;//类型private boolean status;//状态public Book(String name, String author, int price, String type) {this.name = name;this.author = author;this.price = price;this.type = type;}public String getName() {return name;}public void setName(String name) {this.name = name;}public String getAuthor() {return author;}public void setAuthor(String author) {this.author = author;}public int getPrice() {return price;}public void setPrice(int price) {this.price = price;}public String getType() {return type;}public void setType(String type) {this.type = type;}public boolean isStatus() {return status;}public void setStatus(boolean status) {this.status = status;}@Overridepublic String toString() {return "Book{" +"name='" + name + '\'' +", author='" + author + '\'' +", price=" + price +", type='" + type + '\'' +", status=" + /*status +*/( (status == true)?"‘借出’":"‘未借出’")+'}';}
}

创建书架相关的类

package book;public class BookList {private Book[] books;private int usedSize;public BookList() {this.books = new Book[10];books[0] = new Book("三国演义","罗贯中",56,"小说");books[1] = new Book("水浒传","施耐庵",58,"小说");books[2] = new Book("西游记","吴承恩",66,"小说");books[3] = new Book("红楼梦","曹雪芹",46,"小说");this.usedSize = 4;}//尾插法public void setBooks(int pos,Book book){this.books[pos] = book;}public Book getBook(int pos){return this.books[pos];}public int getUsedSize() {return usedSize;}public void setUsedSize(int usedSize) {this.usedSize = usedSize;}
}

创建用户相关的类

package user;import book.BookList;
import operation.IOperation;public abstract class User {public String name;public IOperation[] operations;public User(String name){this.name = name;}public abstract int menu();public void doOperation(int choice, BookList bookList){this.operations[choice].work(bookList

更多推荐

Java面向对象总结性项目 之 图书馆管理代码

本文发布于:2024-02-11 17:48:20,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1682405.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:总结性   面向对象   图书馆   代码   项目

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!