/* * 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 robopractice; import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; /** * * @author jcmtiernan */ public class RoboPractice { /** * @param args the command line arguments */ public static void main(String[] args) //throws FileNotFoundException { final int MAXTEAMS = 150; final int TEAM_NUMBER = 0; final int MEMBER_COUNT = 1; final int FIRST_YEAR = 2; Integer robotTeamNumbers[] = new Integer[MAXTEAMS]; Integer[][] robotTeamInfo = new Integer[MAXTEAMS][3]; String[][][] regionRobotTeams = new String[4][MAXTEAMS][3]; File inputFile = new File("robotteam.dat"); Scanner inFile; // exception handling try { inFile = new Scanner(inputFile); } catch (FileNotFoundException fnf) { System.out.println("Input file was not found. Input will be read from the keyboard."); inFile = new Scanner(System.in); } Scanner input = new Scanner(System.in); int i = 0; int j = 0; boolean isGreaterThanZero = true; Integer tempNumber = 0; System.out.println("Hello and welcome to the Robot Team Manager system."); System.out.println("We need to first get the numbers of all the robot teams to be managed."); System.out.println("Please enter multiple team numbers on one line seperated by spaces. "); System.out.println("When you have finished entering all team numbers, enter a 0 or a negative number to stop."); for (i = 0; (i < MAXTEAMS) && (isGreaterThanZero); i++ ) //do { //System.out.println("Inside the for loop with i = "+i); if (input.hasNextInt()) { //System.out.println("int Input has been entered"); tempNumber = input.nextInt(); } else { //System.out.println("NON int Input has been entered - treat this input as a stop condition"); tempNumber = 0; } if (tempNumber > 0) { //isGreaterThanZero = true; robotTeamNumbers[i] = tempNumber; //System.out.println("You entered "+robotTeamNumbers[i]+" stored at index "+i); } else { isGreaterThanZero = false; i--; } } //while(robotTeamNumbers[i-1] > 0); System.out.println("You entered a total of "+i+" pieces of data"); System.out.println("The array is size "+robotTeamNumbers.length); System.out.println(); for (j = 0; (j < i); j++ ) { //System.out.println("robotTeamNumbers["+j+"] = "+robotTeamNumbers[j]); robotTeamInfo[j][TEAM_NUMBER] = robotTeamNumbers[j]; //System.out.println("Reading team data from file."); robotTeamInfo[j][MEMBER_COUNT] = inFile.nextInt(); robotTeamInfo[j][FIRST_YEAR] = inFile.nextInt(); /* System.out.println("robotTeamInfo[j][MEMBER_COUNT] is "+robotTeamInfo[j][MEMBER_COUNT] +" and robotTeamInfo[j][FIRST_YEAR] "+robotTeamInfo[j][FIRST_YEAR]); */ /* System.out.println("Please enter the number of members on team "+robotTeamInfo[j][0]+": "); robotTeamInfo[j][MEMBER_COUNT] = input.nextInt(); // assume user gives good data System.out.println("Please enter the first year team "+robotTeamInfo[j][0]+" competed in robotics: "); robotTeamInfo[j][FIRST_YEAR] = input.nextInt(); // assume user gives good data */ } System.out.printf("%8s %5s %8s\n","Team #","Mem.","Started"); for (j = 0; (j < i); j++ ) { System.out.printf("%8d %5d %8d\n", robotTeamInfo[j][TEAM_NUMBER], robotTeamInfo[j][MEMBER_COUNT], robotTeamInfo[j][FIRST_YEAR]); // assume user gives good data } i= 1; j= 2; //System.out.println("robotTeamInfo["+j+"]["+i+"] is "+robotTeamInfo[j][i]); } }