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.”
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.
I can solve it by creating a class named Voter having those 5 attributes and then creating an object array of size 4 like Voter v=new Voter. But is there any easy way to store the data and solve it using collections like Arraylist. Suppose this program came in a competitive programming contest, what will be the shortest and easiest way to solve it?