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
icon
Related questions
Question
Write the code in java and please don't plagiarize or copy from other sources write it on your own. Read carefully and follow the instructions in the question. Thank you.
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
Transcribed Image Text: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
Expert Solution
steps

Step by step

Solved in 3 steps with 4 images

Blurred answer
Knowledge Booster
Header Files
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.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning