Java Programming 1: Write an application that computes a business\'s potential p
ID: 658244 • Letter: J
Question
Java Programming 1:
Write an application that computes a business's potential profits for each year for 20 years using the following assumptions: 1) gross profit in the first year is projected to be $20,000 2) expenses in the first year are exptected to be $35,000 3) net profit or loss is gross porfit minus expenses 4) gross profits are expected to increase 10% each year 5) expenses are expected to increase 4% each year.
Display the year, the gross profit, the expenses, and the net profit for each year. Also deplay the year in which a net profit is first reported. Save the file as WhenProfitable.java
Explanation / Answer
Program:
//WhenProfitable.java
public class WhenProfitable {
public static void main(String[] args) {
int grossProfit[]=new int[20];
grossProfit[0]=20000;
int Expenses[]=new int[20];
Expenses[0]=35000;
int netProfitOrLoss[]=new int[20];
int firstProfitYear = -1;
int profitIncrease=0;
int expenseIncrease=0;
System.out.print(" "+String.format("%20s","YEAR")+String.format("%20s","GROSS PROFIT")
+String.format("%20s","EXPENSES")+String.format("%20s","NET PROFIT / LOSS")+" ");
for(int i=0;i<20;i++)
{
if(i!=0){
grossProfit[i]=grossProfit[i-1]+profitIncrease;
Expenses[i]=Expenses[i-1]+expenseIncrease;
}
netProfitOrLoss[i]=grossProfit[i]-Expenses[i];
System.out.print(" "+String.format("%20s",i+1)+String.format("%20s",grossProfit[i])
+String.format("%20s",Expenses[i])+String.format("%20s",netProfitOrLoss[i])+" ");
profitIncrease=(grossProfit[i]*10/100);
expenseIncrease=(Expenses[i]*4/100);
}
for(int i=0;i<20;i++)
{
if(netProfitOrLoss[i]>0)
{
firstProfitYear=i+1;
break;
}
}
if(firstProfitYear!=-1)
System.out.println(" Year in which a net profit is first reported: "+firstProfitYear);
else
System.out.println(" No years have netprofit");
}
}
Output:
YEAR GROSS PROFIT EXPENSES NET PROFIT / LOSS
1 20000 35000 -15000
2 22000 36400 -14400
3 24200 37856 -13656
4 26620 39370 -12750
5 29282 40944 -11662
6 32210 42581 -10371
7 35431 44284 -8853
8 38974 46055 -7081
9 42871 47897 -5026
10 47158 49812 -2654
11 51873 51804 69
12 57060 53876 3184
13 62766 56031 6735
14 69042 58272 10770
15 75946 60602 15344
16 83540 63026 20514
17 91894 65547 26347
18 101083 68168 32915
19 111191 70894 40297
20 122310 73729 48581
Year in which a net profit is first reported: 11
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.