Assume we have Dessert.java whcih private String flavor has private double sweetness in it. Store.java This will be the class that stores the data for the dessert store. We are assuming that a store can sell all kinds of dessert. Variables: String name – name of the store. ArrayList desserts – an ArrayList of type Dessert Constructor(s): • A constructor that only takes in name and creates an empty ArrayList of type Dessert. Methods: • addDessert o This method should take in a valid Dessert object and add it to the back of the ArrayList. o This method should not return anything. o This method should run in O(1) time. • removeDessert o This method should take in a valid Dessert object and remove the first instance of it from the ArrayList. o Return the object that is being removed or null if the dessert is not found. o Use equals when identifying if the object in the ArrayList is the same as the passed in Dessert object. o This method should run in O(n) time. • findDessert o This method should take in a valid Dessert object and find/return the dessert that has the same sweetness and flavor. o If a dessert with the same sweetness and flavor is not found in the Store, return null. o This method should run in O(log n) time. o Assume the ArrayList has unique dessert items and is sorted in ascending order based on sweetness and flavor. • sortStore o This method should sort the ArrayList in ascending order based on sweetness and flavor. o This method should run in O(n2) time worst and best case. • checkStore o This method should take in a valid Dessert object and return the number of desserts in the store that is greater or equal to the Dessert passed in. o This method should run in O(n) time. • If necessary, add getters and setters for the variables in the class.
Assume we have Dessert.java whcih private String flavor has private double sweetness in it.
Store.java
This will be the class that stores the data for the dessert store. We are assuming that a store can sell all kinds of dessert.
Variables:
-
String name – name of the store.
-
ArrayList desserts – an ArrayList of type Dessert
Constructor(s):
• A constructor that only takes in name and creates an empty ArrayList of type Dessert. Methods:
• addDessert
o This method should take in a valid Dessert object and add it to the back of the ArrayList. o This method should not return anything.
o This method should run in O(1) time.
• removeDessert
o This method should take in a valid Dessert object and remove the first instance of it from the ArrayList.
o Return the object that is being removed or null if the dessert is not found.
o Use equals when identifying if the object in the ArrayList is the same as the passed in Dessert object.
o This method should run in O(n) time.
• findDessert
o This method should take in a valid Dessert object and find/return the dessert that has the same sweetness and flavor.
o If a dessert with the same sweetness and flavor is not found in the Store, return null. o This method should run in O(log n) time.
o Assume the ArrayList has unique dessert items and is sorted in ascending order based
on sweetness and flavor.
• sortStore
o This method should sort the ArrayList in ascending order based on sweetness and
flavor.
o This method should run in O(n2) time worst and best case.
• checkStore
o This method should take in a valid Dessert object and return the number of desserts in
the store that is greater or equal to the Dessert passed in. o This method should run in O(n) time.
• If necessary, add getters and setters for the variables in the class.
Trending now
This is a popular solution!
Step by step
Solved in 2 steps