/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package seventhfall16oct25; import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; /** * * @author jcmtiernan */ public class SeventhFall16Oct25 { /** * @param args the command line arguments */ public static void main(String[] args) { Scanner input = new Scanner(System.in); final int MAXTEAMS = 100; File inputData = new File("TeamsRPQPSeventhOct25"); Scanner inFile; try { inFile = new Scanner(inputData); } catch (FileNotFoundException fnf) { inFile = new Scanner(System.in); System.out.println("Can't find input file"); System.out.println(); System.out.println("Please enter an FTC team number followed by the RP, the QP," + " and then the team name. Separate these with a space. \n" + " Enter -1 for the team number if you are finished entering teams."); } int[] teams = new int[MAXTEAMS]; teams[0] = 4001; teams[1] = 9687; teams[7] = 3214; teams[8] = 987; teams[4] = 1276; teams[5] = 6748; teams[6] = 3715; teams[9] = 887; String[] teamNames =new String[MAXTEAMS]; teamNames[0] = "Robotic Cows of Death"; teamNames[1] = "Corncobs"; teamNames[7] = "Ratchet and Clank"; teamNames[8] = "Big Hero 987"; teamNames[4] = "People"; teamNames[5] = "Pandemonium"; teamNames[6] = "Orozco's Army"; teamNames[9] = "TS"; int[] teamsRP = new int[MAXTEAMS]; int[] teamsQP = new int[MAXTEAMS]; // Modify program to read in team names and numbers int done = 0; for(int i = 0; (i < MAXTEAMS) && (done != -1) && (inFile.hasNextInt()); i++) { done = inFile.nextInt(); if (done != -1) { //System.out.println("In loop to read from file"); teams[i] = done; teamsRP[i] = inFile.nextInt(); teamsQP[i] = inFile.nextInt(); teamNames[i] = inFile.nextLine(); while (teamNames[i].charAt(0) == ' ') { teamNames[i] = teamNames[i].substring(1); //System.out.println("Removing blank in name["+i+"]"); } } } // Print matching team numbers and names // *** print team RP and QP for (int index = 0; index < teams.length ; index++) { if (teams[index] > 0) { System.out.print("At index ["+index+"] "); } printTeamBanner(teams[index],teamNames[index],teamsRP[index],teamsQP[index]); } // *** Find the highest ranked team and print it int highestIndex = findHighestTeam(teamsRP, teamsQP); System.out.println("The highest ranked team is team "+teams[highestIndex]); } public static int findHighestTeam(int[] RP, int[] QP) { /* Algorithm to find the highest ranked team by Rp then QP Declare variables for highRP, highQP, highIndex */ int highRP = -1; int highQP = -1; int highIndex = 0; /* Loop through the RP array */ for (int i = 0; i < RP.length; i++) { if (RP[i] > highRP) //(RP[i] > RP[highIndex]) // if ((RP[i] > highRP) || ((RP[i] == highRP) && (QP[i] > highQP))) { highRP = RP[i]; highQP = QP[i]; highIndex = i; } else if ((RP[i] == highRP) && (QP[i] > highQP)) { highRP = RP[i]; highQP = QP[i]; highIndex = i; } } return highIndex; } public static void printTeamBanner(int teamNum, String teamName, int RP, int QP) { if ((teamNum > 0) && (teamNum < 20000)) { System.out.println("Team number is "+teamNum +" and team name is "+teamName +" with ranking points of "+ RP +" and qualifying points of "+QP); } } }