May 14, 2017

Java Technical Question in bayt.com

Ross is an event organizer. He has received data regarding the participation of employees in two different events ( say event One and event Two ). Some employees have participated in only one event and others have participated in both events. Ross now needs to count the number of employees who have taken part in both events. The record received by Ross consist of employee ids, which are unique. Write a program that accepts the employee ids participating in each event ( the first line relates to the first event and the second line relates to the second event). The program should print the number of common employee ids in both the events.

Suppose the following input is given to the program, where each line represents a different event.

1001,1002,1003,1004,1005
1106,1008,1005,1003,1016,1017,1112

Now the common employee ids are 1003 and 1005 so the program should give the output as:2

java source code

import java.util.ArrayList;
import java.util.List;

/**
 * solutions for question one
 */

/**
 * @author shimjith consumerfed
 *
 */
public class EventOrganizer {

private List<Integer> eventOne = null;
private List<Integer> eventTwo = null;
private static int count = 0;

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
EventOrganizer main = new EventOrganizer();
main.getEmployeeDetails();
main.showEmployeeDetails();
main.findEmployeeDetails();
System.out.println("The employee present in both events :"+EventOrganizer.count);

}

// to get employees present in both arrays
private void findEmployeeDetails() {
// TODO Auto-generated method stub
for (int row: eventOne){

if(eventTwo.contains(row)){
count = count +1;
}
}

}

private void showEmployeeDetails() {
// TODO Auto-generated method stub
System.out.println("Employee ids of event one "+eventOne);
System.out.println("Employee ids of event two "+eventTwo);
}

private void getEmployeeDetails() {
// You can use scanner class to get values to event one and two
eventOne = new ArrayList<Integer>();
eventTwo = new ArrayList<Integer>();
eventOne.add(1001);
eventOne.add(1002);
eventOne.add(1003);
eventOne.add(1004);
eventOne.add(1005);
eventTwo.add(1106);
eventTwo.add(1008);
eventTwo.add(1005);
eventTwo.add(1003);
eventTwo.add(1016);;
eventTwo.add(1017);
eventTwo.add(1112);

}

}


out put

No comments:

Post a Comment

Your feedback may help others !!!

Facebook comments