/* * 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 robotpracticeallfile; import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; /** * * @author jcmtiernan */ public class RobotPracticeAllFile { 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]; Scanner input = new Scanner(System.in); System.out.println("Hello and welcome to the Robot Team Manager system."); System.out.println("Your input data should be in a file. Please enter the name of the file here: "); String inputFileName = input.next(); File inputFile = new File(inputFileName); 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."); System.out.println("Enter a team number followed by a space then the number of team members " + "followed by a space then the year the team started followed by a space or the enter key."); System.out.println("Enter a 0 for the team number in order to stop."); System.out.println("Team# MemberCount FirstYear : "); inFile = new Scanner(System.in); // does not handle invalid data from the keyboard } int i = 0; int j = 0; boolean isGreaterThanZero = true; Integer tempNumber = 0; /* 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."); */ //while(robotTeamNumbers[i-1] > 0); System.out.println("The array is size "+robotTeamNumbers.length); System.out.println(); j = 0; while( inFile.hasNextInt() ) { //System.out.println("robotTeamNumbers["+j+"] = "+robotTeamNumbers[j]); robotTeamInfo[j][TEAM_NUMBER] = inFile.nextInt(); //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 */ } i = j; System.out.println("The file had total of "+i+" lines of 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]); } }