package com.basic.study.realization.modifyhome.view;
import com.basic.study.realization.modifyhome.domain.House;
import com.basic.study.realization.modifyhome.service.HouseService;
import com.basic.study.realization.modifyhome.utils.Utility;
/**
* 1.显示界面
* 2.接受用户输入
* 调用HouseService的功能
*/
public class HouseView {
private boolean loop = true;
private char key = ' ';
private HouseService houseService = new HouseService(100);
public void addHouse() {
System.out.println("===============添加房屋===============");
System.out.print("姓名: (长度 < 10) ");
String name = Utility.readString(10);
System.out.print("电话: ");
String phone = Utility.readString(11);
System.out.print("地址: ");
String address = Utility.readString(20);
System.out.print("租金: ");
double rent = Utility.readInt();
System.out.print("状态(未出租/已出租): ");
String state = Utility.readString(3);
House house = new House(0, rent, name, phone, address, state);
boolean result = houseService.add(house);
if (result) {
System.out.println("===============添加完成===============");
} else {
System.out.println("===============添加失败===============");
}
}
public void listHouse() {
System.out.println("===============房屋列表===============");
System.out.println("编号\t" + "房主\t" + "电话\t" + "地址\t" + "月租\t" + "状态(未出租/已出租)");
House[] houses = houseService.list();
for (int i = 0; i < houses.length; i++) {
if (houses[i] == null) {
break;
}
System.out.println(houses[i]);
}
}
public void findHouse() {
System.out.println("===============查找房屋===============");
System.out.print("请输入你要查找的id: ");
int findId = Utility.readInt();
House result = houseService.find(findId);
if (result != null) {
System.out.println(result);
System.out.println("===============查找成功===============");
} else {
System.out.println("===============没有相应的房屋信息===============");
}
}
public void deleteHouse() {
System.out.println("===============删除房屋===============");
System.out.print("请选择删除房屋编号(-1退出): ");
int findId = Utility.readInt();
if (findId == -1) {
System.out.println("===============放弃删除房屋===============");
return;
}
System.out.println("请确认是否删除房屋(Y/N):");
char choose = Utility.readConfirmSelection();
if (choose == 'Y') {
if (houseService.del(findId)) {
System.out.println("===============删除房屋成功===============");
} else {
System.out.println("===============房屋信息不存在===============");
}
} else {
System.out.println("===============放弃删除房屋===============");
}
}
public void modifyHouse() {
System.out.println("===============修改房屋===============");
System.out.print("请输入修改房屋编号(-1退出): ");
int findId = Utility.readInt();
if (findId == -1) {
System.out.println("===============放弃删除房屋===============");
return;
}
House result = houseService.modify(findId);
if (result != null) {
System.out.println("姓名(" + result.getName() + "):");
result.setName(Utility.readString(10));
System.out.println("电话(" + result.getPhone() + "):");
result.setPhone(Utility.readString(11));
System.out.println("地址(" + result.getAddress() + "):");
result.setAddress(Utility.readString(20));
System.out.println("租金(" + result.getRent() + "):");
result.setRent(Utility.readInt());
System.out.println("状态(" + result.getState() + "):");
result.setState(Utility.readString(3));
System.out.println("===============删除房屋成功===============");
} else {
System.out.println("===============房屋信息不存在===============");
}
}
public void exit() {
char choose = Utility.readConfirmSelection();
if (choose == 'Y') {
System.out.println("退出程序!");
loop = false;
}
}
public void mainMenu() {
do {
System.out.println("===============房屋出租系统===============");
System.out.println("\t1 新 增 房 源\n\t2 查 找 房 屋\n\t3 删 除 房 屋\n\t4 修 改 房 屋 信 息" +
"\n\t5 房 屋 列 表\n\t6 退 出");
System.out.println("请输入你的选择:");
key = Utility.readMenuSelection();
switch (key) {
case '1':
addHouse();
break;
case '2':
findHouse();
break;
case '3':
deleteHouse();
break;
case '4':
modifyHouse();
break;
case '5':
listHouse();
break;
case '6':
exit();
break;
}
} while (loop);
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
这个房屋出租管理系统主要包含三个类:House类、HouseService类和HouseView类和Utility类。该项目采用了面向对象的设计思想,将房屋信息的表示、业务逻辑和用户界面分别封装在不同的类中,提高了代码的可维护性和扩展性。House类用于表示房屋信息,包含了房屋的编号、月租、房主姓名、电话、地址以及状态等属性,并提供了对这些属性的访问和设置方法。HouseService类是系统的业务逻辑层,其中定义了对房屋信息进行操作的方法,包括添加房屋、查找房屋、删除房屋和修改房屋信息等功能。HouseView类是系统的用户界面层,负责与用户进行交互,接受用户的输入,并调用HouseService类中的方法来实现相应的功能。添加房屋信息:用户可以输入房主姓名、电话、地址、月租和状态等信息,系统会自动分配一个唯一的房屋编号。 查找房屋信息:用户可以通过输入房屋编号来查找对应的房屋信息。 删除房屋信息:用户可以选择删除指定编号的房屋信息,系统会进行确认操作以避免误删。 相应的代码已进行注释,相应的工具代码也已经上传。本次代码仅供学习,如有其他意见或者需求,可自行修改,不再做其他改动
资源推荐
资源详情
资源评论
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
收起资源包目录
![package](https://csdnimg.cn/release/downloadcmsfe/public/img/package.f3fc750b.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
共 5 条
- 1
资源评论
![avatar-default](https://csdnimg.cn/release/downloadcmsfe/public/img/lazyLogo2.1882d7f4.png)
![avatar](https://profile-avatar.csdnimg.cn/default.jpg!1)
想做大学士
- 粉丝: 42
- 资源: 4
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助
![voice](https://csdnimg.cn/release/downloadcmsfe/public/img/voice.245cc511.png)
![center-task](https://csdnimg.cn/release/downloadcmsfe/public/img/center-task.c2eda91a.png)
安全验证
文档复制为VIP权益,开通VIP直接复制
![dialog-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/green-success.6a4acb44.png)