Instructions Task: Exception handling This program will be reused in the next lab. Save it at a safe place. Write the bin2Dec(String binaryString) method to convert a String representing a binary number into a decimal number (assume it fits into an int type). Implement the bin2Dec method to throw a NumberFortmatException if the string is not a binary string. Write a test main method, in the same class, that prompts the user to enter a binary number as a String and displays its decimal equivalent. If the bin2Dec method throws an exception, display "Not a binary number:" followed by a space and the input string. This message (for example, "Not a binary number: 123" in the sample runs) should be put as the message field in the exception object, which will be returned by the getMessage() method. Below are sample runs. Enter a binary number: 101 The decimal value for binary number 101 is 5 Enter a binary number: 110110110 The decimal value for binary number 110110110 is 438 Enter a binary number: 123 Not a binary number: 123
Instructions Task: Exception handling This program will be reused in the next lab. Save it at a safe place. Write the bin2Dec(String binaryString) method to convert a String representing a binary number into a decimal number (assume it fits into an int type). Implement the bin2Dec method to throw a NumberFortmatException if the string is not a binary string. Write a test main method, in the same class, that prompts the user to enter a binary number as a String and displays its decimal equivalent. If the bin2Dec method throws an exception, display "Not a binary number:" followed by a space and the input string. This message (for example, "Not a binary number: 123" in the sample runs) should be put as the message field in the exception object, which will be returned by the getMessage() method. Below are sample runs. Enter a binary number: 101 The decimal value for binary number 101 is 5 Enter a binary number: 110110110 The decimal value for binary number 110110110 is 438 Enter a binary number: 123 Not a binary number: 123
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 2PE
Related questions
Question
Write the code in java and understand what the question says and give me the code and don't copy or plagiarize please
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 3 steps with 2 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
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning