Today's classwork focuses on more practice with classes and ArrayList.
Snarf the 10_chess_cps006_spring10 project to get started.
Here is the code for today.
Consider the class Player to represent a chess player. Chess is a board game played by two people. A Player stores information about a chess player including their name, their rank (a number that is larger means the player is higher ranked, and a low number below 100 means they are unranked.), and their grade in school, 1-13, with 13 meaning they are out of high school. There is no grade higher than 13.
Here is the code in the main method to test several methods in the class. Note there are some additional lines of code to print pairings for the tournament.
public static void main(String[] args) throws FileNotFoundException { String inputFileName = "chessdata.txt"; FileReader reader = new FileReader(inputFileName); Scanner in = new Scanner(reader); ChessTournament Feb8 = new ChessTournament(in); System.out.println("Grade 5 highest player is: " + Feb8.highestPlayerInGrade(5)); System.out.println("Grade 9 highest player is: " + Feb8.highestPlayerInGrade(9)); System.out.println("Grade 4 highest player is: " + Feb8.highestPlayerInGrade(4)); System.out.println("Number players with rank between 400 and 700 is: " + Feb8.numberPlayersBetween(400, 700)); ArrayListHere is the data file chessdata.txt.highRankPlayers = Feb8.playersWithRankGreater(600); System.out.println("Name of players rank greater than 600: "); for (String name: highRankPlayers) { System.out.print(name + " "); } System.out.println(" "); System.out.println(" "); System.out.println("Print Pairings"); System.out.println(" "); ArrayList players = Feb8.playersInGradeRange(0, 3); Feb8.printPairings("Grades K-3 Pairings", players); players = Feb8.playersInGradeRange(4, 8); Feb8.printPairings("Grades 4-8 Pairings", players); players = Feb8.playersInGradeRange(9, 13); Feb8.printPairings("Grades 9-13 Pairings", players); }
Narten 680 5 Lapidus 956 5 Ward 550 5 Smith 430 3 Yee 800 4 Parker 0 8 Kumar 1 4 Guilak 758 5 Jones 834 9 Wilson 1012 11 Gorin 764 2 Huang 632 1 Liang 943 10 Hellinga 843 2Here is the corresponding output when the program is run with this data file.
Grade 5 highest player is: Lapidus Grade 9 highest player is: Jones Grade 4 highest player is: Yee Number players with rank between 400 and 700 is: 4 Name of players rank greater than 600: Narten Lapidus Yee Guilak Jones Wilson Gorin Huang Liang Hellinga Print Pairings Grades K-3 Pairings ======== Smith Hellinga Huang Gorin Grades 4-8 Pairings ======== Parker Lapidus Kumar Yee Ward Guilak Narten BYE Grades 9-13 Pairings ======== Jones Wilson Liang BYE
Note that the Scanner input is already bound to a file in main. The file is in the following format. Each line in the file has the name of a player (containing no blanks), the rank of the player as an integer and the grade of a player as an integer.
Complete the constructor for the ChessTournament. (hint: what do you need to construct with new?)
Hint: Use Collections.sort(NAMEOFARRAYLIST) to sort an ArrayList of type Integer.
You should test your program out with another data file you create.
When you are satisfied that you have completed the problem above, you should submit your project through Eclipse using assignment name Class10-Feb23. A submission is not considered complete unless it includes all the Java code for the project (both what you have written and the code provided when you downloaded the project) and a README file.