import java.util.Scanner; public class Apartment { public static void main(String[] args) { int unit, rent, main, increase, min=0, ntotal=0, total=0, profit, irent=0; int nunit=0, ncost, cost, max; Scanner keyboard = new Scanner(System.in); System.out.println("Enter the total number of apartment units:"); unit=keyboard.nextInt(); System.out.println("Enter the rent to occupy ALL the units:"); rent=keyboard.nextInt(); System.out.println("Enter the increase in rent that results in a vacant unit:"); increase=keyboard.nextInt(); System.out.println("Enter the amount to maintain a rented unit:"); main=keyboard.nextInt(); total=(rent*unit); cost=unit*main; profit=total-cost; do { nunit=(unit-1); irent=(increase+rent); ntotal=(irent*nunit); ncost=nunit*main; min=ntotal-ncost; } while (profit>min); System.out.println("With "+unit+" apartment units and $"+rent+" each to occupy ALL the units, "); System.out.println("assuming that each increase of $"+increase+" results in one vacant unit, and"); System.out.println("assuming that it costs $"+main+" to maintain each unit ..."); System.out.println("The optimum rent to charge is "+irent); System.out.println(nunit+" apartment units can be rented at this rate."); System.out.println("This will yield a total of "+min+" per month."); System.exit(0); } }
I am trying to figure out what my other loop should be. I need the program to run and find max amount of profit. i think i need to add a for loop, but I am not sure.