Homework 00
Binary Changer
02/03/2023 by 11:55PM
Objective:
Write a program that accepts two
four-digit binary numbers, converts them to decimal values, adds them together,
and prints both the decimal values and the result of the addition.
Requirements:
- Functionality. (80pts)
- No
Syntax, Major Run-Time, or Major Logic Errors. (80pts*)
- *Code
that cannot be compiled due to syntax errors is nonfunctional code and
will receive no points for this entire section.
- *Code
that cannot be executed or tested due to major run-time or logic errors
is nonfunctional code and will receive no points for this entire
section.
- Clear and Easy-To-Use
Interface. (10pts)
- Users should easily
understand what the program does and how to use it.
- Users should be
prompted for input and should be able to enter data easily.
- Users should be
presented with output after major functions, operations, or
calculations.
- All the above must
apply for full credit.
- Users
must be able to enter a 4-bit binary number in some way. (10pts)
- No
error checking is needed here and you may
assume that users will only enter 0’s and 1’s, and they will only enter
4 bits.
- Binary
to Decimal Conversion (50pts)
- You
may assume that users will only give numbers that add up to 15.
- See
the section Hint for more details.
- Adding
Values (10pts)
- Both
decimal values must be added together and printed out.
- You may NOT
use Integer.parseInt(<<STRING>>, 2)
or any automatic converter (80pts*).
- *The use of
specifically Integer.parseInt(<<STRING>>,2)
will result in a 0 for this entire section.
- You may
use Integer.parseInt(<<STRING>>).
- Coding Style. (10pts)
- Readable Code
- Meaningful identifiers
for data and methods.
- Proper indentation
that clearly identifies statements within the body of a class, a method,
a branching statement, a loop statement, etc.
- All the above must
apply for full credit.
- Comments. (10pts)
- Your name in the file.
(5pts)
- At least 5 meaningful
comments in addition to your name. These must describe the function of
the code it is near. (5pts)
Hint:
A simple way to convert a binary value to a decimal value.
- Multiply each binary
digit by its corresponding base 2 placement value.
Binary Digit
|
b0
|
b1
|
b2
|
b3
|
Base 2 Value
|
23
|
22
|
21
|
20
|
Result
|
b0 x 23
|
b1 x 22
|
b2 x 21
|
b3 x 20
|
Example:
Binary Digit
|
0
|
1
|
1
|
1
|
Base 2 Value
|
23
|
22
|
21
|
20
|
Result
|
0
|
4
|
2
|
1
|
- Add the values together to
get the decimal value.
Example:
Binary Value = 0 + 4 + 2 + 1 = 7
|
Finally:
Upload the solution’s source file (.JAVA extension) to the
CSCE Dropbox