Question: 1. Declare and implement a class named BinaryStrings. The class will contain the following methods: incBinary(String b) returns b+1 in binary. //examples - incBinary(101)

1. Declare and implement a class named BinaryStrings. The class will contain the following methods:

incBinary(String b) – returns b+1 in binary.

//examples - incBinary("101") = "110", incBinary("111") = "1000"

decBinary(String b) – returns b-1 in binary assuming b contains at least one 1s.

//examples - decBinary("101") = "100", decBinary("100") = "11"

printBinary(int n) – prints 0 to n in binary calling incBinary() method repeatedly.

//examples - printBinary(15) must print 0, 1, 10, 11, 100, 101, 110, 111, 1000, 1001, 1010, 1011, 1100, 1101, 1110, 1111 in this order.

Note:

You will have to manipulate the given string parameter b directly without changing it to

numeric value like int or long in both incBinary and decBinary methods.

You are not allowed to use any built-in methods that change decimal to binary or binary to

decimal either.

.length(), .charAt(), .indexOf(), .lastIndexOf(), and .substring() are the only built-in methods

allowed.

2. Use the following menu in the main method:

i: increase binary

d: decrease binary

p: print binary

q: Quit

Select:

3. Test your program

Step by Step Solution

3.43 Rating (159 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

public class BinaryStrings Method to increment a binary string by 1 public String incBinaryString b int carry 1 char arr btoCharArray int index arrlen... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Electrical Engineering Questions!