A real estate office handles 50 apartment units. When the rent is $600 per month, all the units are occupied. However, for each $40 increase in rent,one unit becomes vacant. Each occupied unit requires an average of $27 permonth for maintenance. How many units should be rented to maximize the profit
import java.util.*;
import java.io.*;
public class ChapterFiveHomework
{
static Scanner console = new Scanner(System.in);
public static void main(String[] args) throws FileNotFoundException
{
int units;
double rent;
double startRent;
double rentInc;
double maintenance;
double totalMaintenance;
double earnings;
double earnings2;
System.out.println("Enter the number of appartment units.");
units = console.nextInt();
System.out.println("Enter the rent ammount when all units are occupied.");
rent = console.nextDouble();
System.out.println("Enter the increase in rent that results in a vacant"
+" unit.");
rentInc = console.nextDouble();
System.out.println("Enter the ammount to maintain a rented unit.");
maintenance = console.nextDouble();
earnings2 = (units-1)*(rent+rentInc)-maintenance*(units-1);
earnings = units*rent-maintenance*units;
do
{
units--;
rent = rent+rentInc;
earnings = (units--)*(rent+rentInc)-(maintenance*(units--));
}
while (earnings > earnings2);
System.out.println("Number of units to rent:" + (units));
System.out.printf("Ammount to charge for rent: %.2f", rent);
}
}
Aucun commentaire:
Enregistrer un commentaire