题目:【物品租赁系统】
一.语言和环境
A. Java
B. 环境要求
二.功能要求
完成“物品租赁系统”。
【必做】功能包括:
1、查看所有物品
2、查看物品租用情况
3、出租物品
4、归还物品
【选做】以下功能选做:
5、购置物品
6、报废物品
三.数据库设计
无。

四.具体要求及推荐实现步骤
1、【5分】创建java项目,创建包及抽象的设备父类Device,属性包括总共的数量和剩余的数量(备注:总共的数量是指该设备共购进了多少个,剩余的数量是减去了被租用出去的数量后剩余的),两个抽象方法。
提示:计算租金方法原型:
public abstract double calcRent(int days);
显示信息方法原型:
public abstract void showInfo();

2、【10分】创建两个子类笔记本Computer和U盘USBDisk,笔记本类增加型号属性,U盘类增加容量属性。重写计算租金和显示信息两个方法。计算租金的具体要求如下:

类别 型号/容量 每日租金(元)

笔记本

联想13.9英寸超轻薄翻转笔记本 10
小米15.6英寸金属轻薄笔记本 8.8
惠普小欧14英寸笔记本 5
其他型号笔记本 4

U盘

容量1T 1.48
容量512G 1
容量256G 0.88
容量低于256G 0.5

3、【5分】创建租用设备类RentDevice,包括租用学生的学号和租用的设备两个属性(备注:租用的设备是设备父类Device类型的)。方法包括显示信息,按要求打印租用人的学号和租用的物品信息。
4、创建管理类RentManager
//所有设备数组
private Device[] devices = new Device[100];
//出租设备数组
private RentDevice[] rentDevices = new RentDevice[100];
方法请自行根据下面的运行截图封装,要求代码规范。

4.1 【10分】系统运行后,首先显示帮助信息和功能列表:

4.2 【10分】若用户选择菜单1,则显示系统初始化的所有物品清单:

4.3 【10分】若用户选择菜单2,则显示所有已经出租的物品清单:

4.4 【20分】若用户选择菜单3,则显示所有物品供用户租用,需要输入租用的序号以及租用人的学号:

此时重新查看所有物品,剩余数量减1了:

同时,若查看已经租用的物品,可以看到刚租的物品信息:

4.5【20分】 若用户选择菜单4,需要输入归还的物品序号和租用的天数并打印结算的租金信息:

此时重新查看所有物品,剩余数量重新增加1:

已经租用的物品中需要删除归还的物品信息:

5、【5分】创建测试类测试上述功能。

代码实现

package com.biu.demo01;//设备父类Device
public abstract class Device {private int totalCounts;private int remainCounts;//计算租金方法public abstract double calcRent(int days);//显示信息方法public abstract void showInfo();public Device() {super();}public Device(int totalCounts, int remainCounts) {super();this.totalCounts = totalCounts;this.remainCounts = remainCounts;}public int getTotalCounts() {return totalCounts;}public void setTotalCounts(int totalCounts) {this.totalCounts = totalCounts;}public int getRemainCounts() {return remainCounts;}public void setRemainCounts(int remainCounts) {this.remainCounts = remainCounts;}}
package com.biu.demo01;//子类:电脑类
public class Computer extends Device {private String type;public final static String[] computertype={"联想13.9英寸超轻薄翻转笔记本","小米15.6英寸金属轻薄笔记本","惠普小欧14英寸笔记本","其他型号笔记本"};public final static double[] computermoney={10,8.8,5,4};//计算租金@Overridepublic double calcRent(int days) {double money = days * getDayMoney();return money;}//获取当前型号对应的日租金public double getDayMoney() {for(int i=0;i<computertype.length;i++){if(computertype[i].equals(type)){return computermoney[i];}}return 0;}//显示信息@Overridepublic void showInfo() {System.out.println("笔记本,型号:" + type + ", 总数量:" + this.getTotalCounts() + ", 目前剩余数量:" + this.getRemainCounts());}public Computer() {super();}public Computer(int totalCounts, int remainCounts, String type) {super(totalCounts, remainCounts);this.type = type;}public String getType() {return type;}public void setType(String type) {this.type = type;}}
package com.biu.demo01;//子类:U盘
public class USBDisk extends Device {private String volume;public final static String[] usbvolume={"容量1T","容量512G","容量256G","容量低于256G"};public final static double[] usbmoney={1.48,1,0.88,0.5};//计算租金@Overridepublic double calcRent(int days) {double money = days * getDayMoney();return money;}//获取当前日租金public double getDayMoney() {for(int i=0; i<usbvolume.length; i++) {if(volume.equals(usbvolume[i])) {return usbmoney[i];}}return 0;}//显示信息@Overridepublic void showInfo() {System.out.println("U盘,存储容量为:" + volume + ", 总数量:" + this.getTotalCounts() + ", 目前剩余容量:" + this.getRemainCounts());}public USBDisk() {super();}public USBDisk(int totalCounts, int remainCounts, String volume) {super(totalCounts, remainCounts);this.volume = volume;}public String getVolume() {return volume;}public void setVolume(String volume) {this.volume = volume;}}
package com.biu.demo01;public class RentDevice {private String sId;// 学号private Device device;// 设备对象@Overridepublic String toString() {String str = "租用人学号:" + sId + ", 物品信息:";if(device instanceof Computer) {Computer computer = (Computer)device;str += computer.getType();}else if(device instanceof USBDisk) {USBDisk usbDisk = (USBDisk)device;str += usbDisk.getVolume();}return str;}public RentDevice() {super();}public RentDevice(String sId, Device device) {super();this.sId = sId;this.device = device;}public String getsId() {return sId;}public void setsId(String sId) {this.sId = sId;}public Device getDevice() {return device;}public void setDevice(Device device) {this.device = device;}}
package com.biu.demo01;import java.util.Arrays;
import java.util.Scanner;//租借管理类
public class RentManager {Scanner sc = new Scanner(System.in);private Device[] devices = new Device[7];//所有设备数组private RentDevice[] rentDevices = new RentDevice[2];//出租设备数组//初始化对象并显示public void init() {devices[0] = new Computer(100, 99, Computer.computertype[0]);devices[1] = new USBDisk(200, 199, USBDisk.usbvolume[1]);devices[2] = new Computer(50, 50, Computer.computertype[1]);devices[3] = new USBDisk(150, 150, USBDisk.usbvolume[2]);devices[4] = new USBDisk(60, 60, USBDisk.usbvolume[0]);devices[5] = new Computer(60, 60, Computer.computertype[2]);devices[6] = new USBDisk(30, 30, USBDisk.usbvolume[3]);rentDevices[0] = new RentDevice("stu000",devices[3]);rentDevices[1] = new RentDevice("stu001",devices[0]);}//菜单public void menu() {System.out.println("系统功能列表");System.out.println("1、查看所有物品");System.out.println("2、查看物品租用情况");System.out.println("3、出租物品");System.out.println("4、归还物品");System.out.println("0、退出系统");System.out.print("请选择>>>");}//1、查看所有物品public void showAllDevice() {for(int i=0; i<devices.length; i++) {if(devices[i]!=null) {System.out.print(i+1 + "  ");devices[i].showInfo();}}} //2、查看物品租用情况public void showRentDevice() {for(int i=0;i<rentDevices.length;i++){if(rentDevices[i]!=null) {System.out.println(i+1+"  "+rentDevices[i].toString());}}}//3、出租物品public void rentDevice() {showAllDevice();System.out.print("请输入您要租赁的物品序号:");int num = sc.nextInt();if (num > devices.length || num < 1) {System.out.println("输入有误");} else {System.out.print("请输入租用人的学号:");String sId = sc.next();Device device = devices[num - 1];if (device.getRemainCounts() < 1) {System.out.println("该设备数量不足,不能出租");} else {RentDevice rentdevice = new RentDevice(sId, device);rentDevices = Arrays.copyOf(rentDevices, rentDevices.length + 1);rentDevices[rentDevices.length - 1] = rentdevice;device.setRemainCounts(device.getRemainCounts() - 1);System.out.println("租用成功。" + rentdevice.toString());}}}//4、归还物品public void returnDevice() {showAllDevice();System.out.println("请输入要归还的物品序号:");int i=sc.nextInt();if(i>rentDevices.length||i<1){System.out.println("输入有误");}else{System.out.println("请输入出租天数");int day=sc.nextInt();int index=i-1;//索引为序号减1RentDevice rentdevice=rentDevices[index];RentDevice[] temp=new RentDevice[rentDevices.length-1];System.arraycopy(rentDevices, 0, temp, 0, index);System.arraycopy(rentDevices, index+1, temp, index, temp.length-index);rentDevices=temp;Device d=rentdevice.getDevice();d.setRemainCounts(d.getRemainCounts()+1);double money=d.calcRent(day);System.out.println("归还成功,"+rentdevice.toString());System.out.println(day+"天的租金为:"+money + "元");}}//程序开始运行public void start() {menu();int choose = sc.nextInt();switch (choose) {case 1://1、查看所有物品showAllDevice();break;case 2://2、查看物品租用情况showRentDevice();break;case 3://3、出租物品rentDevice();break;case 4://4、归还物品returnDevice();break;case 0://0.退出System.out.println("您已成功退出~");return;default:System.out.println("你输入的功能号有误!");break;}System.out.println();start();}
}
package com.biu.demo01;//运行测试类
public class Test {public static void main(String[] args) {RentManager mgr = new RentManager();mgr.init();mgr.start();}
}

Day23:面向对象项目之物品租赁系统相关推荐

  1. SpringBoot/SSM 物品租赁系统 摄影器材租赁系统

    基于SpringBoot/SSM的物品租赁系统 预览地址:http://doremi.liuyanzhao.com 后台部分代码地址:GitHub - saysky/doremi: SpringBoo ...

  2. 物品租赁系统(SSM,mysql)

    物品租赁系统(SSM,mysql) [项目包含内容] [项目运行教程] [项目运行工具] Eclipse + JDK1.8 + TOMCAT8 + MYSQL         注意: Tomcat8中 ...

  3. SSM毕设项目乡村不动产租赁系统0sie7(java+VUE+Mybatis+Maven+Mysql)

    SSM毕设项目乡村不动产租赁系统0sie7(java+VUE+Mybatis+Maven+Mysql) 项目运行 环境配置: Jdk1.8 + Tomcat8.5 + Mysql + HBuilder ...

  4. uniapp+vue微信小程序java python物资物品租赁系统php

    系统管理也都将通过计算机进行整体智能化操作,对于社团物品租赁所牵扯的管理及数据保存都是非常多的,管理端:首页.个人中心.用户管理.物品类别管理.物品信息管理.租赁订单管理.物品续租管理.物品归还管理. ...

  5. javaweb物品租赁系统源码(毕设)

    开发环境及工具: 大等于jdk1.8,大于mysql5.5,idea(eclipse) 技术说明: springboot mybatis html vue.js bootstrap 代码注释齐全,没有 ...

  6. springboot vue uniapp物品租赁系统源码

    开发环境及工具: 大于Jdk1.8,大于mysql5.5,idea(eclipse),HBuilder,vscode(webstorm) 技术说明: Springboot mybatis elemen ...

  7. 基于springboot vue elementui的物品租赁系统源码

    开发环境及工具: 大等于jdk1.8,大于mysql5.5,idea(eclipse),vscode(webstorm) 技术说明: springboot mybatis vue elementui ...

  8. 基于Spring Boot的物品租赁系统

    文章目录 项目介绍 主要功能截图: 登录 注册 物品信息 租赁信息 租金信息 用户信息 部分代码展示 设计总结 项目获取方式

  9. php短租平台通用物品租赁系统

    随着计算机的普及应用,计算机已经成为人们社会生产和日常生活中不可缺少的部分.现在各行各业都在推行信息化,以提供效益和竞争力.现在的很多短租网站的经营的方向发展.在这个商务过程中,传统的基于纸介质的数据 ...

最新文章

  1. Tungsten Fabric SDN — 网络架构
  2. 使用Spring Cloud Function框架进行面向函数的编程
  3. Kafka使用Java客户端进行访问
  4. 【MFC开发(8)】下拉框控件Combo Box
  5. 人工智能教学解决方案
  6. 系列1—BabeLua入门
  7. android 哈哈镜,Carnival Mirror App(哈哈镜模拟器)
  8. python藏头诗_Python简单实现表白藏头诗-Go语言中文社区
  9. Balsamiq Mockups注册码
  10. 苹果于近日推送了 iOS 14.5 开发者预览版 Beta
  11. 字节跳动2019校招笔试题(后端开发)一
  12. python布尔型变量错误的赋值_Python中布尔变量的值为( )
  13. yolov3--25--Detectron目标检测可视化-P-R曲线绘制-Recall-TP-FP-FN等评价指标
  14. python中int() 按照“四舍五入”的方式取整
  15. JS生成 GUID 或 UUID 四种方法
  16. 【CCF CSP】【Python】【201903-1】小中大
  17. AppleID的申请流程
  18. MR过程和Shuffle详解
  19. 【Linux】快捷键
  20. 日常英语单词 - 食物

热门文章

  1. 语音识别 ——总结知识点(2)
  2. 同一个电脑可安装多个python版本吗_一台电脑能否同时安装不同版本的Python?
  3. Selenium实战教程系列(三)--- Selenium中的动作
  4. 一个经典的嵌入式裸机系统
  5. Cuckoo全部安装过程
  6. MySQL条件查询语句(一)
  7. 【考前冲刺】计算机三级网络技术之综合题-sniffer抓包分析
  8. java 超长字符串处理_JAVA的StringBuffer类( 较长字符串处理时,代替String)
  9. swift5 接入内购全流程
  10. HDU-1848--博弈SG函数模板题