You are on page 1of 1

(3 marks) Write a class Cala with the following information:

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)

Add how many elements: 0


Enter TC(1-f1;2-f2;3-f3): 3
The list before running f3:
(A8,1) (B1,2) (C7,3) (D2,4) (E6,5) (F3,6)
OUTPUT:
(B1,2) (D2,4) (F3,6) (E6,5) (C7,3) (A8,1)

You might also like