I am trying to write a program that organizes results from a tournament of computer games using bots. I want to do interesting things with the data like rank the bots on the results of each map, results of all the maps, and on their averages ... and so on
I am new to arrays so maybe arrays are a bad choice for this, so please correct me if I'm wrong.
So each tournament consists of 5 maps, there are 5 players in each map ("daemia", "xaero", "ezflow", "slash", "doom").
I have used two classes: Bot.java - has methods to retrieve the bots frag (aka "kill") data, like average frags, total frags and also the bots name.
RankBotsVariant.java - has the main method in which I create 5 Bot objects and put their scores in after the tournament (the Bot
constructor has space for 5 int results and a String name).
I am having trouble ranking the bots in terms of their results maybe you can help me or give some advice
//RankBotsVariant.java //imports Bot objects from Bot.class import java.text.DecimalFormat; public class RankBotsVariant { public static void main (String[] args) { Bot bot1 = new Bot ("Daemia", 11, 4, 6, 3, 5); Bot bot2 = new Bot ("Xaero", 5, 5, 6, 9, 10); Bot bot3 = new Bot ("EZfl0w", 5, 8, 3, 6, 9); Bot bot4 = new Bot ("Slash", 6, 5, 8, 11, 4); Bot bot5 = new Bot ("D00m", 5, 3, 7, 5, 19); //print fragsAllMaps System.out.println ("***Total Frags -All Maps***"); System.out.println ("\tDAEMIA: " + bot1.getFragsAllMaps()); System.out.println ("\tXAERO: " + "\t" + bot2.getFragsAllMaps()); System.out.println ("\tezFL0W: " + bot3.getFragsAllMaps()); System.out.println ("\tSLASH: " + "\t" + bot4.getFragsAllMaps()); System.out.println ("\tDOOM: " + "\t" + bot5.getFragsAllMaps()); //best average System.out.println ("***Average Frag-rate - Over All Maps***"); System.out.println ("\tDAEMIA: " + bot1.getAvgFrags()); System.out.println ("\tXAERO: " + "\t" + bot2.getAvgFrags()); System.out.println ("\tezFL0W: " + bot3.getAvgFrags()); System.out.println ("\tSLASH: " + "\t" + bot4.getAvgFrags()); System.out.println ("\tDOOM: " + "\t" + bot5.getAvgFrags()); //prints the winner of each map: System.out.println ("*******Winner Of Each Map*********"); String [] maps = {"LostWorld", "DM18", "Shibam", "TheBouncyMap", "Hearth"}; int [] data = {bot1.getfm1(), bot2.getfm1(), bot3.getfm1(), bot4.getfm1(),bot5.getfm1()}; for (int map = 0; map < maps.length; map++) { System.out.println ("The winner of " + maps[map] + " was "); int largest = data[0]; for (int i = 0; i < data.length; i++) { if (data[i] > largest) { largest = data[i]; } } System.out.println ( + largest); } } }//Bot.java //Holds get methods for frag data used in the RankBotsVarint class. import java.util.Arrays; public class Bot { public int fm1, fm2, fm3, fm4, fm5; //frags map 1 , etc.. public int fragsfm1, fragsfm2, fragsfm3, fragsfm4, fragsfm5; public int fragsAllMaps = 0; public double avgFrags = 0; public String botName, winner, victor; private final int MAPS = 5; public Bot (String alias, int m1, int m2, int m3, int m4, int m5) { botName = alias; fm1 = m1; fm2 = m2; fm3 = m3; fm4 = m4; fm5 = m5; } public int getFragsAllMaps () { fragsAllMaps = fm1 + fm2 + fm3 + fm4 + fm5; return fragsAllMaps; } public String getBotName () { return botName; } public double getAvgFrags () { avgFrags = (fm1 + fm2 + fm3 + fm4 + fm5) / (double)MAPS; return avgFrags; } public int getfm1 () { fragsfm1 = fm1; return fragsfm1; } public int getfm2 () { fragsfm2 = fm2; return fragsfm2; } public int getfm3 () { fragsfm3 = fm3; return fragsfm3; } public int getfm4 () { fragsfm4 = fm4; return fragsfm4; } public int getfm5 () { fragsfm5 = fm5; return fragsfm5; } }
--- Update ---
What i'm having trouble with is the halfway down the RankBotsVariant class where it saysI cant get it to print the winners name or rank all the bots from 1-5 which is what i'd really like to do.//prints the winner of each map: