public SignedNumber long left long mid long right super Mathabs left mid right

# Public signednumber long left long mid long right

• 40

This preview shows page 23 - 25 out of 40 pages.

public SignedNumber (long left, long mid, long right) { super (Math.abs (left), mid, right); isNegative = left < 0; } //... lots more is required here in the same vein Exercise 11.26 Modify the VeryLong constructor to create the equivalent of ZERO when any one of the parameters is negative or has more than eighteen digits. Exercise 11.27 (harder) Write the doubleValue method for the VeryLong class. Exercise 11.28 (harder) Write the equals method for the VeryLong class. Exercise 11.29 (harder) Write a simplified valueOf method for the VeryLong class, for which you have a precondition that the parameter is a string of 1 to 54 digits. Exercise 11.30* Write the full valueOf method for the VeryLong class. Allow the input to contain commas among the digits. Use the preceding exercise to get started. Exercise 11.31* Write a Real subclass of Numeric for ordinary numbers with one double instance variable. This lets the clients mix in ordinary numbers with the special ones. Exercise 11.32* Write the subtract method for the VeryLong class. Exercise 11.33* The Complex instance variables are final but the Fraction instance variables are not, even though both are immutable classes. Explain why. Exercise 11.34** Write the compareTo method for the VeryLong class. Exercise 11.35** The VeryLong toString method produces leading zeros when the leftmost one or more components of itsItem are zero. Revise it to fix this problem. 11.8 Implementing The NumericArray Class With Null-Terminated Arrays These mathematicians often deal with numbers in big bunches. They may read in a bunch of numbers from a file, then calculate the average of the whole bunch, find the smallest and the largest, insert a value in order, etc. For this, you decide to store a lot of Numeric objects in an array of Numeric values. Call it the NumericArray class. Once you define an array, you cannot change its size. So you need to make it big enough for the largest number of values you expect. But then the array is generally only partially filled. So you have to have some way of noting the end of the array. One way is to keep track of the size. Another way is to put the null value in all the components after the end of the actual Numeric values in the array, as shown in Figure 11.5. Figure 11.5 picture of a null-terminated array with six Complex values For instance, if the array has size 1000 and currently contains only 73 values, then those 73 values will be stored in components 0 through 72 and the null value will be stored in each of components 73...1000. We do not allow a full array. A precondition for these null-terminated arrays is that they contain at least one instance of null. Precondition for NumericArrays For the array parameter item , there is some integer n such that 0 <= n < item.length and item[k] is not null when k < n and item[k] is null otherwise. The non-null values are the values on the conceptual list in order, with the first at index 0.
Java Au Naturel by William C. Jones 11-24 11-24 The find method To illustrate how to work with such a null-terminated array, consider the problem of searching through the array to find whether a particular non-null value is there.