Question

Write a Java program to convert power in kilowatts (kW) of an electric car motor to...

Write a Java program to convert power in kilowatts (kW) of an electric car motor to horsepower (hp) as follows:

Prompt the user to enter the power in kilowatts (kW) of the electric car motor.

Convert the power to horsepower. In a comment, reference your source for the conversion factor (non-wiki source). (As a rough estimate, 1 hp equals ~0.75 kW.)

Output the power in horsepower (hp). Print the result with 2 decimal places.

Once this is working, add a do-while loop such that, after the power is displayed, the user sees:

“Repeat the calculation (Y/N)?: ”

If the user enters the character ‘Y’ or ‘y’, then repeat the process of requesting new user input, calculating and displaying the converted power. If the user enters any other character, then quit.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

import java.util.Scanner;

public class One {

public static void main(String[] args) {

char a ;

//Scanner function to get the input from user

Scanner scan = new Scanner(System.in);

do{

//Getting the input power in kilo Watts from user

System.out.print("Enter the power in Kilo watts: ");

double in = scan.nextDouble();

// It is know that 1 Horse power = 745.7 watts which can be found anywhere on the internet

double out = in * 0.7457;

//Printing the output to the console

System.out.println(in+" kWatts = "+out+" Horse Power");

System.out.print("Enter Y to continue: ");

a = scan.next().charAt(0);

}while(a == 'Y'|| a=='y');

//Exiting the program

System.out.println("Thanks for using kilo watts to Horse Power converter");

}

}

// End of Class

Output:

Add a comment
Know the answer?
Add Answer to:
Write a Java program to convert power in kilowatts (kW) of an electric car motor to...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT