/* * 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.io.PrintWriter; import java.util.Scanner; /** * * @author jcmtiernan */ public class RobotPracticeAllFile { public static void main(String[] args) throws FileNotFoundException { final int MAXTEAMS = 5; 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]; double [][] teamCosts = new double[MAXTEAMS][]; 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("teamcostragged.txt"); 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 non-number 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; int numCosts = 0; boolean isGreaterThanZero = true; // use invalid data to stop Integer tempNumber = 0; //System.out.println("Enter the costs for the robot team"); for (i = 0; (i 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 } */ //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++ ) { for (int n = 0; n < teamCosts[j].length; n++) { System.out.println("Row "+j+" Column "+n+" value is "+teamCosts[j][n]); } /* System.out.printf("%8d %5d %8d\n", robotTeamInfo[j][TEAM_NUMBER], robotTeamInfo[j][MEMBER_COUNT], robotTeamInfo[j][FIRST_YEAR]); // assume user gives good data */ } PrintWriter outFile = new PrintWriter("arrayoutput.txt"); for (j = 0; (j < i); j++ ) { for (int n = 0; n < teamCosts[j].length; n++) { outFile.printf("%9.2f\t",teamCosts[j][n]); } outFile.println(); } outFile.close(); //System.out.println("robotTeamInfo["+j+"]["+i+"] is "+robotTeamInfo[j][i]); } }