60 371
Assignments Done
98,1%
Successfully Done
In April 2018

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.
Expert's answer

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!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions