Consider the following question which needs to be solved in Java:

You are given voterld (int), voterName (String), voterAge (int), isVoteCasted (boolean), constituency (String) respectively of 4 different voters and you are asked to find out the following:

i) Given a string parameter cons, you have to find the number of voters who belong to that particular constituency. If the number of voters belonging to that constituency is 0, then print “No votes casted”.

ii) Print the voterId of the persons whose age is less than 30 in ascending order. If there are no voters whose age is below 30, then print “No such voters.”

Sample Input:

1008

Aman

29

true

cons1

1003

Saman

43

true

cons1

1004

Kamal

28

false

cons2

1005

Ritu

48

true

cons1

cons1

Output:

3

1004

1008

Explanation:

i) The string parameter passed is cons1(last row) and there are 3 voters who belong to that constituency(voterId: 1003, 1008 & 1005). So the first output is 3.

ii) There are two voters whose age is less than 30(voterId: 1008 & 1004), so they are printed in ascending order.

Kindly solve it in the shortest way possible using collections like ArrayList, etc. You don’t have to use OOP concepts and create multiple classes, etc. Just imagine this question came in a contest and you have 10 mins left… then how will you solve it?