Question 3:
(2 marks)
Write a class named SDrink with the following information:
SDrink
Where:
-code:String
-make:String
-price:double
+SDrink()
+SDrink(code:String, make:String,
price:double)
+getters & setters
+toString():String
Zoom
SDrink() - default constructor
SDrink(code: String, make: String, price: double) - parameterized constructor, which sets values to code, make, and price
getters & setters: write the setters and getters of all the fields
toString():String - return a string format that contains all the information of the SDrink: code,make, price. The price is formatted to two decimal places and the make is uppercase.
Write a class SDrinkList which extends from ArrayList (ArrayList is a collection) with the following information:
SDrinkList
+addSDrink(sdrink :SDrink):void+getSDrinkByMake(value:String):int
+getSDrink WithMinPrice():SDrink
Where:
addSDrink(sdrink: SDrink): void - add a new SDrink to the collection
getSDrinkByMake(value: String): int - return the number of SDrinks whose make equals to value (not case
sensitive). If not found matching data, return 0.
getSDrinkWithMinPrice(): SDrink - return the SDrink with the lowest price (suppose in the list only one SDrink with the lowest price).
Hints: to declare the SDrinkList class, you can use the following statement:
+ 100%
Close