0% found this document useful (0 votes)
4 views9 pages

Real Estate Management System Code

The document is a Java implementation of a Real Estate Management System using Swing for the GUI. It includes classes for managing properties, handling sales, and displaying property information in a table format. The system allows users to add, sell, update, and filter properties while providing statistics on total properties, available properties, sold properties, and total revenue.

Uploaded by

myworkmyangel
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views9 pages

Real Estate Management System Code

The document is a Java implementation of a Real Estate Management System using Swing for the GUI. It includes classes for managing properties, handling sales, and displaying property information in a table format. The system allows users to add, sell, update, and filter properties while providing statistics on total properties, available properties, sold properties, and total revenue.

Uploaded by

myworkmyangel
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

import [Link].

*;
import [Link];
import [Link].*;
import [Link];
import [Link];
import [Link];

// Property class
class Property {
private static int propertyCounter = 0;

private int propertyId;


private String address;
private double price;
private int bedrooms;
private int bathrooms;
private double squareFeet;
private String propertyType;
private boolean isAvailable;

public Property(String address, double price, int bedrooms, int bathrooms,


double squareFeet, String propertyType) {
[Link] = ++propertyCounter;
[Link] = address;
[Link] = price;
[Link] = bedrooms;
[Link] = bathrooms;
[Link] = squareFeet;
[Link] = propertyType;
[Link] = true;
}

public int getPropertyId() { return propertyId; }


public String getAddress() { return address; }
public double getPrice() { return price; }
public int getBedrooms() { return bedrooms; }
public int getBathrooms() { return bathrooms; }
public double getSquareFeet() { return squareFeet; }
public String getPropertyType() { return propertyType; }
public boolean isAvailable() { return isAvailable; }

public void setPrice(double price) { [Link] = price; }


public void setAvailable(boolean available) { [Link] = available; }
public static int getTotalPropertiesCreated() {
return propertyCounter;
}
}

// Real Estate Manager


class RealEstateManager {
private static List<Property> properties = new ArrayList<>();
private static double totalRevenue = 0.0;

public static void addProperty(Property property) {


[Link](property);
}

public static List<Property> getAllProperties() {


return new ArrayList<>(properties);
}

public static List<Property> getAvailableProperties() {


return [Link]()
.filter(Property::isAvailable)
.collect([Link]());
}

public static List<Property> searchByType(String type) {


return [Link]()
.filter(p -> [Link]().equalsIgnoreCase(type))
.collect([Link]());
}

public static void sellProperty(int propertyId) {


Property property = findPropertyById(propertyId);
if (property != null && [Link]()) {
[Link](false);
totalRevenue += [Link]();
}
}

public static Property findPropertyById(int id) {


return [Link]()
.filter(p -> [Link]() == id)
.findFirst()
.orElse(null);
}
public static void updatePrice(int propertyId, double newPrice) {
Property property = findPropertyById(propertyId);
if (property != null) {
[Link](newPrice);
}
}

public static long getAvailableCount() {


return [Link]().filter(Property::isAvailable).count();
}

public static long getSoldCount() {


return [Link]() - getAvailableCount();
}

public static double getAveragePrice() {


return [Link]()
.mapToDouble(Property::getPrice)
.average()
.orElse(0.0);
}

public static double getTotalRevenue() {


return totalRevenue;
}
}

// Main GUI Application


public class RealEstateManagementSystem extends JFrame {
private JTable propertyTable;
private DefaultTableModel tableModel;
private JLabel lblTotal, lblAvailable, lblSold, lblRevenue;

public RealEstateManagementSystem() {
setTitle("Real Estate Management System");
setSize(900, 600);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(new BorderLayout(10, 10));

// Top Panel - Title


JPanel topPanel = new JPanel();
[Link](new Color(70, 130, 180));
JLabel titleLabel = new JLabel("Real Estate Management System");
[Link](new Font("Arial", [Link], 24));
[Link]([Link]);
[Link](titleLabel);
add(topPanel, [Link]);

// Center Panel - Table


String[] columns = {"ID", "Address", "Type", "Bedrooms", "Bathrooms", "Sq Ft", "Price",
"Status"};
tableModel = new DefaultTableModel(columns, 0);
propertyTable = new JTable(tableModel);
[Link](25);
[Link](new Font("Arial", [Link], 12));
JScrollPane scrollPane = new JScrollPane(propertyTable);
add(scrollPane, [Link]);

// Bottom Panel - Statistics


JPanel statsPanel = new JPanel(new GridLayout(1, 4, 10, 10));
[Link]([Link](10, 10, 10, 10));

lblTotal = createStatLabel("Total: 0");


lblAvailable = createStatLabel("Available: 0");
lblSold = createStatLabel("Sold: 0");
lblRevenue = createStatLabel("Revenue: $0");

[Link](lblTotal);
[Link](lblAvailable);
[Link](lblSold);
[Link](lblRevenue);
add(statsPanel, [Link]);

// Right Panel - Buttons


JPanel buttonPanel = new JPanel();
[Link](new GridLayout(8, 1, 5, 10));
[Link]([Link](10, 10, 10, 10));

JButton btnAdd = new JButton("Add Property");


JButton btnSell = new JButton("Sell Property");
JButton btnUpdate = new JButton("Update Price");
JButton btnShowAll = new JButton("Show All");
JButton btnShowAvailable = new JButton("Show Available");
JButton btnFilterHouse = new JButton("Filter: Houses");
JButton btnFilterCondo = new JButton("Filter: Condos");
JButton btnRefresh = new JButton("Refresh");
[Link](e -> addProperty());
[Link](e -> sellProperty());
[Link](e -> updatePrice());
[Link](e -> showAllProperties());
[Link](e -> showAvailableProperties());
[Link](e -> filterByType("House"));
[Link](e -> filterByType("Condo"));
[Link](e -> refreshTable());

[Link](btnAdd);
[Link](btnSell);
[Link](btnUpdate);
[Link](btnShowAll);
[Link](btnShowAvailable);
[Link](btnFilterHouse);
[Link](btnFilterCondo);
[Link](btnRefresh);

add(buttonPanel, [Link]);

// Add sample data


addSampleData();
refreshTable();
}

private JLabel createStatLabel(String text) {


JLabel label = new JLabel(text, [Link]);
[Link](new Font("Arial", [Link], 14));
[Link]([Link]([Link]));
[Link](true);
[Link](new Color(240, 240, 240));
return label;
}

private void addSampleData() {


[Link](new Property("123 Main St", 350000, 3, 2, 1800,
"House"));
[Link](new Property("456 Oak Ave", 275000, 2, 2, 1200,
"Condo"));
[Link](new Property("789 Pine Rd", 450000, 4, 3, 2400,
"House"));
[Link](new Property("321 Elm St", 180000, 1, 1, 750,
"Apartment"));
[Link](new Property("654 Maple Dr", 520000, 5, 4, 3200,
"House"));
}

private void addProperty() {


JTextField addressField = new JTextField();
JTextField priceField = new JTextField();
JTextField bedroomsField = new JTextField();
JTextField bathroomsField = new JTextField();
JTextField sqFtField = new JTextField();
String[] types = {"House", "Condo", "Apartment"};
JComboBox<String> typeCombo = new JComboBox<>(types);

Object[] fields = {
"Address:", addressField,
"Price:", priceField,
"Bedrooms:", bedroomsField,
"Bathrooms:", bathroomsField,
"Square Feet:", sqFtField,
"Type:", typeCombo
};

int result = [Link](this, fields, "Add New Property",


JOptionPane.OK_CANCEL_OPTION);

if (result == JOptionPane.OK_OPTION) {
try {
String address = [Link]();
double price = [Link]([Link]());
int bedrooms = [Link]([Link]());
int bathrooms = [Link]([Link]());
double sqFt = [Link]([Link]());
String type = (String) [Link]();

[Link](new Property(address, price, bedrooms, bathrooms,


sqFt, type));
refreshTable();
[Link](this, "Property added successfully!");
} catch (NumberFormatException ex) {
[Link](this, "Invalid input! Please enter valid numbers.",
"Error", JOptionPane.ERROR_MESSAGE);
}
}
}
private void sellProperty() {
String input = [Link](this, "Enter Property ID to sell:");
if (input != null && ![Link]().isEmpty()) {
try {
int id = [Link](input);
Property property = [Link](id);
if (property == null) {
[Link](this, "Property not found!",
"Error", JOptionPane.ERROR_MESSAGE);
} else if (![Link]()) {
[Link](this, "Property already sold!",
"Error", JOptionPane.ERROR_MESSAGE);
} else {
[Link](id);
refreshTable();
[Link](this, "Property sold successfully!");
}
} catch (NumberFormatException ex) {
[Link](this, "Invalid ID!",
"Error", JOptionPane.ERROR_MESSAGE);
}
}
}

private void updatePrice() {


String idInput = [Link](this, "Enter Property ID:");
if (idInput != null && ![Link]().isEmpty()) {
try {
int id = [Link](idInput);
Property property = [Link](id);
if (property == null) {
[Link](this, "Property not found!",
"Error", JOptionPane.ERROR_MESSAGE);
} else {
String priceInput = [Link](this,
"Enter new price for " + [Link]() + ":");
if (priceInput != null && ![Link]().isEmpty()) {
double newPrice = [Link](priceInput);
[Link](id, newPrice);
refreshTable();
[Link](this, "Price updated successfully!");
}
}
} catch (NumberFormatException ex) {
[Link](this, "Invalid input!",
"Error", JOptionPane.ERROR_MESSAGE);
}
}
}

private void showAllProperties() {


displayProperties([Link]());
}

private void showAvailableProperties() {


displayProperties([Link]());
}

private void filterByType(String type) {


displayProperties([Link](type));
}

private void displayProperties(List<Property> properties) {


[Link](0);
for (Property p : properties) {
Object[] row = {
[Link](),
[Link](),
[Link](),
[Link](),
[Link](),
(int) [Link](),
[Link]("$%.0f", [Link]()),
[Link]() ? "Available" : "Sold"
};
[Link](row);
}
}

private void refreshTable() {


showAllProperties();
updateStatistics();
}

private void updateStatistics() {


[Link]("Total: " + [Link]());
[Link]("Available: " + [Link]());
[Link]("Sold: " + [Link]());
[Link]([Link]("Revenue: $%.0f",
[Link]()));
}

public static void main(String[] args) {


[Link](() -> {
RealEstateManagementSystem frame = new RealEstateManagementSystem();
[Link](true);
});
}
}

You might also like