Suppose you have a pre-existing class Height that keeps track of a height in feet and...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Suppose you have a pre-existing class Height that keeps track of a height in feet and inches. The class has the following data and constructor: Field/Constructor private String description private int feet private double inches Description W Describes the type of height, one of "Building, "Person, and "Tree". W Number of feet (always > 0) public Height(String description, int constructs a Height object with the given description, and number of feet and inches. Throws an exception if description is not one of "Building", "Person" and "Tree", or if feet or inches are negative, or if inches is greater than or equal to 12. feet, int inches) Number of inches (always 0 and <12) Your task is to modify the class to be comparable by adding an appropriate compareTo method. Height objects of different heights are just compared by height irrespective of their description. That is a Height object ("Person", 6 feet, 2.5 inches) is considered greater than a Height object ("Tree", 4 feet, 3.6 inches). Height objects of the same height are compared by their description. For the same height, "Building" Height objects are greater than "Tree" Height objects, and "Tree" Height objects are greater than "Person" Height objects. If two Height objects have the same description and the same height (i.e. same number of feet and inches), they are considered equal. Your method should not modify any Height object's state. You may assume that the parameter passed is not null. . to contain an override of the equals method from Object (public boolean equals(Object obj)). As stated in the compareTo question, two Height objects are considered equal if they have the same description and the same height. to contain an override of the hashCode method from Object (public int hashCode()). The return value of the hashCode method of an object is used to compute the index of the location of the object in a hash table. Write the three methods compareTo, equals and hashCode below. Suppose you have a pre-existing class Height that keeps track of a height in feet and inches. The class has the following data and constructor: Field/Constructor private String description private int feet private double inches Description W Describes the type of height, one of "Building, "Person, and "Tree". W Number of feet (always > 0) public Height(String description, int constructs a Height object with the given description, and number of feet and inches. Throws an exception if description is not one of "Building", "Person" and "Tree", or if feet or inches are negative, or if inches is greater than or equal to 12. feet, int inches) Number of inches (always 0 and <12) Your task is to modify the class to be comparable by adding an appropriate compareTo method. Height objects of different heights are just compared by height irrespective of their description. That is a Height object ("Person", 6 feet, 2.5 inches) is considered greater than a Height object ("Tree", 4 feet, 3.6 inches). Height objects of the same height are compared by their description. For the same height, "Building" Height objects are greater than "Tree" Height objects, and "Tree" Height objects are greater than "Person" Height objects. If two Height objects have the same description and the same height (i.e. same number of feet and inches), they are considered equal. Your method should not modify any Height object's state. You may assume that the parameter passed is not null. . to contain an override of the equals method from Object (public boolean equals(Object obj)). As stated in the compareTo question, two Height objects are considered equal if they have the same description and the same height. to contain an override of the hashCode method from Object (public int hashCode()). The return value of the hashCode method of an object is used to compute the index of the location of the object in a hash table. Write the three methods compareTo, equals and hashCode below.
Expert Answer:
Related Book For
Posted Date:
Students also viewed these programming questions
-
(a) Use the following text to derive distributions for rat and chased. Use a five-word window, including open- and closed- class words, ignore case, punctuation and sentence boundaries and weight...
-
In this programming assignment you will practice using ArrayLists, Inheritance and Polymorphism. You are to write a game called Magical Creatures War. You will do this by implementing a class called...
-
Chee, single, age 40, had the following income and expenses during 2017: Calculate Chees taxable income for the year before personal exemptions. If Chee has any options, choose the method that...
-
Cinders Marketing Corporation reported the following stockholders' equity at December 31 (adapted and in millions): Common stock....................................$ 281 Additional paid-in...
-
Several years ago Ms . Nina Fern ndez purchased a building to be used in a business she carries on as a sole proprietor. The total cost of the property was $ 2 , 3 0 0 , 0 0 0 , with $ 8 0 0 , 0 0 0...
-
How to oppose a motion for summary judgment?
-
A popular product of Loring Glassworks is a hand-decorated vase. The companys standard cost system calls for 0.75 hours of direct labor per vase, at a standard wage rate of $8.25. During September,...
-
Determine the value of P so that the function f is continuous at x = OP=-112 O P = -56 P = 8 7 OP=56 OP=-8 -8, where 7(x - 64) f(x) = if x-8 x+8 P if x = -8
-
Brian and Corrine Lee are married taxpayers filing jointly. They live in the home they own, located at 3301 Pacific Coast Hwy., Laguna Beach, CA 92651. Brian is an optometrist who owns his business;...
-
In terms of psychological factors, who do you think is at fault? Is the company is partly at fault? That is, did they foster "a lot of expectations of growth"? Is it the investment bankers? The media...
-
(d) wave function is given given by Comider system whose 4 (0,4) = { Yoo (0,4) + /13 (1 (0,4) + Y -1 (0,4) + /16 (122 (012) Is 4 (0.4) normalized? gs 4 (0.4) an eigenstate of 2 and L ? Calculate I+ 4...
-
The article"Content Shock: Why Content Marketing is not a Sustainable Strategy"discusses how the popularity of content marketing could lead to its demise. It is suggested that the belief that content...
-
Assume that a company is considering a capital Investment project with a four-year time horizon and the following cash flows: Cost of new equipment Working capital required Annual net cash inflows...
-
Consider the following algorithm which takes an array A[0 ... n - 1] of n elements: Algorithm Mystery answer + true for i 0 to n - 1 do for j - 0 to n - 1 do return answer if i #j and A[i] = A[] then...
-
Hilary Corp. contracted with a company to build a storage warehouse in Year 1 . Construction began on April 1 at which time Hilary Corp. paid $ 6 5 , 0 0 0 . Hilary Corp. then made additional...
-
identify the points of inflection and the intervals of concavity of the function f(x)=-3x + x +8x
-
1. Firms may hold financial assets to earn returns. How the firm would classify financial assets? What treatment will such financial assets get in the financial statements in accordance with US GAAP...
-
Refer to the previous exercise. The same week that the Field Poll was released a Web site called SFGate.com (www.sfgate.com/polls/) (www.sfgate.com/polls/) asked visitors to Click to vote on their...
-
Go to your library or an electronic journal resource and peruse journal articles, looking for examples of scatterplots accompanied by correlations. Find three examples in different journal articles....
-
Would it be easier to reject hypotheses about populations that had a lot of natural variability in the measurements or a little variability in the measurements? Explain.
-
Solve for \(t_{\max }\) in Equation 3.17 in general for arbitrary variables. Then evaluate \(t_{\max }\) numerically for the cases in Table 3.1. Plot each case and discuss trends. Table 3.1: Cases...
-
Coulomb used the following method to determine the viscosity of liquids. A thin plate of weight \(W\) is suspended vertically and set into motion, first in air and then fully submerged in the...
-
The bell-crank mechanism depicted in Figure 3.55 is rotated slightly and released to oscillate in free vibration. Derive the damped frequency of oscillation \(\omega_{d}\) and the critical damping...
Study smarter with the SolutionInn App