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
-
Kindly help me solve the following finance question Kimbo Dima Kewa Sh. 120 per share Sh. 160 per share Sh. 140 per share Hari was to receive 10,000 shares of Sh. 10 per value in Dima Ltd. and the...
-
(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...
-
Show that Formula 6 is valid for negative integer exponents if z 0.
-
1. You buy a call option with a strike price of $85 for $13. At expiration, the underlying stock price is $108. a. What is the payoff? b. What is the profit? C. What is the break-even price (where...
-
Brian Hughes and Wendy Perez formed a partnership five years ago. The partnership has been very successful and is growing rapidly. The partners are evaluating future actions for the next five years....
-
J. Los Clothiers has forecast credit sales for the fourth quarter of the year as: September (actual)......................$70,000 Fourth Quarter October ....................................$60,000...
-
[ I Need the answar ASAP ] Tent Master produces Pup tents and Pop - up tents. The company budgets $ 2 6 4 , 0 0 0 of overhead cost and 4 4 , 0 0 0 direct labor hours. Additional information follows....
-
The cash account for Highlander Diamond Co. on April 1, 20Y5, indicated a balance of $35,400. During April, the total cash deposited was $120,255, and checks written totaled $109,200. The bank...
-
Janet Spurlock can invest $25,000 at 5.25% in a 1-year CD compounded quarterly or a 1-year CD compounded daily. a) What is the amount of the CD at maturity for each rate? b) What is the difference in...
-
How do socioecological frameworks elucidate the interconnectedness between environmental factors and an individual's capacity for resilience?
-
The following ratios were defined, computed, and reviewed in prior weeks. The computations are the basis for extracting meaning from the financial statements provided. Each category heading should...
-
Philip has noticed that one of his senior subordinates has flouted workplace safety rules three times. One of Philip's newer subordinates has also flouted the same rules. Philip has decided to ignore...
-
Cake Manufacturers Ltd completes a range of jobs for customers. The budgeted production overhead costs for the next year are: Cost Allocated Overheads: Manufacturing Dept. 1 64800 Manufacturing Dept....
-
Q7: Let f(x)=3x+1 and g(x) = x+ 2, then verify that whether (fog)(x) = (go f) (x) x-x+1 Q8: Show that the function f(x) = = is continuous at x = -3. x-5
-
Gravitational Constant (G) = 6.67 x 10 -11 N-m/kg Mass of Earth = 5.97 x 10 4 kg Radius of Earth = 6.37 x 10 6 m Acceleration Due to Gravity or Gravitational Field Near Earth = 9.81 m/s or 9.81 N/kg...
-
Write a function that reads a Float24_t value: Float24_t float24_read(void) A legitimate float24 value string is of the form: "mantissabexponent" where the mantissa (m) and the exponent (e) may have...
-
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.
-
The constants obtained by Shende and Sharma (1974) for use in Eq. (16-72) are given in the following table. Assume their experiments with \(\mathrm{NaOH}-\mathrm{SO}_{2}\) were done at \(1.0...
-
We are separating methanol and water in a staged distillation column at total reflux to determine Murphree efficiency. Pressure is \(101.3 \mathrm{kPa}\). The column has a 2.0 -in. head of liquid on...
-
The large-scale column in Example 16-4 is fed a saturated liquid with mole fraction \(\mathrm{z}=0.5\), and separation is essentially complete ( \(\mathrm{x}_{\text {dist }} \sim 1.0\) and...
Study smarter with the SolutionInn App