Problem #1: [25 pts] Binary number calculator Write a Java program that creates an array data of size 8, representing a binary number of 8 bits. The user must fill/enter the elements of this array only by inputting 0 or 1. If the user enters any different number, the program must stop and display all invalid entries. If all entered digits are valid binary digits, the program must calculate and output the special decimal number represented by this binary number as shown in the below example: If the array data is 1 1 0 X 2'+ 1 X 22 + 1 X 2'+ O X 25 + O X 24+ O X 2'+ + 0 + 0 + 0 + Result = 1 X 2° + O X 2' Result = 1 4 8 13 Then the result is calculated by multiplying the value of the data array at each index with the result of 2 mdex then adding all the answers. (shown in the above example) Sample run1: Enter the digits consisting of (0s or 1s): 2 5 4 1 3 2 5 7 The following entries are invalid: 4 3 7 Sample run2: Enter the digits consisting of (0s or 1s): 1 1 1 1 3 0 0 2 The following entries are invalid: 3 Sample run3: Enter the digits consisting of (0s or 1s): 1 1 1 1 0 0 0 0 The number in decimal is 15 Sample run4: Enter the digits consisting of (0s or 1s): 1 0 1 1 0 00 0 The number in decimal is 13 Page 3 of 8

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
Please solve faster using java1 (csci 250)
Problem #1: [25 pts] Binary number calculator
Write a Java program that creates an array data of size 8, representing a binary number of 8 bits.
The user must fill/enter the elements of this array only by inputting 0 or 1. If the user enters any different
number, the program must stop and display all invalid entries.
If all entered digits are valid binary digits, the program must calculate and output the special decimal
number represented by this binary number as shown in the below example:
If the array data is
1
1
1
Result = 1X 2° +
O X 2'+
1 X 23 +
O X 25 +
O X 2'
0 + 0 + 0
1 X 2' +
O X 2'+
O X 2* +
Result =
1
4
8 + 0 +
13
Then the result is calculated by multiplying the value of
then adding all the answers. (shown in the above example)
data array at each index
ith
result of 2 index
Sample run1:
Enter the digits consisting of (0s or 1s): 2 5 4 1 3 2 5 7
The following entries are invalid:
2
3
7
Sample run2:
Enter the digits consisting of (0s or 1s): 1 1 1 1 3 0 0 2
The following entries are invalid:
3
Sample run3:
Enter the digits consisting of (Os or 1s): 1 1 1 1 0 0 0 0
The number in decimal is 15
Sample run4:
Enter the digits consisting of (Os or 1s): 1 0 1 1 0 0 0 0
The number in decimal is 13
Page 3 of 8
Transcribed Image Text:Problem #1: [25 pts] Binary number calculator Write a Java program that creates an array data of size 8, representing a binary number of 8 bits. The user must fill/enter the elements of this array only by inputting 0 or 1. If the user enters any different number, the program must stop and display all invalid entries. If all entered digits are valid binary digits, the program must calculate and output the special decimal number represented by this binary number as shown in the below example: If the array data is 1 1 1 Result = 1X 2° + O X 2'+ 1 X 23 + O X 25 + O X 2' 0 + 0 + 0 1 X 2' + O X 2'+ O X 2* + Result = 1 4 8 + 0 + 13 Then the result is calculated by multiplying the value of then adding all the answers. (shown in the above example) data array at each index ith result of 2 index Sample run1: Enter the digits consisting of (0s or 1s): 2 5 4 1 3 2 5 7 The following entries are invalid: 2 3 7 Sample run2: Enter the digits consisting of (0s or 1s): 1 1 1 1 3 0 0 2 The following entries are invalid: 3 Sample run3: Enter the digits consisting of (Os or 1s): 1 1 1 1 0 0 0 0 The number in decimal is 15 Sample run4: Enter the digits consisting of (Os or 1s): 1 0 1 1 0 0 0 0 The number in decimal is 13 Page 3 of 8
Expert Solution
steps

Step by step

Solved in 2 steps with 3 images

Blurred answer
Knowledge Booster
Binary numbers
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
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