package houserent.view;
import houserent.domain.House;
import houserent.service.HouseService;
import houserent.utils.Utility;
/*
*1.显示界面
*2.接收用户的输入
*3.调用HouseService完成对房屋信息的各种操作
* */
public class Houseview {
//1.显示主菜单
private boolean loop = true;
private char key = ' ';
private HouseService houseService = new HouseService(10);
public void updateHouse(){
System.out.println("=================修改房屋===================");
System.out.println("=================请选择修改的房屋编号(-1退出)===================");
int UpdateId = Utility.readInt();
if (UpdateId == -1){
return;
}
House house = houseService.findById(UpdateId);
if (house == null){
System.out.println("=================你要修改的房屋信息不存在无法修改===================");
return;
}
//值得注意的是,引用类型是存在堆里的,谁指向他都能直接修改。
//返回的是引用类型也就是数组中的元素 ,因此在后对house.setXX(),就会对HouseService中的houses数组进行修改
System.out.println("姓名("+ house.getName() +")");
//读取修改的信息,有可能直接回车,如果是空的,那么就是不修改,如果不是空的那么就修改
String name = Utility.readString(8,"");//这里如果用户直接回车的话,表示不修改信息
if(!"".equals(name)){
house.setName(name);
}
System.out.println("电话(" + house.getPhone() + ")");
String phone = Utility.readString(12,"");
if(!"".equals(phone)){
house.setPhone(phone);
}
System.out.println("地址(" + house.getAddress() + ")");
String address = Utility.readString(18,"");
if(!"".equals(address)){
house.setAddress(address);
}
System.out.println("租金(" + house.getRent() + ")");
int rent = Utility.readInt(-1);
if(rent != -1){
house.setRent(rent);
}
System.out.println("状态(" + house.getState() + ")");
String state = Utility.readString(18,"");
if(!"".equals(address)){
house.setState(state);
}
System.out.println("=================修改房屋信息成功===================");
}
public void findHouse(){
System.out.println("=================查找房屋===================");
System.out.println("=================请输入你要查找的id===================");
int findId = Utility.readInt();
//调用方法
House house = houseService.findById(findId);
if(house != null){
System.out.println(house);
System.out.println("=================查找成功===================");
}
else{
System.out.println("=================查找的id不存在===================");
}
}
public void exit(){
char c = Utility.readConfirmSelection();
if(c == 'Y'){
loop = false;
}
}
public void delHouse(){
System.out.println("=================删除房屋===================");
System.out.println("============请选择房屋编号(-1退出)==============");
int detId = Utility.readInt();
if(detId == -1){
System.out.println("===========放弃删除房屋===================");
return;
}
//注意该方法本身就有循环判断的逻辑,只能输出Y或者N
char choice = Utility.readConfirmSelection();
if(choice == 'Y'){//真的删除了
if(houseService.delHouse(detId)){
System.out.println("===========删除房屋成功===================");
}
else{
System.out.println("===========删除房屋失败,编号不存在===================");
}
}
}
public void addHouses(){
System.out.println("=================添加房屋===================");
System.out.println("姓名:");
String name = Utility.readString(8);
System.out.println("电话:");
String phone = Utility.readString(12);
System.out.println("地址:");
String address = Utility.readString(18);
System.out.println("月租:");
int rent = Utility.readInt();
System.out.println("状态:");
String state = Utility.readString(3);
//创建一个新的House对象,注意id是系统分配的
House newHouse = new House(0, name, phone, address, rent, state);
if(houseService.addHouse(newHouse)){
System.out.println("==============添加房屋成功==========");
}
else{
System.out.println("=============添加房屋失败===============");
}
}
public void listHouses(){
System.out.println("==================房屋列表===================");
System.out.println("编号\t\t房主\t\t电话\t\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]);
}
System.out.println("==================房屋列表显示完毕===================");
System.out.println();
}
public void mainMenu() {
do{
System.out.println("=============房屋出租菜单================");
System.out.println("\t\t\t1.新增房源");
System.out.println("\t\t\t2.查找房屋");
System.out.println("\t\t\t3.删除房源");
System.out.println("\t\t\t4.修改房屋信息");
System.out.println("\t\t\t5.房屋列表");
System.out.println("\t\t\t6.退出");
System.out.println("请输入你的选择");
key = Utility.readChar();
switch (key){
case '1':
addHouses();
break;
case '2':
findHouse();
break;
case '3':
delHouse();
break;
case '4':
updateHouse();
break;
case '5':
listHouses();
break;
case '6':
System.out.println("退出");
exit();
break;
}
}
while(loop);
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.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)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.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)
![jar](https://img-home.csdnimg.cn/images/20210720083455.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.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)
![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)
![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/f65e263023ea4f4a8aa63e3efb127be9_showy0.jpg!1)
A_SHOWY
- 粉丝: 1567
- 资源: 5
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的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)
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
![feedback](https://img-home.csdnimg.cn/images/20220527035711.png)
![feedback](https://img-home.csdnimg.cn/images/20220527035711.png)
![feedback-tip](https://img-home.csdnimg.cn/images/20220527035111.png)
安全验证
文档复制为VIP权益,开通VIP直接复制
![dialog-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/green-success.6a4acb44.png)