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

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter7: Arrays
Section: Chapter Questions
Problem 1PP: (Statistics) a. Write a C++ program that reads a list of double-precision grades from the keyboard...
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.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr