Guest User

Untitled

a guest
Feb 15th, 2018
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.12 KB | None | 0 0
  1. /**
  2. * @param args the command line arguments
  3. */
  4. public static void main(String[] args) {
  5. //Create the variable
  6. double[][] businesses = new double[10][];
  7.  
  8. Scanner in = new Scanner(System.in);
  9.  
  10. boolean yes = true;
  11. int numYears;
  12.  
  13. double initInvestment;
  14. double profitMargin;
  15. double fixedExp;
  16. double variableExp;
  17.  
  18. System.out.println("Please enter the number of years for the financial analysis? ");
  19. numYears = in.nextInt();
  20.  
  21. System.out.println("Please enter the initial investment capital? ");
  22. initInvestment = in.nextDouble();
  23.  
  24. //start while
  25. int i = 0;
  26.  
  27. while (yes) {
  28. double[] eachBusiness = new double[3];
  29. System.out.println("Please enter the profit margin (%) for business# " + i);
  30. profitMargin = in.nextDouble();
  31. eachBusiness[0] = profitMargin;
  32.  
  33. System.out.println("Please enter the annual fixed expenses for business# " + i);
  34. fixedExp = in.nextDouble();
  35. eachBusiness[1] = fixedExp;
  36.  
  37. System.out.println("Please enter the annual variable expenses for business# " + i);
  38. variableExp = in.nextDouble();
  39. eachBusiness[2] = variableExp;
  40.  
  41. System.out.println("Do you want to process more businesses? true/false");
  42. yes = in.nextBoolean();
  43.  
  44. businesses[i] = eachBusiness;
  45.  
  46. i++;
  47. }//end-while
  48.  
  49. //show results for each business and store all their profits
  50. double profits[] = new double[10];
  51. for (int j = 0; j < i; j++) {
  52. profits[j] = calculate(numYears, j, initInvestment,
  53. businesses[j][0], businesses[j][1], businesses[j][2]);
  54. }
  55.  
  56. System.out.println("---------------------------------");
  57.  
  58. //find most profitable business
  59. int mostProfits = 0;
  60. double profit = 0.0;
  61. for (int j = 0; j < i; j++) {
  62. if (profits[j] > profit) {
  63. profit = profits[j];
  64. mostProfits = j;
  65. }//end-if
  66. }//end-for
  67.  
  68. //Display the result
  69. System.out.println("* most profitable business is number: "
  70. + mostProfits + ", with overall profit= "
  71. + String.format("%.2f", profit - initInvestment));
  72.  
  73. //calculate when it will reach 100% ROI
  74. double ROI = findROI(initInvestment, businesses[mostProfits][0],
  75. businesses[mostProfits][1], businesses[mostProfits][2]);
  76. System.out.println("* It will achieve/exceed 100% ROI in year:("
  77. + String.format("%.0f", ROI) + "), with a total ending "
  78. + "balance at the end of year(" + (numYears - 1)
  79. + ") = " + String.format("%.2f", profit));
  80.  
  81. }
  82.  
  83. //find the the max profit business#
  84. public static double calculate(int years, int i,
  85. double starting_balance, double profit_margin,
  86. double fixed_expenses, double variable_expenses) {
  87.  
  88. double originalInvestment = starting_balance;
  89.  
  90. int year;
  91. double endBalance = 0.0;
  92. double ROI;
  93. double net_profit;
  94. double gross_profit;
  95. double all_expenses;
  96.  
  97. System.out.println("--------------------");
  98. System.out.println("Currently analysing business# " + i);
  99. System.out.println("--------------------");
  100.  
  101. for (year = 0; year < years; year++) {
  102.  
  103. gross_profit = starting_balance * profit_margin;
  104.  
  105. all_expenses = starting_balance * variable_expenses + fixed_expenses;
  106.  
  107. net_profit = gross_profit - all_expenses;
  108.  
  109. endBalance = starting_balance + net_profit;
  110.  
  111. System.out.println("year:" + year + " analysis");
  112. System.out.println("grossProfit: " + String.format("%.2f", gross_profit));
  113. System.out.println("netProfit: " + String.format("%.2f", net_profit));
  114. System.out.println("endBalance: " + String.format("%.2f", endBalance));
  115.  
  116. starting_balance = endBalance;
  117.  
  118. }//end-for
  119. return endBalance;
  120.  
  121. }//end max profits
  122.  
  123. //find yearROI
  124. public static double findROI(double starting_balance,
  125. double profit_margin, double fixed_expenses,
  126. double variable_expenses) {
  127.  
  128. double originalInvestment = starting_balance;
  129. double endBalance = 0.0;
  130. double ROI = 0.0;
  131. double net_profit;
  132. double gross_profit;
  133. double all_expenses;
  134.  
  135. int yearROI = 0;
  136.  
  137. while (ROI < 1.00) {
  138.  
  139. gross_profit = starting_balance * profit_margin;
  140.  
  141. all_expenses = starting_balance * variable_expenses + fixed_expenses;
  142.  
  143. net_profit = gross_profit - all_expenses;
  144.  
  145. endBalance = starting_balance + net_profit;
  146.  
  147. ROI = (endBalance - originalInvestment) / originalInvestment;
  148.  
  149. starting_balance = endBalance;
  150.  
  151. yearROI++;
  152. }//end-while
  153. return yearROI-1;
  154. }//end find yearROI
  155. }
Advertisement
Add Comment
Please, Sign In to add comment