for this program i get an input from a file then i massage the data and write back out to a new file. IT worked good for having a file with data and changing it to represent something that is more usable.
package teamleader; public class TeamLeader { public static void main(String[] args) { //initialization int team; int totalEmployess = 0; int totalTeams = 0; int average; int index; int teamCount [] = new int [100]; String PTL[] = new String[100]; String employee; // in and out from files InputFile in = new InputFile("in.txt"); OutputFile out = new OutputFile("out.txt"); // for a loop that initilized the value of array for(index=1;index<8;index++) { teamCount[index] = 0; PTL[index] = ""; index = index + 1; } // end of the for loop System.out.println("Program Started..."); while (!in.eof()) { employee = in.readWord(); // reads employee team = in.readInt(); // reads Team teamCount[team] = teamCount[team] +1; if(teamCount[team] <= 3) //counts to see team { PTL[team] = employee; }// end of the if statement totalEmployess = totalEmployess +1; }// end of the while loop for(index=1;index<100;index++) { if (teamCount[index] > 0) { out.writeString("Team_Number:"); out.writeInt(index); out.writeString("Team_Leader"); out.writeWord(PTL[index]); out.writeString("Total_Members"); out.writeInt(teamCount[index]); totalTeams = totalTeams + 1; }// end of the if statment } // end of the for loop out.close(); // closes the file average = AVG( totalEmployess, totalTeams ); System.out.println(" Total Teams:" + totalTeams + " Average Team Size:" + average); System.out.println("Team Leader Completed Successfully. "); } // end of the main // always set your functions outside the main public static int AVG(int total, int divisor) // AVG Function { int average = total/divisor; return average; }// end of the AVG function } // end of team leader class
I always had a passion for the field of STEM (Science, Technology, Engineering, and Math) and I knew I wanted to do something to make a difference in the world. I just didn’t know where to start. I was an immigrant in a new country, grew up in a tough environment, and wasn’t sure how… Read More