当前位置: 首页 > news >正文

房屋租赁系统-java

思维导图:业务逻辑

 

类的存放:

工具类 Utility

package study.houserent.util;
import java.util.*;
/***/
public class Utility {//静态属性。。。private static Scanner scanner = new Scanner(System.in);/*** 功能:读取键盘输入的一个菜单选项,值:1——5的范围* @return 1——5*/public static char readMenuSelection() {char c;for (; ; ) {String str = readKeyBoard(1, false);//包含一个字符的字符串c = str.charAt(0);//将字符串转换成字符char类型if (c != '1' && c != '2' &&c != '3' && c != '4' && c != '5') {System.out.print("选择错误,请重新输入:");} else break;}return c;}/*** 功能:读取键盘输入的一个字符* @return 一个字符*/public static char readChar() {String str = readKeyBoard(1, false);//就是一个字符return str.charAt(0);}/*** 功能:读取键盘输入的一个字符,如果直接按回车,则返回指定的默认值;否则返回输入的那个字符* @param defaultValue 指定的默认值* @return 默认值或输入的字符*/public static char readChar(char defaultValue) {String str = readKeyBoard(1, true);//要么是空字符串,要么是一个字符return (str.length() == 0) ? defaultValue : str.charAt(0);}/*** 功能:读取键盘输入的整型,长度小于2位* @return 整数*/public static int readInt() {int n;for (; ; ) {String str = readKeyBoard(10, false);//一个整数,长度<=10位try {n = Integer.parseInt(str);//将字符串转换成整数break;} catch (NumberFormatException e) {System.out.print("数字输入错误,请重新输入:");}}return n;}/*** 功能:读取键盘输入的 整数或默认值,如果直接回车,则返回默认值,否则返回输入的整数* @param defaultValue 指定的默认值* @return 整数或默认值*/public static int readInt(int defaultValue) {int n;for (; ; ) {String str = readKeyBoard(10, true);if (str.equals("")) {return defaultValue;}//异常处理...try {n = Integer.parseInt(str);break;} catch (NumberFormatException e) {System.out.print("数字输入错误,请重新输入:");}}return n;}/*** 功能:读取键盘输入的指定长度的字符串* @param limit 限制的长度* @return 指定长度的字符串*/public static String readString(int limit) {return readKeyBoard(limit, false);}/*** 功能:读取键盘输入的指定长度的字符串或默认值,如果直接回车,返回默认值,否则返回字符串* @param limit 限制的长度* @param defaultValue 指定的默认值* @return 指定长度的字符串*/public static String readString(int limit, String defaultValue) {String str = readKeyBoard(limit, true);return str.equals("")? defaultValue : str;}/*** 功能:读取键盘输入的确认选项,Y或N* 将小的功能,封装到一个方法中.* @return Y或N*/public static char readConfirmSelection() {System.out.println("请输入你的选择(Y/N): 请小心选择");char c;for (; ; ) {//无限循环//在这里,将接受到字符,转成了大写字母//y => Y n=>NString str = readKeyBoard(1, false).toUpperCase();c = str.charAt(0);if (c == 'Y' || c == 'N') {break;} else {System.out.print("选择错误,请重新输入:");}}return c;}/*** 功能: 读取一个字符串* @param limit 读取的长度* @param blankReturn 如果为true ,表示 可以读空字符串。* 					  如果为false表示 不能读空字符串。**	如果输入为空,或者输入大于limit的长度,就会提示重新输入。* @return*/private static String readKeyBoard(int limit, boolean blankReturn) {//定义了字符串String line = "";//scanner.hasNextLine() 判断有没有下一行while (scanner.hasNextLine()) {line = scanner.nextLine();//读取这一行//如果line.length=0, 即用户没有输入任何内容,直接回车if (line.length() == 0) {if (blankReturn) return line;//如果blankReturn=true,可以返回空串else continue; //如果blankReturn=false,不接受空串,必须输入内容}//如果用户输入的内容大于了 limit,就提示重写输入//如果用户如的内容 >0 <= limit ,我就接受if (line.length() < 1 || line.length() > limit) {System.out.print("输入长度(不能大于" + limit + ")错误,请重新输入:");continue;}break;}return line;}
}

House类

package study.houserent.domain;
/*
house类的对象代表一个信息*/
public class House {private  int id;private  String name;private  String iphone;private  int rent;//ctrl +aprivate  String state;public int getId() {return id;}public void setId(int id) {this.id = id;}public String getName() {return name;}public void setName(String name) {this.name = name;}public String getIphone() {return iphone;}public void setIphone(String iphone) {this.iphone = iphone;}public int getRent() {return rent;}public void setRent(int rent) {this.rent = rent;}public String getState() {return state;}public void setState(String state) {this.state = state;}public House(int id, String name, String iphone, int rent, String state) {this.id = id;this.name = name;this.iphone = iphone;this.rent = rent;this.state = state;}@Overridepublic String toString() {return  id + "\t"+ name + "\t" + iphone + "\t" + rent + "\t"+ state ;}
}

HouseSerive类

package study.houserent.serive;
import study.houserent.domain.House;
import study.houserent.atil.Utility;public class HouseService {private  House[] houses;private int houseNums=1;private int idCounter=1;public boolean add(House newhouse){if(houseNums==houses.length){System.out.println("已满");return  false;}houses[houseNums]=newhouse;houseNums++;idCounter++;newhouse.setId(idCounter);
//        newhouse.setId(++idCounter);return true;}public House changeID(int change){for(int i=0;i<houseNums;i++){if(houses[i].getId()==change){System.out.print("姓名:");String name= Utility.readString(8);System.out.print("电话:");String phone=Utility.readString(12);System.out.print("月租: ");int rent=Utility.readInt();System.out.println("状态:");String state =Utility.readString(3);houses[i].setName(name);houses[i].setIphone(phone);houses[i].setRent(rent);houses[i].setState(state);return houses[i];}}return null;}public House findById(int findid){for(int i=0;i<houseNums;i++){if(findid==houses[i].getId()){return houses[i];}}return null;}public boolean del(int delid){int  index=-1;for(int i=0;i<houseNums;i++){if(delid==houses[i].getId()){index=i;}}if(index==-1){return false;}else{for(int i=index;i<houseNums-1;i++){houses[i]=houses[i+1];}houses[--houseNums]=null;return true;}}public HouseService(int size){houses =new House[size];houses[0]=new House(1,"A","100",2000,"未出租");}public House[] list() {return houses;}
}

HouseView类

package study.houserent.views;
import study.houserent.domain.House;
import study.houserent.serive.HouseService;
import study.houserent.atil.Utility;
public class HouseView {private boolean loop=true;private char key=' ';public HouseService houseService=new HouseService(10);public void exit(){char c=Utility.readConfirmSelection();if(c=='Y'){loop=false;}}public void addhouse(){System.out.println("===========添加房屋==========");System.out.print("姓名:");String name=Utility.readString(8);System.out.print("电话:");String phone=Utility.readString(12);System.out.print("地址:");String address=Utility.readString(16);System.out.print("月租: ");int rent=Utility.readInt();System.out.println("状态:");String state =Utility.readString(3);House newhouse = new House(0,name, phone, rent, state);if(houseService.add(newhouse)){System.out.println("==========添加房屋=========");}else{System.out.println("========添加房屋失败=======");}}public void findHouse(){System.out.println("=========查找房屋信息=======");System.out.println("输入查找的房间号:");int findid=Utility.readInt();House house=houseService.findById(findid);System.out.println((house==null)?"=======查找失败=====":house);}public void listHouses(){System.out.println("============房屋出租系统=======");System.out.println("编号  房主  电话  地址  状态");House[] houses=houseService.list();for(Object q:houses){if(q==null);else System.out.println(q);}System.out.println("房屋列表显示完毕");}public void changeHouses(){System.out.println("=====修改房屋信息========");System.out.println("修改的房间号:");int change=Utility.readInt();House house=houseService.changeID(change);System.out.println((house==null)?"=======不存在=====":house);}public void    delHouse(){System.out.println("================删除房屋============");System.out.println("请输入待删除房屋的编号:");int deTid=Utility.readInt();if(deTid==-1){System.out.println("放弃删除房屋");return;}char choice=Utility.readConfirmSelection();if(choice=='Y'){//在调用方法if(houseService.del(deTid)){System.out.println("===========删除房屋信息成功=========");}else{System.out.println("=============删除失败===========");}}else{System.out.println("放弃删除房屋");}}public void mainMenu (){do{System.out.println("=============房屋租赁系统===========");System.out.println("\t\t\t[新 增 房 源]");System.out.println("\t\t\t[查 找 房 间]");System.out.println("\t\t\t[删 除 房 屋 信 息]");System.out.println("\t\t\t[修 改 房 屋 信 息]");System.out.println("\t\t\t[房 屋 列 表]");System.out.println("\t\t\t 其输入你得选择【1-6】");key= Utility.readChar();switch( key){case '1':System.out.println("新 增");addhouse();listHouses();break;case '2':System.out.println("查 找 房 间");findHouse();listHouses();break;case '3':System.out.println("删除房屋信息");delHouse();listHouses();break;case '4':System.out.println("修改房屋信息");changeHouses();listHouses();break;case '5':System.out.println("房屋列表");listHouses();break;case '6':exit();System.out.println("退出");listHouses();}}while(loop);}}

HouserentApp类 运行入口

package study.houserent;import study.houserent.domain.House;
import study.houserent.views.HouseView;public class houseRentApp {public static void main(String[] args) {//创造程序入口new HouseView().mainMenu();System.out.println("=========你退出房屋出租系统===============");}
}

相关文章:

房屋租赁系统-java

思维导图&#xff1a;业务逻辑 类的存放&#xff1a; 工具类 Utility package study.houserent.util; import java.util.*; /***/ public class Utility {//静态属性。。。private static Scanner scanner new Scanner(System.in);/*** 功能&#xff1a;读取键盘输入的一个菜单…...

docker环境搭建及其安装常用软件

centos安装docker Install Docker Engine on CentOS | Docker Docs 下载docker sudo yum install -y yum-utils sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo sudo yum install -y docker-ce docker-ce-cli containerd.io…...

【Spring连载】使用Spring Data访问Redis(三)----连接模式

【Spring连载】使用Spring Data访问Redis&#xff08;三&#xff09;----连接模式Connection Modes 一、Redis Standalone二、向Master写入&#xff0c;从Replica读取三、Redis Sentinel四、Redis Cluster Redis可以在各种设置中运行。每种操作模式都需要特定的配置&#xff0c…...

ppt背景图片怎么设置?让你的演示更加出彩!

PowerPoint是一款广泛应用于演示文稿制作的软件&#xff0c;而背景图片是演示文稿中不可或缺的一部分。一个好的背景图片能够提升演示文稿的整体效果&#xff0c;使观众更加关注你的演示内容。可是ppt背景图片怎么设置呢&#xff1f;本文将介绍ppt背景图片设置的三个方法&#…...

SQL 关键字参考手册(一)

目录 SQL 关键字 SQL ADD 关键字 ADD SQL ADD CONSTRAINT 关键字 ADD CONSTRAINT SQL ALTER 关键字 ALTER TABLE ALTER COLUMN SQL ALTER COLUMN 关键字 ALTER COLUMN SQL ALTER TABLE 关键字 ALTER TABLE SQL ALL 关键字 ALL SQL AND 关键字 AND SQL ANY 关键…...

快速排序|超详细讲解|入门深入学习排序算法

快速排序介绍 快速排序(Quick Sort)使用分治法策略。 它的基本思想是&#xff1a;选择一个基准数&#xff0c;通过一趟排序将要排序的数据分割成独立的两部分&#xff1b;其中一部分的所有数据都比另外一部分的所有数据都要小。然后&#xff0c;再按此方法对这两部分数据分别进…...

指针+一维整型数组的基本运用 和 指针+一维整型数组的初步学习

一&#xff0c;调式程序的技巧&#xff1a; 1.明确问题 2.定位问题 3.加打印&#xff08;打印核心数据0&#xff09; 二&#xff0c;指针的回顾 1.指针的概念&#xff1a;指针就是地址&#xff08;内存单元的编号&#xff09;&#xff0c;是一个数据类型&#xff08;指针类型…...

APP测试基本流程以及APP测试要点总结

&#x1f345; 视频学习&#xff1a;文末有免费的配套视频可观看 &#x1f345; 点击文末小卡片&#xff0c;免费获取软件测试全套资料&#xff0c;资料在手&#xff0c;涨薪更快 APP测试实际上依然属于软件测试的范畴&#xff0c;是软件测试的一个真子集&#xff0c;所以经典软…...

GPT-4 Vision调试任何应用,即使缺少文本日志 升级Streamlit七

GPT-4 Vision 系列: 翻译: GPT-4 with Vision 升级 Streamlit 应用程序的 7 种方式一翻译: GPT-4 with Vision 升级 Streamlit 应用程序的 7 种方式二翻译: GPT-4 Vision静态图表转换为动态数据可视化 升级Streamlit 三翻译: GPT-4 Vision从图像转换为完全可编辑的表格 升级St…...

ppt形状导入draw.io

draw.io里面的形状还是有点少&#xff0c;我有时想找一个形状&#xff0c;发现PPT里有&#xff0c;但draw.io里有&#xff0c;比如 也就是这个形状 最简单的想法就是我直接把这个形状在PPT里存成图片&#xff08;png)&#xff0c;然后再导入到draw.io里&#xff0c;但是结果是…...

GoLang和GoLand的安装和配置

1. GoLang 1.1 特点介绍 Go 语言保证了既能达到静态编译语言的安全和性能&#xff0c;又达到了动态语言开发维护的高效率&#xff0c;使用一个表达式来形容 Go 语言&#xff1a;Go C Python , 说明 Go 语言既有 C 静态语言程序的运行速度&#xff0c;又能达到 Python 动态语…...

BGAD文章复现笔记-1

文章名&#xff1a;《Explicit Boundary Guided Semi-Push-Pull Contrastive Learning for Supervised Anomaly Detection》 原作者代码&#xff1a;https://github.com/xcyao00/BGAD 复现过程&#xff1a; 系统Ubuntu22.04, PyTorch1.12.1&#xff0c;python3.9 下载原作者…...

【EI会议推荐】第六届下一代数据驱动网络国际学术会议(NGDN 2024)

第六届下一代数据驱动网络国际学术会议&#xff08;NGDN 2024&#xff09; The Sixth International Conference on Next Generation Data-driven Networks 2024年4月26-28日 | 中国沈阳 *NGDN 2024已进入中国学术会议在线推荐列表&#xff1a;Click 基于前几届在英国埃克塞…...

聊聊java中的Eureka和Nacos

本文主要来自于黑马课程中 1.提供者与消费者 在服务调用关系中&#xff0c;会有两个不同的角色&#xff1a; 服务提供者&#xff1a;一次业务中&#xff0c;被其它微服务调用的服务。&#xff08;提供接口给其它微服务&#xff09; 服务消费者&#xff1a;一次业务中&#xff0…...

系统架构设计师-21年-上午试题

系统架构设计师-21年-上午试题 更多软考资料 https://ruankao.blog.csdn.net/ 1 ~ 10 1 前趋图(Precedence Graph)是一个有向无环图&#xff0c;记为:→{(Pi,Pj)|Pi must complete before Pj may strat}&#xff0c;假设系统中进程P{P1&#xff0c;P2&#xff0c;P3&#xf…...

数据库MySQL查询设计||给定四个关联表,其定义和数据加载如下:-- 学生表 Student-- 选课表 SC

SQL查询设计 给定四个关联表&#xff0c;其定义和数据加载如下&#xff1a; -- 学生表 Student create table Student(Sno varchar(6), Sname varchar(10), Sdate datetime, Ssex varchar(10)); insert into Student values(01 , 赵雷 , 1999-01-01 , 男); insert into St…...

C#使用RabbitMQ-3_发布订阅模式(扇形交换机)

简介 发布订阅模式允许一个生产者向多个消费者发送消息。在RabbitMQ中实现发布订阅模式通常涉及以下几个关键组件&#xff1a; 生产者&#xff1a;负责生产并发送消息到RabbitMQ的Exchange&#xff08;路由器&#xff09;。Exchange&#xff1a;作为消息的中转站&#xff0c;…...

区块链游戏解说:什么是 SecondLive

数据源&#xff1a;SecondLive Dashboard 作者&#xff1a;lesleyfootprint.network 什么是 SecondLive SecondLive 是元宇宙居民的中心枢纽&#xff0c;拥有超过100 万用户的蓬勃社区。它的主要使命是促进自我表达&#xff0c;释放创造力&#xff0c;构建梦想中的平行宇宙…...

构建基于Flask的跑腿外卖小程序

跑腿外卖小程序作为现代生活中的重要组成部分&#xff0c;其技术实现涉及诸多方面&#xff0c;其中Web开发框架是至关重要的一环。在这篇文章中&#xff0c;我们将使用Python的Flask框架构建一个简单的跑腿外卖小程序的原型&#xff0c;展示其基本功能和实现原理。 首先&…...

【算法】Partitioning the Array(数论)

题目 Allen has an array a1,a2,…,an. For every positive integer k that is a divisor of n, Allen does the following: He partitions the array into n/k disjoint subarrays of length k. In other words, he partitions the array into the following subarrays: [a1,…...

openclaw里面如何添加channel

在 OpenClaw 中添加 Channel&#xff08;消息通道 / 渠道&#xff09;&#xff0c;核心是通过 CLI 命令 或直接编辑 配置文件&#xff0c;将 Telegram、Discord、飞书、WhatsApp 等 IM 平台接入网关&#xff08;Gateway&#xff09;&#xff0c;并绑定到 Agent。以下是完整、可…...

别再只盯着mAP50了!手把手教你修改YOLOv8的best模型保存逻辑(附代码)

突破mAP50局限&#xff1a;YOLOv8模型保存策略深度定制指南 在目标检测领域&#xff0c;mAP50&#xff08;mean Average Precision at IoU0.5&#xff09;长期被作为模型性能的黄金标准。但当我们面对工业质检中微米级缺陷识别&#xff0c;或是自动驾驶场景中对行人检测的严苛要…...

LOSEHU固件:解锁泉盛UV-K5/K6对讲机专业潜能的终极解决方案

LOSEHU固件&#xff1a;解锁泉盛UV-K5/K6对讲机专业潜能的终极解决方案 【免费下载链接】uv-k5-firmware-custom 全功能泉盛UV-K5/K6固件 Quansheng UV-K5/K6 Firmware 项目地址: https://gitcode.com/gh_mirrors/uvk5f/uv-k5-firmware-custom 还在为对讲机原厂固件的功…...

为什么头部AI团队已弃用Triton+ONNX Runtime?Cuvil架构设计图暴露Python推理第三条路!

第一章&#xff1a;Cuvil编译器在Python AI推理中的应用全景概览Cuvil编译器是一款面向AI工作负载的轻量级领域专用编译器&#xff0c;专为优化Python生态中基于PyTorch、ONNX及自定义计算图的推理流程而设计。它不替代传统Python解释器&#xff0c;而是通过源码到IR&#xff0…...

终极Google Drive下载解决方案:专业级gdrivedl实战指南

终极Google Drive下载解决方案&#xff1a;专业级gdrivedl实战指南 【免费下载链接】gdrivedl Google Drive Download Python Script 项目地址: https://gitcode.com/gh_mirrors/gd/gdrivedl Google Drive文件下载是许多开发者和技术爱好者面临的常见挑战&#xff0c;特…...

告别混乱!用Power BI工作区高效管理跨部门报表:数据集/仪表板/报告编排技巧

告别混乱&#xff01;用Power BI工作区高效管理跨部门报表&#xff1a;数据集/仪表板/报告编排技巧 在数据驱动的商业环境中&#xff0c;跨部门协作常陷入"数据孤岛"困境——财务部的销售分析需要市场部的活动数据&#xff0c;运营部的库存报表又依赖采购部的供应商信…...

STM32H743+CubeMX配置FDCAN实战:如何利用TxFIFO优化FreeRTOS下的CAN通信性能?

STM32H743CubeMX配置FDCAN实战&#xff1a;如何利用TxFIFO优化FreeRTOS下的CAN通信性能&#xff1f; 在嵌入式系统开发中&#xff0c;CAN总线因其高可靠性和实时性被广泛应用于工业控制、汽车电子等领域。当我们将目光投向STM32H743这类高性能微控制器时&#xff0c;其内置的FD…...

解决SlowFast环境配置中的‘No module named torch._six’等疑难杂症:从修改压缩包到调整import路径

SlowFast环境配置深度排障指南&#xff1a;从源码修改到路径调整的完整解决方案 在视频理解领域&#xff0c;SlowFast作为Facebook Research开源的优秀框架&#xff0c;凭借其双路径网络设计在动作识别任务中表现出色。然而&#xff0c;许多开发者在环境配置阶段就会遭遇各种&q…...

效果对比:Qwen3.5-4B-Claude-4.6-Opus-Reasoning-Distilled-GGUF在多轮对话与复杂指令跟随上的表现

效果对比&#xff1a;Qwen3.5-4B-Claude-4.6-Opus-Reasoning-Distilled-GGUF在多轮对话与复杂指令跟随上的表现 1. 模型能力概览 Qwen3.5-4B-Claude-4.6-Opus-Reasoning-Distilled-GGUF&#xff08;以下简称"推理蒸馏模型"&#xff09;是一款专注于复杂推理和多轮对…...

探索XPopup:一款强大的Android弹窗库,让UI交互更灵动

探索XPopup&#xff1a;一款强大的Android弹窗库&#xff0c;让UI交互更灵动 【免费下载链接】XPopup &#x1f525;XPopup2.0版本重磅来袭&#xff0c;2倍以上性能提升&#xff0c;带来可观的动画性能优化和交互细节的提升&#xff01;&#xff01;&#xff01;功能强大&#…...