
Could you please help me to write a program for a simple team leader?

Please clarify your problem. Which type of program you want to create in java? Please specify this.

A company has a file with records of employees name and team number. Each team has 5 members. The 3rd member of each team is the team leader. Write a program to read the records from this file and display the names of the teamleaders on the screen

We have took 2 teams with 5 members each. Depend of which we have created the following code:
import java.io.*;
import java.util.*;
public class TeamLeader{
public static void main(String []args) throws Exception{
FileInputStream fstream = new FileInputStream("leader.txt");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String strLine;
ArrayList list=new ArrayList();
while((strLine = br.readLine()) != null){
list.add(strLine);
}
String team1[]=new String[5];
String team2[]=new String[5];
Iterator itr;
int k=0,p=0;
for (itr=list.iterator(); itr.hasNext(); ){
String str=itr.next().toString();
String [] splitSt =str.split(" ");
String name="",num="";
for (int i = 0 ; i < splitSt.length ; i++) {
name=splitSt[0];
num=splitSt[1];
}
if(Integer.parseInt(num)==1){
team1[k]=name;
k++;
}
if(Integer.parseInt(num)==2){
team2[p]=name;
p++;
}
}
System.out.println("Team Leader of Team 1: "+team1[2]);
System.out.println("Team Leader of Team 2: "+team2[2]);
}
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.