温馨提示:这篇文章已超过289天没有更新,请注意相关的内容是否还可用!
Java房屋租售系统是一个用于管理房屋租赁和销售信息的系统。它可以帮助用户发布房屋信息、搜索房屋、预订房屋、完成租赁和销售交易等功能。下面是一个简单的Java房屋租售系统的代码示例:
public class House {
private String address;
private double price;
private boolean isForRent;
public House(String address, double price, boolean isForRent) {
this.address = address;
this.price = price;
this.isForRent = isForRent;
}
public String getAddress() {
return address;
}
public double getPrice() {
return price;
}
public boolean isForRent() {
return isForRent;
}
}
public class HouseManagementSystem {
private List<House> houses;
public HouseManagementSystem() {
houses = new ArrayList<>();
}
public void addHouse(House house) {
houses.add(house);
}
public List<House> searchHouses(boolean isForRent) {
List<House> result = new ArrayList<>();
for (House house : houses) {
if (house.isForRent() == isForRent) {
result.add(house);
}
}
return result;
}
}
public class Main {
public static void main(String[] args) {
HouseManagementSystem houseManagementSystem = new HouseManagementSystem();
House house1 = new House("123 Main St", 200000, false);
House house2 = new House("456 Elm St", 1500, true);
House house3 = new House("789 Oak St", 300000, false);
houseManagementSystem.addHouse(house1);
houseManagementSystem.addHouse(house2);
houseManagementSystem.addHouse(house3);
List<House> housesForRent = houseManagementSystem.searchHouses(true);
System.out.println("Houses for rent:");
for (House house : housesForRent) {
System.out.println(house.getAddress() + " - $" + house.getPrice());
}
List<House> housesForSale = houseManagementSystem.searchHouses(false);
System.out.println("Houses for sale:");
for (House house : housesForSale) {
System.out.println(house.getAddress() + " - $" + house.getPrice());
}
}
}
以上示例代码展示了一个简单的房屋租售系统。House类表示房屋对象,包含地址、价格和是否出租的属性。HouseManagementSystem类用于管理房屋信息,包括添加房屋和搜索房屋的功能。Main类是程序的入口,演示了如何使用HouseManagementSystem类来添加房屋、搜索出租房屋和出售房屋,并打印结果。