用java写一个物业管理
时间: 2024-05-11 10:18:56 浏览: 8
好的,以下是一个简单的物业管理系统的Java代码示例:
```
import java.util.ArrayList;
import java.util.Scanner;
public class PropertyManagementSystem {
private ArrayList<Property> properties;
public PropertyManagementSystem() {
properties = new ArrayList<Property>();
}
public void addProperty(Property property) {
properties.add(property);
}
public void removeProperty(Property property) {
properties.remove(property);
}
public void displayProperties() {
for (Property property : properties) {
System.out.println(property);
}
}
public static void main(String[] args) {
PropertyManagementSystem pms = new PropertyManagementSystem();
Scanner scanner = new Scanner(System.in);
while (true) {
System.out.println("1. Add property");
System.out.println("2. Remove property");
System.out.println("3. Display properties");
System.out.println("4. Exit");
int choice = scanner.nextInt();
switch (choice) {
case 1:
System.out.println("Enter property name:");
String name = scanner.next();
System.out.println("Enter property address:");
String address = scanner.next();
System.out.println("Enter property type:");
String type = scanner.next();
System.out.println("Enter property price:");
double price = scanner.nextDouble();
Property property = new Property(name, address, type, price);
pms.addProperty(property);
break;
case 2:
System.out.println("Enter property name to remove:");
String propertyName = scanner.next();
for (Property p : pms.properties) {
if (p.getName().equals(propertyName)) {
pms.removeProperty(p);
break;
}
}
break;
case 3:
pms.displayProperties();
break;
case 4:
System.exit(0);
}
}
}
}
class Property {
private String name;
private String address;
private String type;
private double price;
public Property(String name, String address, String type, double price) {
this.name = name;
this.address = address;
this.type = type;
this.price = price;
}
public String getName() {
return name;
}
public String getAddress() {
return address;
}
public String getType() {
return type;
}
public double getPrice() {
return price;
}
public String toString() {
return "Name: " + name + ", Address: " + address + ", Type: " + type + ", Price: " + price;
}
}
```
该示例实现了一个基本的物业管理系统,可以添加和删除物业,并显示已添加的物业。你可以根据你的需求进行修改和扩展。