Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions src/main/java/ru/urfu/Data.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package ru.urfu;
import java.util.*;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;

public class Data {
public List<Player> records = new ArrayList<>();

public void load_data() {
try (BufferedReader br = new BufferedReader(new FileReader("src/main/resources/fakePlayers.csv"))) {
String line = br.readLine();
while ((line = br.readLine()) != null) {
String[] values = line.split(";");
records.add(new Player(values));
}
} catch (IOException e) {
System.err.println("Error reading CSV file: " + e.getMessage());
}
}
}
92 changes: 83 additions & 9 deletions src/main/java/ru/urfu/Main.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,91 @@
package ru.urfu;
import ru.urfu.resolver.IResolver;
import java.util.HashMap;

//TIP To <b>Run</b> code, press <shortcut actionId="Run"/> or
// click the <icon src="AllIcons.Actions.Execute"/> icon in the gutter.
public class Main {
public static void main(String[] args) {
//TIP Press <shortcut actionId="ShowIntentionActions"/> with your caret at the highlighted text
// to see how GIGA IDE suggests fixing it.
System.out.printf("Hello and welcome!");
Resolver res = new Resolver();
res.init();
System.out.println(res.getCountWithoutAgency());
System.out.println(res.getMaxDefenderGoalsCount());
System.out.println(res.getTheExpensiveGermanPlayerPosition());
System.out.println(res.getTheRudestTeam());
}
}

class Resolver implements IResolver {
Data data = new Data();

public void init() {
data.load_data();
}

public int getCountWithoutAgency() {
int ans = 0;
for (Player player : data.records) {
if (player.agency == "") {
ans += 1;
}
}
return ans;
}

public int getMaxDefenderGoalsCount() {
int ans = -1;
for (Player player : data.records) {
if (player.position.equals("DEFENDER")) {
ans = Math.max(ans, player.goals);
}
}
return ans;
}

for (int i = 1; i <= 5; i++) {
//TIP Press <shortcut actionId="Debug"/> to start debugging your code. We have set one <icon src="AllIcons.Debugger.Db_set_breakpoint"/> breakpoint
// for you, but you can always add more by pressing <shortcut actionId="ToggleLineBreakpoint"/>.
System.out.println("i = " + i);
public String getTheExpensiveGermanPlayerPosition() {
String ans = "";
int max_cost = -1;
for (Player player : data.records) {
if (player.nationality.equals("Germany") && player.transfer_cost > max_cost) {
ans = player.position;
max_cost = player.transfer_cost;
}
}
switch (ans) {
case "MIDFIELD":
ans = "Полузащитник";
break;
case "DEFENDER":
ans = "Защитник";
break;
case "FORWARD":
ans = "Нападающий";
break;
case "GOALKEEPER":
ans = "Вратарь";
break;
}
return ans;
}

public String getTheRudestTeam() {
HashMap<String, Integer> cnt = new HashMap<>();
HashMap<String, Integer> deletes = new HashMap<>();
float max_rudeness = -1;
String ans = "";
for (Player player : data.records) {
if (cnt.get(player.team) == null) {
cnt.put(player.team, 0);
deletes.put(player.team, 0);
}
cnt.put(player.team, cnt.get(player.team) + 1);
deletes.put(player.team, deletes.get(player.team) + player.red_cards);
}
for (String team : cnt.keySet()) {
float rudeness = (float)deletes.get(team) / cnt.get(team);
if (rudeness > max_rudeness) {
max_rudeness = rudeness;
ans = team;
}
}
return ans;
}
}
31 changes: 31 additions & 0 deletions src/main/java/ru/urfu/Player.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package ru.urfu;

public class Player {
public String name;
public String team;
public String city;
public String position;
public String nationality;
public String agency;
public int transfer_cost;
public int participations;
public int goals;
public int assists;
public int yellow_cards;
public int red_cards;

Player (String[] args) {
name = args[0];
team = args[1];
city = args[2];
position = args[3];
nationality = args[4];
agency = args[5];
transfer_cost = Integer.parseInt(args[6]);
participations = Integer.parseInt(args[7]);
goals = Integer.parseInt(args[8]);
assists = Integer.parseInt(args[9]);
yellow_cards = Integer.parseInt(args[10]);
red_cards = Integer.parseInt(args[11]);
}
}