82 290
Assignments Done
99,5%
Successfully Done
In January 2020

# Answer to Question #16123 in Java | JSP | JSF for Christoper

Question #16123
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");
}

}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

#### Comments

No comments. Be first!

### Ask Your question

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS