here is waht I'm tring to do:
and coding done by meA household is preparing its next month's budget. For this, they want to estimate their monthly grocery spend. They expect their next month's grocery spend to be 10% higher than the average spend over the last several months. Given their grocery spend for the last several months, the expected spend should be rounded off to 2 decimal places. For e.g. if the input is {1004.56,1200,989.50,1100,1050.36,1000.88,1104.56, 990,1089.50,1070,1310.36,900.88}, the expected output is 1174.31
import java.text.DecimalFormat; public class GroceryPlan { static double[] test1 = {1004.56,1200,989.50,1100,1050.36,1000.88,1104.56,990,1089.50,1070,1310.36,900.88}; static double[] testcase = test1; public static void main(String args[]){ GroceryPlan inst = new GroceryPlan(); double v = inst.getEstimate(testcase); System.out.println(v); } // Write your code in the function below public double getEstimate(double[] spends){ double total=0,inc=0; DecimalFormat Form = new DecimalFormat("#.##"); double count= spends.length; for(double element:spends){ total+=element; } System.out.printf("total amount : %.2f\n",total); System.out.println("Months :"+count); total/=count; inc=total*0.1; total+=inc; return Double.valueOf(Form.format(total)); }
output is looking fine but look here when code is check for quality
execution.JPG
Please guide me how to format double values? please look at the screen shot