Question

JAVA coding language: Complete the howFast method that take a double parameter, speed, and prints a...

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

}

Homework Answers

Answer #1

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!

Know the answer?
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
Similar Questions
Complete method printPopcornTime(), with int parameter bagOunces, and void return type. If bagOunces is less than...
Complete method printPopcornTime(), with int parameter bagOunces, and void return type. If bagOunces is less than 3, print "Too small". If greater than 10, print "Too large". Otherwise, compute and print 6 * bagOunces followed by "seconds". End with a newline. Example output for ounces = 7: 42 seconds import java.util.Scanner; public class PopcornTimer { public void printPopcornTime(int bagOunces) { /* Your solution goes here */ } public static void main (String [] args) { PopcornTimer popcornBag = new PopcornTimer();...
Using Java language.... Polymorphism of Interfaces : Take the Account class from the last chapter and...
Using Java language.... Polymorphism of Interfaces : Take the Account class from the last chapter and make a java program for your bank. However, there is another type of customer that may not have money in the bank and may not in fact have a back account with this bank at all, but may have a loan here. Make another class in the application you are making called CarLoan. Carloan's should have a name, amount owed, a rate, and a...
Java Code: Console IO Practice Exercise The purpose of this exercise is to practice console input...
Java Code: Console IO Practice Exercise The purpose of this exercise is to practice console input and output with the Java console. Setup: Create a class called ConsolePractice with a main method. Create a static field in your class that stores a scanner object. You will use this scanner for all user input. private static Scanner scanner = new Scanner(System.in); Part A: Create a static method called “divide”. Your method should do the following: Accept two integers as parameters, a...
Modify the following code by JAVA language Write a static method totalDurations that is passed the...
Modify the following code by JAVA language Write a static method totalDurations that is passed the parallel arrays from the main program. It creates a new pair of parallel arrays (phone numbers and durations, again) where each different incoming phone number is stored exactly once, and the duration is the total duration of all the calls from that phone number. It then prints these arrays. Nothing is returned. For example, if the arrays contain 555-1234 (duration 10), 555-4321 (duration 20),...
public static int newtonCount​(double x, double err) Determines the number of iterations of Newton's method required...
public static int newtonCount​(double x, double err) Determines the number of iterations of Newton's method required to approximate the square root of x within the given bound. Newton's method starts out by setting the initial approximate answer to x. Then in each iteration, answer is replaced by the quantity (answer + x / answer) / 2.0. The process stops when the difference between x and (answer * answer) is strictly less than the given bound err. The method returns the...
Java Program Implement a class called AnimalTrainer. Include the following data types in your class with...
Java Program Implement a class called AnimalTrainer. Include the following data types in your class with the default values denoted by dataType name : defaultValue - String animal : empty string - int lapsRan : 0 - boolean resting : false - boolean eating : false - double energy : 100.00 For the animal property implement both getter/setter methods. For all other properties implement ONLY a getter method Now implement the following constructors: 1. Constructor 1 – accepts a String...
Hi, I'm writing a Java program that prints a grid with circles and squares that have...
Hi, I'm writing a Java program that prints a grid with circles and squares that have letters in them and it is also supposed to print the toString() function to the console window each time the application runs. This toString() function is supposed to show the tile's shape, letter, and color component (or components). Could someone please review and debug my code to help me figure out why my toString() function is not working? import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JButton;...
JAVA please Arrays are a very powerful data structure with which you must become very familiar....
JAVA please Arrays are a very powerful data structure with which you must become very familiar. Arrays hold more than one object. The objects must be of the same type. If the array is an integer array then all the objects in the array must be integers. The object in the array is associated with an integer index which can be used to locate the object. The first object of the array has index 0. There are many problems where...
The ability to read through Java™ code and predict the results, given specific inputs, is an...
The ability to read through Java™ code and predict the results, given specific inputs, is an extremely useful skill. For this assignment, you will be analyzing the Java™ code in the linked zip file, and predicting the results given specific input. Carefully read through the code line by line, then answer the following questions in a Microsoft® Word document: What is the output of the program as it is written? What would the output of the program be if you...
Java question, Please answer everything. Thank you Answer the following questions as briefly (but completely) as...
Java question, Please answer everything. Thank you Answer the following questions as briefly (but completely) as possible: What is a checked exception, and what is an unchecked exception? What is NullPointerException? Which of the following statements (if any) will throw an exception? If no exception is thrown, what is the output? 1: System.out.println( 1 / 0 ); 2: System.out.println( 1.0 / 0 ); Point out the problem in the following code. Does the code throw any exceptions? 1: long value...