Write an algorithm that is given your electric meter readings (in kilowatt-hours) at the beginning and end of each month of the year. The algorithm determines your annual cost of electricity on the basis of a charge of 6 cents per kilowatt-hour for the first 1,000 kilowatt-hours of each month and 8 cents per kilowatt-hour beyond 1,000. After printing out your total annual charge, the algorithm also determines whether you used less than 500 kilowatt- hours for the entire year and, if so, prints out a message thanking you for conserving electricity.
1
Expert's answer
2012-11-01T11:25:34-0400
public static void saveEnergie(int [] mas){ int limit=0; double averageEnergeiY=0.0;//average for the year int energeiPay=0;//fees for year
for(int i=0;i<mas.length;i++){ if(mas[i]<1000){///6 cents when less than 1000
averageEnergeiY+=mas[i]; energeiPay+=(mas[i]*6); }else{ averageEnergeiY+=mas[i]; energeiPay+=(mas[i]*8); } } averageEnergeiY/=12;////average for the year limit=Math.round((float)averageEnergeiY);///Rounds to equalize with 500
if(limit<=500){ System.out.println("Thanking you for conserving electricity."); System.out.print("Expenses for the year :"); System.out.println((int)energeiPay/100+" $ "+energeiPay0+"cents");///conversion payment }else{ System.out.println(" You do not save electricity ."); System.out.print("Expenses for the year :"); System.out.println((int)energeiPay/100+" $ "+energeiPay0+"cents"); }
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