68 282
Assignments Done
99%
Successfully Done
In November 2018

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("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 first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions