Share on Google+Share on Google+

Real Estate Application

Here we have to find the number of units to be rented to maximize the profit

Real Estate Application

There is a real estate office that handles near about 50 apartment units. All the units are occupied when the rent is $600. If there is an increase in rent of about $ 40, one unit becomes vacant. Each occupied unit requires an average of $27 per month for maintenance.  Here we have to find the number of units to be rented to maximize the profit. For this, we have allowed the user to enter the following:
1) The number of apartment units
2) The rent to occupy all the units
3) The increase in rent that results in a vacant unit
4) Amount to maintain a rented unit

Here is the code:

import java.util.*;

public class RealEstate {
	public void findMaxProfit(int apartments, int rent, int increase,
			int maintenance) {
		int maxRent = 0;
		int maxProfit = 0;
		int maxApartments = 0;
		int notOccupied = 0;
		int profit = 0;
		System.out.println("Units Rent    profit");
		while (notOccupied <= apartments) {
			rent = rent + (notOccupied * increase);
			profit = (apartments - notOccupied) * rent
					- (maintenance * notOccupied);
			System.out.println((apartments - notOccupied) + "    " + rent
					+ "    " + profit);
			if (maxProfit < profit) {
				maxApartments = (apartments - notOccupied);
				maxProfit = profit;
				maxRent = rent;
		System.out.println("Maximum Profit: " + maxProfit);
		System.out.println("It occurs when Number of occupied Units is: "
				+ maxApartments + " and  rent is: " + maxRent);

	public static void main(String args[]) {
		RealEstate re = new RealEstate();
		Scanner input = new Scanner(;
		System.out.print("Enter the number of apartment units: ");
		int apartments = input.nextInt();
		System.out.print("Enter the Rent value for all the occupied units: ");
		int rent = input.nextInt();
		System.out.print("Enter the increase in rent value: ");
		int increase = input.nextInt();
				.print("Enter the Maintenance value for each occupied unit: ");
		int maintenance = input.nextInt();

		re.findMaxProfit(apartments, rent, increase, maintenance);


Posted on: June 16, 2010 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.


Advertisement null