feat(04-chess-stats): Добавлено задание
This commit is contained in:
43
labs/04-chess-stats/app/build.gradle.kts
Normal file
43
labs/04-chess-stats/app/build.gradle.kts
Normal file
@ -0,0 +1,43 @@
|
||||
/*
|
||||
* This file was generated by the Gradle 'init' task.
|
||||
*
|
||||
* This generated file contains a sample Java application project to get you started.
|
||||
* For more details on building Java & JVM projects, please refer to https://docs.gradle.org/8.10.2/userguide/building_java_projects.html in the Gradle documentation.
|
||||
*/
|
||||
|
||||
plugins {
|
||||
// Apply the application plugin to add support for building a CLI application in Java.
|
||||
application
|
||||
}
|
||||
|
||||
repositories {
|
||||
// Use Maven Central for resolving dependencies.
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
// This dependency is used by the application.
|
||||
implementation(libs.guava)
|
||||
}
|
||||
|
||||
// Apply a specific Java toolchain to ease working on different environments.
|
||||
java {
|
||||
toolchain {
|
||||
languageVersion = JavaLanguageVersion.of(23)
|
||||
}
|
||||
}
|
||||
|
||||
application {
|
||||
// Define the main class for the application.
|
||||
mainClass = "ru.mrqiz.chess.App"
|
||||
}
|
||||
|
||||
tasks.named<Test>("test") {
|
||||
// Use JUnit Platform for unit tests.
|
||||
useJUnitPlatform()
|
||||
}
|
||||
|
||||
tasks.named<JavaExec>("run") {
|
||||
standardInput = System.`in`
|
||||
}
|
||||
|
||||
@ -0,0 +1,47 @@
|
||||
package ru.mrqiz.chess;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class App {
|
||||
private static String fileNameToPlayers(String fileName) {
|
||||
return Paths.get(fileName).getFileName().toString().replace(".txt", "");
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
if (args.length < 1) {
|
||||
System.out.println("Нет имени файла");
|
||||
return;
|
||||
}
|
||||
|
||||
String filePath = args[0];
|
||||
|
||||
try (BufferedReader br = new BufferedReader(new FileReader(filePath))) {
|
||||
List<String> lines = new ArrayList<>();
|
||||
String line;
|
||||
|
||||
while ((line = br.readLine()) != null) {
|
||||
lines.add(line);
|
||||
}
|
||||
|
||||
System.out.printf("Игроки: %s\n", fileNameToPlayers(filePath));
|
||||
|
||||
for (int i = 0; i < lines.size() - 1; i++) {
|
||||
System.out.printf("%d. %s\n", i + 1, lines.get(i));
|
||||
}
|
||||
|
||||
if (!lines.isEmpty()) {
|
||||
System.out.println("Результат: " + lines.get(lines.size() - 1));
|
||||
}
|
||||
|
||||
} catch (IOException e) {
|
||||
System.out.println("Не удалось прочесть файл");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user