77 902
Assignments Done
98,6%
Successfully Done
In August 2019

Answer to Question #44808 in Java | JSP | JSF for Jackie

Question #44808
Write a program that calculates the annual cost of running an appliance. The program will ask the user for the cost per kilowatt-hour and the number of kilowatt-hours the appliance uses in a year:
Enter cost per kilowatt-hour in cents: 8.42
Enter kilowatt-hours used per year : 653
Annual cost: 54.9826
Expert's answer
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
double cost = 0;
double used = 0;
Scanner inpScan = new Scanner(System.in);

System.out.print(&quot;Enter cost per kilowatt-hour in cents: &quot;);
cost = Double.parseDouble(inpScan.nextLine());

System.out.print(&quot;Enter kilowatt-hours used per year: &quot;);
used = Double.parseDouble(inpScan.nextLine());

System.out.format(&quot;Annual cost: %.4f%n&quot;, cost*used*0.01);

inpScan.close();
}
}

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!

Submit