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

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
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
trending now

Trending now

This is a popular 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
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education