JAVA coding language:
Complete the howFast method that take a double parameter, speed, and prints a message based on the value of speed. These are the message that should be printed for each range of values for speed:
"slow" for values of speed less than or equal to 10.
"fast" for values of speed greater than 10 and strictly less than or equal to 50.
"very fast" for values of speed greater than 50 and strictly less than or equal to 100.
"super fast" for values of speed greater than 100 and strictly less than or equal to 150.
"too fast!" for values of speed greater than 150.
Examples:
howFast(9);
prints slow
howFast(45);
prints fast
howFast(90);
prints very fast
howFast(200);
prints too fast!
public static void howFast(double speed) {
//Write the method body code
}
Explanation:
Here is the code which takes the speed as a parameter and then uses the if else if conditional structure to decide what should be printed on the console based on the value of the double variable speed.
Code:
public static void howFast(double speed) {
if(speed<=10)
{
System.out.println("slow");
}
else if(speed>10 && speed<=50)
{
System.out.println("fast");
}
else if(speed>50 && speed<=100)
{
System.out.println("very fast");
}
else if(speed>100 && speed<=150)
{
System.out.println("super fast");
}
else if(speed>150)
{
System.out.println("too fast!");
}
}
PLEASE UPVOTE IF YOU FOUND THIS HELPFUL!
PLEASE COMMENT IF YOU NEED ANY HELP!
Get Answers For Free
Most questions answered within 1 hours.