Real Estate Managing Website

                                    

                                    REAL ESTATE MANAGING WEBSITE USING RMI


1.Remote interface – RealEstateService

import java.rmi.Remote;

import java.rmi.RemoteException;

import java.util.List;


public interface RealEstateService extends Remote {

    String addProperty(String address, double price, String owner) throws RemoteException;

    Property getProperty(int id) throws RemoteException;

    List<Property> listProperties() throws RemoteException;

}


2.Implementation – RealEstateServiceImpl

import java.rmi.server.UnicastRemoteObject;

import java.rmi.RemoteException;

import java.util.ArrayList;

import java.util.List;


public class RealEstateServiceImpl extends UnicastRemoteObject implements RealEstateService {

    private static final long serialVersionUID = 1L;

    private List<Property> properties;

    private int currentId = 1;


    protected RealEstateServiceImpl() throws RemoteException {

        super();

        properties = new ArrayList<>();

    }


    public synchronized String addProperty(String address, double price, String owner) throws RemoteException {

        Property p = new Property(currentId++, address, price, owner);

        properties.add(p);

        return "Property added with ID: " + p.getId();

    }


    public Property getProperty(int id) throws RemoteException {

        for (Property p : properties) {

            if (p.getId() == id) return p;

        }

        return null;

    }


    public List<Property> listProperties() throws RemoteException {

        return properties;

    }

}


3.RMI Server – RealEstateServer

import java.rmi.Naming;

import java.rmi.registry.LocateRegistry;


public class RealEstateServer {

    public static void main(String[] args) {

        try {

            LocateRegistry.createRegistry(1099);

            RealEstateService service = new RealEstateServiceImpl();

            Naming.rebind("RealEstateService", service);

            System.out.println("Real Estate Service is running...");

        } catch (Exception e) {

            System.out.println("Server Error: " + e.getMessage());

        }

    }

}


4.Client interaction – RealEstateClient

import java.rmi.Naming;

import java.util.List;


public class RealEstateClient {

    public static void main(String[] args) {

        try {

            RealEstateService service = (RealEstateService) Naming.lookup("rmi://localhost/RealEstateService");


            System.out.println(service.addProperty("123 Palm St, LA", 500000, "Alice"));

            System.out.println(service.addProperty("456 Oak Ave, NY", 800000, "Bob"));


            Property p = service.getProperty(1);

            System.out.println("Fetched Property ID 1: " + p);


            List<Property> all = service.listProperties();

            System.out.println("All Properties:");

            for (Property prop : all) {

                System.out.println(prop);

            }


        } catch (Exception e) {

            System.out.println("Client Error: " + e.getMessage());

        }

    }

}


5.Data model – Property

import java.io.Serializable;


public class Property implements Serializable {

    private static final long serialVersionUID = 1L;


    private int id;

    private String address;

    private double price;

    private String owner;


    public Property(int id, String address, double price, String owner) {

        this.id = id;

        this.address = address;

        this.price = price;

        this.owner = owner;

    }


    public int getId() {

        return id;

    }


    public String getAddress() {

        return address;

    }


    public double getPrice() {

        return price;

    }


    public String getOwner() {

        return owner;

    }


    @Override

    public String toString() {

        return "ID: " + id + ", Address: " + address + ", Price: $" + price + ", Owner: " + owner;

    }

}


6.Expected Output

Server
















Client



Comments

Popular posts from this blog

Matrix Division

Password Manager