Question: please answer Directions: SHOW ALL YOUR WORK. REMEMBER THAT PROGRAM SEGMENTS ARE TO BE WRITTEN IN JAVA. Notes Assume that the classes listed in the

 please answer Directions: SHOW ALL YOUR WORK. REMEMBER THAT PROGRAM SEGMENTS

ARE TO BE WRITTEN IN JAVA. Notes Assume that the classes listed

in the Java Quick Reference have been imported where appropriate. Unless otherwise

noted in the question, assume that parameters in method calls are not

please answer

Directions: SHOW ALL YOUR WORK. REMEMBER THAT PROGRAM SEGMENTS ARE TO BE WRITTEN IN JAVA. Notes Assume that the classes listed in the Java Quick Reference have been imported where appropriate. Unless otherwise noted in the question, assume that parameters in method calls are not null and that methods are called only when their preconditions are satisfied. In writing solutions for each question, you may use any of the accessible methods that are listed in classes defined in that question. Writing significant amounts of code that can be replaced by a call to one of these methods will not receive full credit. . 3. This question involves a system to analyze the inventory of different types of flowers sold by a florist. Flower types are represented by the following Flower class. public class Flower /** Returns the name of the flower (e. g., "rose", "tulip", etc.) public string getName() { /* implementation not shown 7** Returns the quantity in stock of the flowers public int getQuantity * implementation not shown *} Sets the quantity in stock of the flower to new public void setquantity (int new * implementation not shown *} // There may be instance variables, constructors, and methods that are not shown. 3 In the following Flowershop class, the array flower Inventory contains information about the flowers sold at a flower shop. You will implement two methods in the flowershop class. public class Flowershop 7** An array of the flowers sold at the flower shop, sorted alphabetically by flower name Guaranteed to be nonempty and to contain only non-null entries *] private Flower() flower Inventory *** Returns a copy of Flower) arr in which the array elements have been sorted in order from highest quantity to lowest quantity public Flower() sortByQuantity (Flower arr) { /* implementation not shown public Flower[] sortByQuantity (Flower arr) { /* implementation not shown /** Updates the Flower objects contained in flower Inventory, as described in part (a) Precondition: newInventory has the same flower names in the same positions as flower Inventory. Postcondition: newInventory is unchanged. public void update Inventory (Flower(newInventory) { /* to be implemented in part (a) */ 7** Returns true if the top n flowers by quantity in stock at the flower shop are the same as the top n flowers by quantity in stock in other Inventory, as described in part (b) Precondition: n is less than or equal to the lengths of flowerinventory and otherInventory. Postcondition: flower Inventory and other Inventory are unchanged. 23 public boolean top Same(int n, Flower ) other Inventory) { /* to be implemented in part (b) */ } // There may be instance variables, constructors, and methods that are not shown. 1 (a) Write the Flowershop method updateInventory, which increases the quantities of the flowers in flower Inventory by the quantities of the flowers in the array parameter newInventory. Each quantity of a flower in newInventory is added to the quantity of the corresponding flower in flower Inventory. The arrays flower Inventory and newInventory are the same length and contain the same flower names in the same positions! For example, assume that sunnyFlowers has been declared as a Flowershop object and newFlowers is a Flower array. The array flower Inventory before the call sunnyFlowers.update Inventory (new Flowers) rose" daffodil 225 "tulip" 419 550 The array newFlowers: daffodil 2ee rose se tulip" 150 The array flower Inventory after the call sunnyFlowers.updateInventory (newflowers): The array flower Inventory after the call sunnyFlowers. updateInventory (newFlowers) daffodil 425 rose 660 tulip" 569 Complete method updateInventory ** Updates the Flower objects contained in flower Inventory, as described in part (a) Precondition: newInventory has the same flower names in the same positions as flower Inventory Postcondition: new Inventory is unchanged. public void updateInventory (Flower[] newInventory) B 1 0 10000 Word Limit (b) Write the Flowershop method topleSame, which compares the flowers that appear in the first n positions of flower Inventory with the flowers that appear in the first in positions of other Inventory when both arrays are sorted in decreasing order by quantity in stock. The method returns true if the first n Flower objects in both arrays are the same and appear in the same position in both soned arrays and retums false otherwise. A helper method, sortByQuantity, has been provided. It retums a copy of its Flower [] parameter sorted in decreasing order by quantity in stock For example, assume that sunnyFlowers has been declared as a Flowershop object and that stocke is an array of Flower objects, The array flower Inventory in sunnyFlowers: Mcarnation 50 daffodil 320 Mdaisy 375 "rose" 550 "tulip 419 The array stocke carnation 250 daffodil 220 daisy 508 rose 525 "tulip 318 2:20 Sud S5 SL The method call sunny Flowers. tapNsame(3, stockB) should return false. For sunnyFlowers, the top three flowers by quantity (in order) are rose "tulip" and "daisy. However, for stocke the top three flowers by quantity (in order) are "rose". "daisy", and "tulip" Complete method top Same. You must use sortByQuantity appropriately to receive full credit. /** Returns true if the top n flowers by quantity in stock at the flower shop are the same as the top n flowers by quantity in stock in otherinventory, as described in part (b) Precondition: n is less than or equal to the lengths of flowerinventory and other inventory. Postcondition: flower Inventory and otherInventory are unchanged. public boolean top Same (int n, Flower [] other Inventory) B 1 0 / 10000 Word Limit (c) A programmer would like to add a method called getMostExpensiveFlower, which returns the name of the flower with the highest price. Write a description of how you would change the Flower and FlowerShop classes in order to support this modification, Make sure to include the following in your response. Write the method header for the getkostexpensiveFlower method Identify any new or modified variables, constructors, or methods aside from the getMostExpensiveFlower method. Do not write the program code for this change. Describe for each new or revised variable, constructor, or method, how it would change or be implemented, including visibility and type. You do not need to describe the implementation of the getrostexpensiveFlower method. Do not write the program code for this change. Directions: SHOW ALL YOUR WORK. REMEMBER THAT PROGRAM SEGMENTS ARE TO BE WRITTEN IN JAVA. Notes Assume that the classes listed in the Java Quick Reference have been imported where appropriate. Unless otherwise noted in the question, assume that parameters in method calls are not null and that methods are called only when their preconditions are satisfied. In writing solutions for each question, you may use any of the accessible methods that are listed in classes defined in that question. Writing significant amounts of code that can be replaced by a call to one of these methods will not receive full credit. . 3. This question involves a system to analyze the inventory of different types of flowers sold by a florist. Flower types are represented by the following Flower class. public class Flower /** Returns the name of the flower (e. g., "rose", "tulip", etc.) public string getName() { /* implementation not shown 7** Returns the quantity in stock of the flowers public int getQuantity * implementation not shown *} Sets the quantity in stock of the flower to new public void setquantity (int new * implementation not shown *} // There may be instance variables, constructors, and methods that are not shown. 3 In the following Flowershop class, the array flower Inventory contains information about the flowers sold at a flower shop. You will implement two methods in the flowershop class. public class Flowershop 7** An array of the flowers sold at the flower shop, sorted alphabetically by flower name Guaranteed to be nonempty and to contain only non-null entries *] private Flower() flower Inventory *** Returns a copy of Flower) arr in which the array elements have been sorted in order from highest quantity to lowest quantity public Flower() sortByQuantity (Flower arr) { /* implementation not shown public Flower[] sortByQuantity (Flower arr) { /* implementation not shown /** Updates the Flower objects contained in flower Inventory, as described in part (a) Precondition: newInventory has the same flower names in the same positions as flower Inventory. Postcondition: newInventory is unchanged. public void update Inventory (Flower(newInventory) { /* to be implemented in part (a) */ 7** Returns true if the top n flowers by quantity in stock at the flower shop are the same as the top n flowers by quantity in stock in other Inventory, as described in part (b) Precondition: n is less than or equal to the lengths of flowerinventory and otherInventory. Postcondition: flower Inventory and other Inventory are unchanged. 23 public boolean top Same(int n, Flower ) other Inventory) { /* to be implemented in part (b) */ } // There may be instance variables, constructors, and methods that are not shown. 1 (a) Write the Flowershop method updateInventory, which increases the quantities of the flowers in flower Inventory by the quantities of the flowers in the array parameter newInventory. Each quantity of a flower in newInventory is added to the quantity of the corresponding flower in flower Inventory. The arrays flower Inventory and newInventory are the same length and contain the same flower names in the same positions! For example, assume that sunnyFlowers has been declared as a Flowershop object and newFlowers is a Flower array. The array flower Inventory before the call sunnyFlowers.update Inventory (new Flowers) rose" daffodil 225 "tulip" 419 550 The array newFlowers: daffodil 2ee rose se tulip" 150 The array flower Inventory after the call sunnyFlowers.updateInventory (newflowers): The array flower Inventory after the call sunnyFlowers. updateInventory (newFlowers) daffodil 425 rose 660 tulip" 569 Complete method updateInventory ** Updates the Flower objects contained in flower Inventory, as described in part (a) Precondition: newInventory has the same flower names in the same positions as flower Inventory Postcondition: new Inventory is unchanged. public void updateInventory (Flower[] newInventory) B 1 0 10000 Word Limit (b) Write the Flowershop method topleSame, which compares the flowers that appear in the first n positions of flower Inventory with the flowers that appear in the first in positions of other Inventory when both arrays are sorted in decreasing order by quantity in stock. The method returns true if the first n Flower objects in both arrays are the same and appear in the same position in both soned arrays and retums false otherwise. A helper method, sortByQuantity, has been provided. It retums a copy of its Flower [] parameter sorted in decreasing order by quantity in stock For example, assume that sunnyFlowers has been declared as a Flowershop object and that stocke is an array of Flower objects, The array flower Inventory in sunnyFlowers: Mcarnation 50 daffodil 320 Mdaisy 375 "rose" 550 "tulip 419 The array stocke carnation 250 daffodil 220 daisy 508 rose 525 "tulip 318 2:20 Sud S5 SL The method call sunny Flowers. tapNsame(3, stockB) should return false. For sunnyFlowers, the top three flowers by quantity (in order) are rose "tulip" and "daisy. However, for stocke the top three flowers by quantity (in order) are "rose". "daisy", and "tulip" Complete method top Same. You must use sortByQuantity appropriately to receive full credit. /** Returns true if the top n flowers by quantity in stock at the flower shop are the same as the top n flowers by quantity in stock in otherinventory, as described in part (b) Precondition: n is less than or equal to the lengths of flowerinventory and other inventory. Postcondition: flower Inventory and otherInventory are unchanged. public boolean top Same (int n, Flower [] other Inventory) B 1 0 / 10000 Word Limit (c) A programmer would like to add a method called getMostExpensiveFlower, which returns the name of the flower with the highest price. Write a description of how you would change the Flower and FlowerShop classes in order to support this modification, Make sure to include the following in your response. Write the method header for the getkostexpensiveFlower method Identify any new or modified variables, constructors, or methods aside from the getMostExpensiveFlower method. Do not write the program code for this change. Describe for each new or revised variable, constructor, or method, how it would change or be implemented, including visibility and type. You do not need to describe the implementation of the getrostexpensiveFlower method. Do not write the program code for this change

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!