Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

java lanuage. the the consturcotr should set up the value for numerator and deoninator of string 2.3 Binary Periodic Number A binary periodic number is

image text in transcribed
java lanuage. the the consturcotr should set up the value for numerator and deoninator of string
2.3 Binary Periodic Number A binary periodic number is a binary fractional number that includes a (possibly empty) periodie (a.k.a 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 a Java String literal characteristic, antiperiod.period" where any two (but not all three of characteristic antiperiod, puriod can be empty. Examples of valid strings are 10.001, 10.1, 10.101, ..01. But .. is an invalid string. 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, 0.2 +0.2 +1.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 examples + = . To evaluate the period, proceed from right to left, and multiply each digit by increasing powers of 2 (starting from 20 = 1). (This is the same process that is applied to the characteristic.) Then, divide the result by 2" (2-1), where a is the length of the anti-period, and is the length of the period. In this example, 101 evaluates to 5, length(anti-period) - 2, b length(period) -3, yielding - 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.01.101 evaluates to 4 + + + W . The final rational number should be in simplifed form. Implement the following: A constructor Rational Number (String s) where strings is of the form characteristic.antiperiod. period The constructor should purses and convert the binary periodic number to a rational 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 with AI-Powered 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

Question

Agency problem manifestation in Enron Sandal

Answered: 1 week ago