Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please answer. Thank you. A binary periodic number is a binary fractional number that include a periodic (or recurring) fractional part. For example, 100.01.101 is

Please answer. Thank you.

image text in transcribed

image text in transcribed

A binary periodic number is a binary fractional number that include a periodic (or recurring) fractional part. For example, 100.01.101 is a binary periodic number, where 100 is called the characteristic, 01 is called the anti-period, and 101 is called the period. Hence, a binary periodic number can be represented as characteristic.antiperiod period where any two of characteristic, antiperiod, period can be empty, but not all three. (A string where all of them are empty would be invalid.) Examples of valid strings are .10_001, 10.1, 10..101, .-01. On the other hand, -- is an invalid string. A binary periodic number can be represented as a rational number by applying the following rules: To evaluate the characteristic, proceed from right to left, and multiply each digit by increasing powers of 2 (starting from 2 = 1). In this example, 1* 22 +0*21 +0*2 = 4. To evaluate the anti-period, proceed from left to right, and divide each digit by increasing powers 2 (starting from 21 = 2). In this example, To evaluate the period, proceed from right to left, and multiply each digit by increasing powers of 2 (starting from 2 = 1). (This is the same process that is applied to the characteristic.) Then, divide the result by 24 (2P 1), where a is the length of the anti-period, and b is the length of the period. In this example, 101 evaluates to 5, a = length(anti period) = 2, b= length(period) = 3, yielding 22/03_1 The rational number which represents the binary periodic number is obtained by adding the value of characteristic, anti-period and period. In this example, 100.01101 evaluates to 4+ i + = 124 = 31. The final rational number should be in simplifed form. Implement the following : A constructor Rational Number (String s) where string s is of the form characteristic.antiperiod. period. The constructor should parse s and convert the binary periodic number to a ratio- nal number. Hint : int java.lang.String.indexOf(int ch) returns the index of the first occurrence of character ch in the string. char java.lang.String.charAt(int index) returns the char value at the specified index. char java.lang. String.substring(int beginIndex, int endIndex) returns a new String that is a substring of this String from beginIndex included up to endIndex excluded

Step by Step Solution

There are 3 Steps involved in it

Step: 1

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

Students also viewed these Databases questions