java房屋信息系统
时间: 2023-11-21 09:56:34 浏览: 66
房屋信息系统
以下是一个简单的Java房屋信息系统的示例,其中包括管理员角色的功能:
```java
import java.util.ArrayList;
import java.util.Scanner;
public class HousingSystem {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
ArrayList<House> houses = new ArrayList<>();
ArrayList<Tenant> tenants = new ArrayList<>();
ArrayList<Contract> contracts = new ArrayList<>();
ArrayList<Payment> payments = new ArrayList<>();
ArrayList<Schedule> schedules = new ArrayList<>();
ArrayList<Refund> refunds = new ArrayList<>();
ArrayList<Viewing> viewings = new ArrayList<>();
while (true) {
System.out.println("请选择您的身份:1.管理员 2.租户 3.退出");
int identity = scanner.nextInt();
if (identity == 1) {
System.out.println("请输入管理员用户名和密码:");
String username = scanner.next();
String password = scanner.next();
if (username.equals("admin") && password.equals("admin")) {
System.out.println("欢迎,管理员!");
while (true) {
System.out.println("请选择您要进行的操作:1.房源信息查询 2.房源信息增删改查 3.在租列表 4.查看租房合同 5.修改租房合同 6.退租列表 7.退租申请 8.审批看房申请 9.填写合同 10.查看退租申请 11.收租管理 12.查看代缴 13.查看已经缴纳的租金 14.日程 15.退出");
int operation = scanner.nextInt();
if (operation == 1) {
System.out.println("房源信息如下:");
for (House house : houses) {
System.out.println(house);
}
} else if (operation == 2) {
System.out.println("请选择您要进行的操作:1.增加房源 2.删除房源 3.修改房源信息 4.查询房源信息");
int subOperation = scanner.nextInt();
if (subOperation == 1) {
System.out.println("请输入房源信息:"); String address = scanner.next();
int area = scanner.nextInt();
int price = scanner.nextInt();
House house = new House(address, area, price);
houses.add(house);
System.out.println("房源信息添加成功!");
} else if (subOperation == 2) {
System.out.println("请输入要删除的房源地址:");
String address = scanner.next();
for (House house : houses) {
if (house.getAddress().equals(address)) {
houses.remove(house);
System.out.println("房源信息删除成功!");
break;
}
}
} else if (subOperation == 3) {
System.out.println("请输入要修改的房源地址:");
String address = scanner.next();
for (House house : houses) {
if (house.getAddress().equals(address)) {
System.out.println("请输入新的房源信息:");
String newAddress = scanner.next();
int newArea = scanner.nextInt();
int newPrice = scanner.nextInt();
house.setAddress(newAddress);
house.setArea(newArea);
house.setPrice(newPrice);
System.out.println("房源信息修改成功!");
break;
}
}
} else if (subOperation == 4) {
System.out.println("请输入要查询的房源地址:");
String address = scanner.next();
for (House house : houses) {
if (house.getAddress().equals(address)) {
System.out.println(house);
break;
}
}
}
} else if (operation == 3) {
System.out.println("在租列表如下:");
for (Contract contract : contracts) {
if (contract.getStatus().equals("在租")) {
System.out.println(contract);
}
}
} else if (operation == 4) {
System.out.println("请输入租户姓名:");
String name = scanner.next();
for (Contract contract : contracts) {
if (contract.getTenant().getName().equals(name)) {
System.out.println(contract);
break;
}
}
} else if (operation == 5) {
System.out.println("请输入租户姓名:");
String name = scanner.next();
for (Contract contract : contracts) {
if (contract.getTenant().getName().equals(name)) {
System.out.println("请输入新的租房合同信息:");
String address = scanner.next();
int area = scanner.nextInt();
int price = scanner.nextInt();
contract.setHouse(new House(address, area, price));
System.out.println("租房合同修改成功!");
break;
}
}
} else if (operation == 6) {
System.out.println("退租列表如下:");
for (Refund refund : refunds) {
System.out.println(refund);
}
} else if (operation == 7) {
System.out.println("请输入租户姓名:");
String name = scanner.next();
for (Contract contract : contracts) {
if (contract.getTenant().getName().equals(name)) {
System.out.println("请输入退租原因:");
String reason = scanner.next();
Refund refund = new Refund(contract, reason);
refunds.add(refund);
contract.setStatus("退租申请中");
System.out.println("退租申请提交成功!");
break;
}
}
} else if (operation == 8) {
System.out.println("请输入租户姓名:");
String name = scanner.next();
for (Viewing viewing : viewings) {
if (viewing.getTenant().getName().equals(name)) {
System.out.println(viewing);
break;
}
}
} else if (operation == 9) {
System.out.println("请输入租户姓名:");
String name = scanner.next();
for (Contract contract : contracts) {
if (contract.getTenant().getName().equals(name)) {
System.out.println("请输入合同信息:");
String address = scanner.next();
int area = scanner.nextInt();
int price = scanner.nextInt();
contract.setHouse(new House(address, area, price));
contract.setStatus("已签订");
System.out.println("合同填写成功!");
break;
}
}
} else if (operation == 10) {
System.out.println("请输入租户姓名:");
String name = scanner.next();
for (Refund refund : refunds) {
if (refund.getContract().getTenant().getName().equals(name)) {
System.out.println(refund);
break;
}
}
} else if (operation == 11) {
System.out.println("收租管理如下:");
for (Payment payment : payments) {
System.out.println(payment);
}
} else if (operation == 12) {
System.out.println("请输入租户姓名:");
String name = scanner.next();
for (Payment payment : payments) {
if (payment.getTenant().getName().equals(name)) {
System.out.println(payment);
break;
}
}
} else if (operation == 13) {
System.out.println("请输入租户姓名:");
String name = scanner.next();
for (Payment payment : payments) {
if (payment.getTenant().getName().equals(name)) {
System.out.println("已经缴纳的租金为:" + payment.getAmount());
break;
}
}
} else if (operation == 14) {
System.out.println("日程如下:");
for (Schedule schedule : schedules) {
System.out.println(schedule);
}
} else if (operation == 15) {
break;
}
}
} else {
System.out.println("用户名或密码错误!");
}
} else if (identity == 2) {
System.out.println("请输入租户姓名:");
String name = scanner.next();
Tenant tenant = null;
for (Tenant t : tenants) {
if (t.getName().equals(name)) {
tenant = t;
break;
}
}
if (tenant == null) {
tenant = new Tenant(name);
tenants.add(tenant);
}
while (true) {
System.out.println("请选择您要进行的操作:1.查看房源信息 2.查看租房合同 3.修改租房合同 4.申请退租 5.查看退租申请 6.查看已经缴纳的租金 7.退出");
int operation = scanner.nextInt();
if (operation == 1) {
System.out.println("房源信息如下:");
for (House house : houses) {
System.out.println(house);
}
} else if (operation == 2) {
for (Contract contract : contracts) {
if (contract.getTenant().equals(tenant)) {
System.out.println(contract);
break;
}
}
} else if (operation == 3) {
for (Contract contract : contracts) {
if (contract.getTenant().equals(tenant)) {
System.out.println("请输入新的租房合同信息:");
String address = scanner.next();
int area = scanner.nextInt();
int price = scanner.nextInt();
contract.setHouse(new House(address, area, price));
System.out.println("租房合同修改成功!");
break;
}
}
} else if (operation == 4) {
System.out.println("请输入退租原因:");
String reason = scanner.next();
Contract contract = null;
for (Contract c : contracts) {
if (c.getTenant().equals(tenant) && c.getStatus().equals("在租")) {
contract = c;
break;
}
}
if (contract != null) {
Refund refund = new Refund(contract, reason);
refunds.add(refund);
contract.setStatus("退租申请中");
System.out.println("退租申请提交成功!");
} else {
System.out.println("您当前没有在租的房源!");
}
} else if (operation == 5) {
for (Refund refund : refunds) {
if (refund.getContract().getTenant().equals(tenant)) {
System.out.println(refund);
break;
}
}
} else if (operation == 6) {
for (Payment payment : payments) {
if (payment.getTenant().equals(tenant)) {
System.out.println("已经缴纳的租金为:" + payment.getAmount());
break;
}
}
} else if (operation == 7) {
break;
}
}
} else if (identity == 3) {
break;
}
}
}
}
class House {
private String address;
private int area;
private int price;
public House(String address, int area, int price) {
阅读全文