mili
unknown
plain_text
3 years ago
6.9 kB
5
Indexable
public static String[] generate_word_cloud(int Difficulty, Question[] questions){ Question[] temp_questions = questions; String[] temp_word_cloud = new String[15]; for (int i = 0; i < 15; i++) { int random_question = randomInt(0, temp_questions.length-1); int random_key_word = randomInt(0, temp_questions[random_question].getKeyWords().length-1); String key_word = temp_questions[random_question].getKeyWords()[random_key_word]; boolean flag = true; for (int j = 0; j < key_word.length(); j++) { if (Character.isDigit(key_word.charAt(j))) { flag = false; } } if(!isStringInArray(key_word, temp_word_cloud) && !key_word.equals("") && temp_questions[random_question].getDifficulty() == Difficulty && temp_questions[random_question].getIsAsked() == false && flag) { temp_word_cloud[i] = key_word; } else { i--; } } return temp_word_cloud; } public static int getIndexOfArray(String word,String[] array) { for (int i = 0; i < array.length; i++) { if(word.equals(array[i])) { return i; } } return -1; } public static int get_money_won(int i) { int money = -1; switch (i) { case 1: money = 20000; break; case 2: money = 100000; break; case 3: money = 250000; break; case 4: money = 500000; break; case 5: money = 1000000; break; } return money; } public static int get_money_tier(int i) { int money = -1; switch (i) { case 1: case 2: money = 0; break; case 3: case 4: money = 100000; break; case 5: money = 500000; break; } return money; } public static void print_statics(String[] statics, Question[] questions, Participant[] participants) { //the most succesfull contestant String[] contestants = new String[100]; int last_int_1 = 0; int[] correct_answer_number = new int[100]; int[] ages = new int[100]; //the most correctly and badly answered category String[] categories = new String[100]; int last_int_2 = 0; int[] correctly_answered = new int[100]; int[] badly_answered = new int[100]; //correct answer number per ages int under_30_total = 0; int under_30_num = 0; double under_30_avg = 0; int higher_50_total = 0; int higher_50_num = 0; double higher_50_avg = 0; int between_30_50_total = 0; int between_30_50_num = 0; double between_30_50_avg = 0; //the city that has the most contestant number String[] cities = new String[100]; int last_int_4 = 0; int[] contestant_number = new int[100]; for (int i = 0; i < statics.length; i++) { String[] round_static = statics[i].split("#"); int question_id = Integer.valueOf(round_static[0]); int contestant_id = Integer.valueOf(round_static[1]); int isAnsweredCorrectly = Integer.valueOf(round_static[2]); String contestant = participants[contestant_id].getName(); String city = participants[contestant_id].getAdress().split(";")[3]; int birth_year = Integer.valueOf(participants[contestant_id].getBirthDate().substring(6)); int age = 2022 - birth_year; String category = questions[question_id].getCategory(); //counting contestant number per city if(isStringInArray(city, cities) && !isStringInArray(contestant, contestants)) { int index = getIndexOfArray(city, cities); contestant_number[index] ++; } else if(!isStringInArray(city, cities)){ cities[last_int_4] = city; contestant_number[last_int_4] ++; last_int_4++; } //counting contestants correct answers if (!isStringInArray(contestant, contestants)) { contestants[last_int_1] = contestant; ages[last_int_1] = age; if (isAnsweredCorrectly == 1) { correct_answer_number[last_int_1] ++; } last_int_1++; } else { if (isAnsweredCorrectly == 1) { int index = getIndexOfArray(contestant, contestants); correct_answer_number[index] ++; } } //counting correct and wrong answers per category if(isStringInArray(category, categories)) { int index = getIndexOfArray(category, categories); if (isAnsweredCorrectly == 1) { correctly_answered[index] ++; } else { badly_answered[index] ++; } } else{ categories[last_int_2] = category; if (isAnsweredCorrectly == 1) { correctly_answered[last_int_2] ++; } else { badly_answered[last_int_2] ++; } last_int_2++; } } //determining the most successfull contestant int max = -1; int index_1 = 0; for (int j = 0; j < correct_answer_number.length; j++) { if (correct_answer_number[j] > max) { max = correct_answer_number[j]; index_1 = j; } } //determining the most correctly answered category max = -1; int index_2 = 0; for (int j = 0; j < correctly_answered.length; j++) { if (correctly_answered[j] > max) { max = correctly_answered[j]; index_2 = j; } } //determining the most badly answered category max = -1; int index_3 = 0; for (int j = 0; j < badly_answered.length; j++) { if (badly_answered[j] > max) { max = badly_answered[j]; index_3 = j; } } //determining the city that has the most highest number of participants max = -1; int index_4 = 0; for (int j = 0; j < contestant_number.length; j++) { if (contestant_number[j] > max) { max = contestant_number[j]; index_4 = j; } } //determining average correct answer per ages for (int i = 0; i < correct_answer_number.length; i++) { if (ages[i] > 50) { higher_50_num ++; higher_50_total += correct_answer_number[i]; } else if (ages[i] <= 50 && ages[i] > 30) { between_30_50_num ++; between_30_50_total += correct_answer_number[i]; } else if(ages[i] <= 30 && ages[i] > 0){ under_30_num ++; under_30_total += correct_answer_number[i]; } } under_30_avg = (double) under_30_total/under_30_num; String str_u3a = String.valueOf(under_30_avg).substring(0, 3); between_30_50_avg = (double) between_30_50_total/between_30_50_num; String str_b35a = String.valueOf(between_30_50_avg).substring(0, 3); higher_50_avg = (double) higher_50_total/higher_50_num; String str_h5a = String.valueOf(higher_50_avg).substring(0, 3); System.out.println("The most successful contestant: " + contestants[index_1]); System.out.println("The category with the most correctly answered: " + categories[index_2]); System.out.println("The category with the most badly answered: " + categories[index_3]); System.out.println("Age<=30 " + str_u3a + " 30<Age<=50 " + str_b35a + " Age>50 " + str_h5a); System.out.println("The city with the highest number of participants: " + cities[index_4]); } }
Editor is loading...