A pedometer treats walking 2,000 steps as walking 1 mile. Write a stepsTOMiles() method that takes the number of steps as an integer parameter and returns the miles walked as a double. The stepsToMiles() method throws an Exception object with the message "Exception: Negative step count entered." when the number of steps is negative. Complete the main() method that reads the number of steps from a user, calls the steps ToMiles() method, and outputs the returned value from the steps ToMiles() method. Use a try-catch block to catch any Exception object thrown by the stepsToMiles() method and output the exception message. Output each floating-point value with two digits after the decimal point, which can be achieved as follows: System.out.printf("%.2f", yourValue); Ex: If the input of the program is: 5345 the output of the program is: 2.67 Ex: If the input of the program is: -3850 the output of the program is: Exception: Negative step count entered.
A pedometer treats walking 2,000 steps as walking 1 mile. Write a stepsTOMiles() method that takes the number of steps as an integer parameter and returns the miles walked as a double. The stepsToMiles() method throws an Exception object with the message "Exception: Negative step count entered." when the number of steps is negative. Complete the main() method that reads the number of steps from a user, calls the steps ToMiles() method, and outputs the returned value from the steps ToMiles() method. Use a try-catch block to catch any Exception object thrown by the stepsToMiles() method and output the exception message. Output each floating-point value with two digits after the decimal point, which can be achieved as follows: System.out.printf("%.2f", yourValue); Ex: If the input of the program is: 5345 the output of the program is: 2.67 Ex: If the input of the program is: -3850 the output of the program is: Exception: Negative step count entered.
C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter14: Exception Handling
Section: Chapter Questions
Problem 4PE
Related questions
Question
Needed code

Transcribed Image Text:A pedometer treats walking 2,000 steps as walking 1 mile. Write a stepsToMiles() method that takes the
number of steps as an integer parameter and returns the miles walked as a double. The stepsToMiles()
method throws an Exception object with the message "Exception: Negative step count entered." when the
number of steps is negative. Complete the main() method that reads the number of steps from a user, calls
the stepsToMiles() method, and outputs the returned value from the stepsToMiles() method. Use a try-catch
block to catch any Exception object thrown by the stepsToMiles() method and output the exception message.
Output each floating-point value with two digits after the decimal point, which can be achieved as follows:
System.out.printf("%.2f", yourValue);
Ex: If the input of the program is:
5345
the output of the program is:
2.67
Ex: If the input of the program is:
-3850
the output of the program is:
Exception: Negative step count entered.
373020.2041158.gx3zgy7
![1 import java.util.Scanner;
3 public class LabProgram {
/* Define your method here */
4
public static void main(String [] args) {
Scanner scnr = new Scanner(System.in);
8.
/* Type your code here. */
}
9
10
11 }
12](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F722c0934-aff7-4600-989e-1d198e6697ab%2Fd5735549-35b1-4966-9766-98f34f0a0eee%2Fle5ro3s_processed.jpeg&w=3840&q=75)
Transcribed Image Text:1 import java.util.Scanner;
3 public class LabProgram {
/* Define your method here */
4
public static void main(String [] args) {
Scanner scnr = new Scanner(System.in);
8.
/* Type your code here. */
}
9
10
11 }
12
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 3 images

Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Recommended textbooks for you

C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning

EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT

Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,

C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning

EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT

Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage

C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr

EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781305480537
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT