QUESTION 1
Answer in javascript ..You are given a table that shows the total number of cars sold by a local car manufacturer in Johor Bharu for the first six months in the year 2008.
Month Jan Feb Mar Apr May Jun
Number of cars sold (units) 191 196 269 308 236 145
Based on the figures given above, you required to write a Java program using array which can perform the following:
• Average number of cars sold
• The month that achieve lowest sales
1
Expert's answer
2011-07-11T13:23:29-0400
var sales = new Object; // The associative array with the cars sold during the specific month sales["Jan"] = 191; sales["Feb"] = 196; sales["Mar"] = 269; sales["Apr"] = 308; sales["May"] = 236; sales["Jun"] = 145;
// This function calculates the average number of cars sold function find_average(pSales) { var totalSales = 0; var count = 0; for (var numberOfSales in pSales) { & totalSales += pSales[numberOfSales]; & count++; } return (totalSales / count) - (totalSales % count); }
// This function finds the month that achieve lowest sales function find_lowest_sales_month(pSales) { var lowestSalesMonth; var lowestSales = 1000000; for (var month in pSales) { & if (pSales[month] < lowestSales) & { & lowestSalesMonth = month; & lowestSales = pSales[month]; & } } return lowestSalesMonth; }
document.write("The average number of cars sold is: " + find_average(sales) + " "); document.write("The month that achieve lowest sales is: " + find_lowest_sales_month(sales) + " ");
Numbers and figures are an essential part of our world, necessary for almost everything we do every day. As important…
APPROVED BY CLIENTS
"assignmentexpert.com" is professional group of people in Math subjects! They did assignments in very high level of mathematical modelling in the best quality. Thanks a lot
Comments
Leave a comment