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
1
Expert's answer
2014-08-13T09:16:32-0400
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("Enter cost per kilowatt-hour in cents: ");
cost = Double.parseDouble(inpScan.nextLine());

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

System.out.format("Annual cost: %.4f%n", 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 the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS