Professional Documents
Culture Documents
(3 Marks) Write A Class Cala With The Following Information: Cala
(3 Marks) Write A Class Cala With The Following Information: Cala
Cala Where:
-owner:String getOwner():String – return owner.
-price:int getPrice():int – return price.
+Cala () setOwner(owner:String): void – update owner.
+Cala (owner:String, price:int) setPrice(price:int): void – update price.
+getOwner():String
+getPrice():int
+setOwner(owner:String):void
+setPrice(price:int):void
The interface ICala below is already compiled and given in byte code format, thus you can use it without
creating ICala.java file.
import java.util.List;
public interface ICala {
public int f1(List<Cala> t);
public void f2(List<Cala> t);
public void f3(List<Cala> t);
}
Write a class MyCala, which implements the interface ICala. The class MyCala implements methods f1, f2
and f3 in ICala as below (you can add other functions in MyCala class):
f1: Suppose all owners contain at least 2 characters. Count and return number of elements
with owner having 2nd character (i.e. owner.charAt(1)) is a digit.
f2: Remove the second element having maximum price (do nothing if only one max element
in the list).
f3: Suppose all owners contain at least 2 characters. Sort the list t ascendingly by the 2nd
character of owner.
When running, the program will add some data to the list. Sample output might look something like:
Add how many elements: 0 Add how many elements: 0
Enter TC(1-f1;2-f2;3-f3): 1 Enter TC(1-f1;2-f2;3-f3): 2
The list before running f1: The list before running f2:
(A1B,5) (BC2,4) (CT,3) (D3X,4) (2E1,5) (FY4,2) (A,4) (C,3) (B,7) (D,3) (E,7) (F,5)
OUTPUT: OUTPUT:
2 (A,4) (C,3) (B,7) (D,3) (F,5)