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.
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:
Write a Java program to convert power in kilowatts (kW) of an electric car motor to...