Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) {
- //Create the variable
- double[][] businesses = new double[10][];
- Scanner in = new Scanner(System.in);
- boolean yes = true;
- int numYears;
- double initInvestment;
- double profitMargin;
- double fixedExp;
- double variableExp;
- System.out.println("Please enter the number of years for the financial analysis? ");
- numYears = in.nextInt();
- System.out.println("Please enter the initial investment capital? ");
- initInvestment = in.nextDouble();
- //start while
- int i = 0;
- while (yes) {
- double[] eachBusiness = new double[3];
- System.out.println("Please enter the profit margin (%) for business# " + i);
- profitMargin = in.nextDouble();
- eachBusiness[0] = profitMargin;
- System.out.println("Please enter the annual fixed expenses for business# " + i);
- fixedExp = in.nextDouble();
- eachBusiness[1] = fixedExp;
- System.out.println("Please enter the annual variable expenses for business# " + i);
- variableExp = in.nextDouble();
- eachBusiness[2] = variableExp;
- System.out.println("Do you want to process more businesses? true/false");
- yes = in.nextBoolean();
- businesses[i] = eachBusiness;
- i++;
- }//end-while
- //show results for each business and store all their profits
- double profits[] = new double[10];
- for (int j = 0; j < i; j++) {
- profits[j] = calculate(numYears, j, initInvestment,
- businesses[j][0], businesses[j][1], businesses[j][2]);
- }
- System.out.println("---------------------------------");
- //find most profitable business
- int mostProfits = 0;
- double profit = 0.0;
- for (int j = 0; j < i; j++) {
- if (profits[j] > profit) {
- profit = profits[j];
- mostProfits = j;
- }//end-if
- }//end-for
- //Display the result
- System.out.println("* most profitable business is number: "
- + mostProfits + ", with overall profit= "
- + String.format("%.2f", profit - initInvestment));
- //calculate when it will reach 100% ROI
- double ROI = findROI(initInvestment, businesses[mostProfits][0],
- businesses[mostProfits][1], businesses[mostProfits][2]);
- System.out.println("* It will achieve/exceed 100% ROI in year:("
- + String.format("%.0f", ROI) + "), with a total ending "
- + "balance at the end of year(" + (numYears - 1)
- + ") = " + String.format("%.2f", profit));
- }
- //find the the max profit business#
- public static double calculate(int years, int i,
- double starting_balance, double profit_margin,
- double fixed_expenses, double variable_expenses) {
- double originalInvestment = starting_balance;
- int year;
- double endBalance = 0.0;
- double ROI;
- double net_profit;
- double gross_profit;
- double all_expenses;
- System.out.println("--------------------");
- System.out.println("Currently analysing business# " + i);
- System.out.println("--------------------");
- for (year = 0; year < years; year++) {
- gross_profit = starting_balance * profit_margin;
- all_expenses = starting_balance * variable_expenses + fixed_expenses;
- net_profit = gross_profit - all_expenses;
- endBalance = starting_balance + net_profit;
- System.out.println("year:" + year + " analysis");
- System.out.println("grossProfit: " + String.format("%.2f", gross_profit));
- System.out.println("netProfit: " + String.format("%.2f", net_profit));
- System.out.println("endBalance: " + String.format("%.2f", endBalance));
- starting_balance = endBalance;
- }//end-for
- return endBalance;
- }//end max profits
- //find yearROI
- public static double findROI(double starting_balance,
- double profit_margin, double fixed_expenses,
- double variable_expenses) {
- double originalInvestment = starting_balance;
- double endBalance = 0.0;
- double ROI = 0.0;
- double net_profit;
- double gross_profit;
- double all_expenses;
- int yearROI = 0;
- while (ROI < 1.00) {
- gross_profit = starting_balance * profit_margin;
- all_expenses = starting_balance * variable_expenses + fixed_expenses;
- net_profit = gross_profit - all_expenses;
- endBalance = starting_balance + net_profit;
- ROI = (endBalance - originalInvestment) / originalInvestment;
- starting_balance = endBalance;
- yearROI++;
- }//end-while
- return yearROI-1;
- }//end find yearROI
- }
Advertisement
Add Comment
Please, Sign In to add comment