Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

public class BinaryStrings Method to increment a binary string by 1 public String incBinaryString b int carry 1 char arr btoCharArray int index arrlen... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Introduction To Java Programming And Data Structures Comprehensive Version

Authors: Y. Daniel Liang

12th Edition

0136520235, 978-0136520238

More Books

Students also viewed these Electrical Engineering questions

Question

Detailed note on the contributions of F.W.Taylor

Answered: 1 week ago