Inital commit
This commit is contained in:
commit
33c91a809c
29
.gitignore
vendored
Normal file
29
.gitignore
vendored
Normal file
@ -0,0 +1,29 @@
|
||||
### IntelliJ IDEA ###
|
||||
out/
|
||||
!**/src/main/**/out/
|
||||
!**/src/test/**/out/
|
||||
|
||||
### Eclipse ###
|
||||
.apt_generated
|
||||
.classpath
|
||||
.factorypath
|
||||
.project
|
||||
.settings
|
||||
.springBeans
|
||||
.sts4-cache
|
||||
bin/
|
||||
!**/src/main/**/bin/
|
||||
!**/src/test/**/bin/
|
||||
|
||||
### NetBeans ###
|
||||
/nbproject/private/
|
||||
/nbbuild/
|
||||
/dist/
|
||||
/nbdist/
|
||||
/.nb-gradle/
|
||||
|
||||
### VS Code ###
|
||||
.vscode/
|
||||
|
||||
### Mac OS ###
|
||||
.DS_Store
|
8
.idea/.gitignore
vendored
Normal file
8
.idea/.gitignore
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# Editor-based HTTP Client requests
|
||||
/httpRequests/
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
6
.idea/misc.xml
Normal file
6
.idea/misc.xml
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_21" default="true" project-jdk-name="openjdk-21" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
8
.idea/modules.xml
Normal file
8
.idea/modules.xml
Normal file
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/Paradygmaty_Programowania_2.iml" filepath="$PROJECT_DIR$/Paradygmaty_Programowania_2.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
11
Paradygmaty_Programowania_2.iml
Normal file
11
Paradygmaty_Programowania_2.iml
Normal file
@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
20
src/BiConsumerType.java
Normal file
20
src/BiConsumerType.java
Normal file
@ -0,0 +1,20 @@
|
||||
import java.util.Arrays;
|
||||
import java.util.function.BiConsumer;
|
||||
|
||||
public class BiConsumerType {
|
||||
public BiConsumer<int[], int[]> goalsOnTheSameTime() {
|
||||
return (i,k) -> {
|
||||
if (i.length != k.length) {
|
||||
System.out.println("False");
|
||||
} else {
|
||||
for (int j = 0; j < i.length; j++) {
|
||||
if (i[j] != k[j]) {
|
||||
System.out.println("False");
|
||||
return;
|
||||
}
|
||||
}
|
||||
System.out.println("True");
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
8
src/BiFunctionType.java
Normal file
8
src/BiFunctionType.java
Normal file
@ -0,0 +1,8 @@
|
||||
import java.util.Arrays;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
public class BiFunctionType {
|
||||
public BiFunction<int[], int[], Integer> sumOfTwoPlayersGoals() {
|
||||
return (array1, array2) -> Arrays.stream(array1).sum() + Arrays.stream(array2).sum();
|
||||
}
|
||||
}
|
7
src/BiPredicateType.java
Normal file
7
src/BiPredicateType.java
Normal file
@ -0,0 +1,7 @@
|
||||
import java.util.function.BiPredicate;
|
||||
|
||||
public class BiPredicateType {
|
||||
public BiPredicate<Integer, Integer> goalsMoreThanMatches() {
|
||||
return (g, m) -> g > m;
|
||||
}
|
||||
}
|
6
src/BinaryOperatorType.java
Normal file
6
src/BinaryOperatorType.java
Normal file
@ -0,0 +1,6 @@
|
||||
import java.util.function.BinaryOperator;
|
||||
public class BinaryOperatorType {
|
||||
public BinaryOperator<Double> passesPerGoal() {
|
||||
return (g, p) -> p/g;
|
||||
}
|
||||
}
|
13
src/ConsumerType.java
Normal file
13
src/ConsumerType.java
Normal file
@ -0,0 +1,13 @@
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class ConsumerType {
|
||||
public Consumer<String> isDefender() {
|
||||
return (i) -> {
|
||||
if (i.equals("defender")) {
|
||||
System.out.println("Yes");
|
||||
} else {
|
||||
System.out.println("No");
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
8
src/FunctionType.java
Normal file
8
src/FunctionType.java
Normal file
@ -0,0 +1,8 @@
|
||||
import java.util.Arrays;
|
||||
import java.util.function.Function;
|
||||
|
||||
public class FunctionType {
|
||||
public Function<int[], Integer> goalsSum() {
|
||||
return sum -> Arrays.stream(sum).sum();
|
||||
}
|
||||
}
|
89
src/Main.java
Normal file
89
src/Main.java
Normal file
@ -0,0 +1,89 @@
|
||||
import java.util.Date;
|
||||
import java.util.function.*;
|
||||
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
PremierLeaguePlayer playerOne = new PremierLeaguePlayer(34, "defender");
|
||||
PremierLeaguePlayer playerTwo = new PremierLeaguePlayer(30, "forward");
|
||||
|
||||
System.out.print("Scores goals on the same time: ");
|
||||
BiConsumerType biConsumerType = new BiConsumerType();
|
||||
biConsumerType.goalsOnTheSameTime().accept(playerOne.getMinutesOfGoals(), playerOne.getMinutesOfGoals());
|
||||
System.out.println("---------------------------");
|
||||
|
||||
System.out.print("Sum goals of both players: ");
|
||||
BiFunctionType biFunctionType = new BiFunctionType();
|
||||
BiFunction<int[], int[], Integer> sum = biFunctionType.sumOfTwoPlayersGoals();
|
||||
int goalsSum = sum.apply(playerOne.getGoalsInMatches(), playerTwo.getGoalsInMatches());
|
||||
System.out.println(goalsSum);
|
||||
System.out.println("---------------------------");
|
||||
|
||||
BinaryOperatorType binaryOperatorType = new BinaryOperatorType();
|
||||
BinaryOperator<Double> passesPerGoalRatio = binaryOperatorType.passesPerGoal();
|
||||
|
||||
Double playerOnePassesPerGoal = passesPerGoalRatio.apply((double) playerOne.getTotalGoals(), (double) playerOne.getTotalPasses());
|
||||
System.out.print("Passes per goal for Player One: ");
|
||||
System.out.println(playerOnePassesPerGoal);
|
||||
Double playerTwoPassesPerGoal = passesPerGoalRatio.apply((double) playerTwo.getTotalGoals(), (double) playerTwo.getTotalPasses());
|
||||
System.out.print("Passes per goal for Player Two: ");
|
||||
System.out.println(playerTwoPassesPerGoal);
|
||||
System.out.println("---------------------------");
|
||||
|
||||
BiPredicateType biPredicateType = new BiPredicateType();
|
||||
BiPredicate<Integer, Integer> goalsMoreThanMatchesBoolean = biPredicateType.goalsMoreThanMatches();
|
||||
System.out.print("Player One has more goals than matches: ");
|
||||
boolean playerOneMoreGoalsThanMatches = goalsMoreThanMatchesBoolean.test(playerOne.getTotalGoals(), playerOne.getMatchesPlayed());
|
||||
System.out.println(playerOneMoreGoalsThanMatches);
|
||||
System.out.print("Player Two has more goals than matches: ");
|
||||
boolean playerTwoMoreGoalsThanMatches = goalsMoreThanMatchesBoolean.test(playerTwo.getTotalGoals(), playerTwo.getMatchesPlayed());
|
||||
System.out.println(playerTwoMoreGoalsThanMatches);
|
||||
System.out.println("---------------------------");
|
||||
|
||||
ConsumerType consumerType = new ConsumerType();
|
||||
Consumer<String> isDefenderFunction = consumerType.isDefender();
|
||||
System.out.print("Is Player One a defender: ");
|
||||
isDefenderFunction.accept(playerOne.getPosition());
|
||||
System.out.print("Is Player Two a defender: ");
|
||||
isDefenderFunction.accept(playerTwo.getPosition());
|
||||
System.out.println("---------------------------");
|
||||
|
||||
FunctionType functionType = new FunctionType();
|
||||
Function<int[], Integer> goalsSumFunction = functionType.goalsSum();
|
||||
int playerOneGoals = goalsSumFunction.apply(playerOne.getGoalsInMatches());
|
||||
System.out.println("Goals sum for Player One: " + playerOneGoals);
|
||||
int playerTwoGoals = goalsSumFunction.apply(playerTwo.getGoalsInMatches());
|
||||
System.out.println("Goals sum for Player Two: " + playerTwoGoals);
|
||||
System.out.println("---------------------------");
|
||||
|
||||
PredicateType predicateType = new PredicateType();
|
||||
Predicate<Integer> hasAtLeastThreeMatchPlayedFunction = predicateType.hasAtLeastThreeMatchPlayed();
|
||||
boolean player1HasAtLeastThreeMatches = hasAtLeastThreeMatchPlayedFunction.test(playerOne.getMatchesPlayed());
|
||||
System.out.println("Player One played at least three matches: " + player1HasAtLeastThreeMatches);
|
||||
boolean player2HasAtLeastThreeMatches = hasAtLeastThreeMatchPlayedFunction.test(playerTwo.getMatchesPlayed());
|
||||
System.out.println("Player Two played at least three matches: " + player2HasAtLeastThreeMatches);
|
||||
System.out.println("---------------------------");
|
||||
|
||||
ToIntType toIntType = new ToIntType();
|
||||
ToIntFunction<Integer> secondsPlayedFunction = toIntType.secondsPlayed();
|
||||
int playerOneSecondsPlayed = secondsPlayedFunction.applyAsInt(playerOne.getMinutesPlayed());
|
||||
System.out.println("Player One minutes played in seconds: " + playerOneSecondsPlayed);
|
||||
int playerTwoSecondsPlayed = secondsPlayedFunction.applyAsInt(playerTwo.getMinutesPlayed());
|
||||
System.out.println("Player Two minutes played in seconds: " + playerTwoSecondsPlayed);
|
||||
System.out.println("---------------------------");
|
||||
|
||||
UnaryType unaryType = new UnaryType();
|
||||
UnaryOperator<Double> goalsPerMatchFunction = unaryType.goalsPerMatch();
|
||||
double playerOneGoalsPerMatch = goalsPerMatchFunction.apply((double) playerOne.getTotalGoals());
|
||||
System.out.println("Player One goals per match: " + playerOneGoalsPerMatch);
|
||||
double playerTwoGoalsPerMatch = goalsPerMatchFunction.apply((double)playerTwo.getTotalGoals());
|
||||
System.out.println("Player Two goals per match: " + playerTwoGoalsPerMatch);
|
||||
System.out.println("---------------------------");
|
||||
|
||||
SupplierType supplierType = new SupplierType();
|
||||
Supplier<Date> dateSupplier = supplierType.reportDate();
|
||||
Date reportDate = dateSupplier.get();
|
||||
System.out.println("Report Date: " + reportDate);
|
||||
}
|
||||
|
||||
|
||||
}
|
6
src/PredicateType.java
Normal file
6
src/PredicateType.java
Normal file
@ -0,0 +1,6 @@
|
||||
import java.util.function.Predicate;
|
||||
public class PredicateType {
|
||||
public Predicate<Integer> hasAtLeastThreeMatchPlayed() {
|
||||
return i -> i >= 3;
|
||||
}
|
||||
}
|
64
src/PremierLeaguePlayer.java
Normal file
64
src/PremierLeaguePlayer.java
Normal file
@ -0,0 +1,64 @@
|
||||
import java.util.Arrays;
|
||||
import java.util.Random;
|
||||
|
||||
public class PremierLeaguePlayer {
|
||||
private int[] goalsInMatches;
|
||||
private int minutesPlayed;
|
||||
private int[] minutesOfGoals;
|
||||
private int totalPasses;
|
||||
private int matchesPlayed;
|
||||
private int totalGoals;
|
||||
private String position;
|
||||
|
||||
public PremierLeaguePlayer(int numberOfMatches, String position) {
|
||||
Random random = new Random();
|
||||
|
||||
this.goalsInMatches = new int[numberOfMatches];
|
||||
for (int i = 0; i < numberOfMatches; i++) {
|
||||
this.goalsInMatches[i] = random.nextInt(5);
|
||||
}
|
||||
|
||||
this.minutesPlayed = random.nextInt(90 * numberOfMatches);
|
||||
|
||||
this.minutesOfGoals = new int[numberOfMatches];
|
||||
for (int i = 0; i < numberOfMatches; i++) {
|
||||
if(this.goalsInMatches[i] > 0) {
|
||||
this.minutesOfGoals[i] = random.nextInt(91);
|
||||
}
|
||||
}
|
||||
|
||||
this.totalPasses = random.nextInt(250 * numberOfMatches);
|
||||
this.matchesPlayed = numberOfMatches;
|
||||
this.totalGoals = Arrays.stream(this.goalsInMatches).sum();
|
||||
this.position = position;
|
||||
}
|
||||
|
||||
public int getMatchesPlayed() {
|
||||
return matchesPlayed;
|
||||
}
|
||||
|
||||
public int getMinutesPlayed() {
|
||||
return minutesPlayed;
|
||||
}
|
||||
|
||||
public int getTotalGoals() {
|
||||
return totalGoals;
|
||||
}
|
||||
|
||||
public int getTotalPasses() {
|
||||
return totalPasses;
|
||||
}
|
||||
|
||||
public int[] getGoalsInMatches() {
|
||||
return goalsInMatches;
|
||||
}
|
||||
|
||||
public int[] getMinutesOfGoals() {
|
||||
return minutesOfGoals;
|
||||
}
|
||||
|
||||
public String getPosition() {
|
||||
return position;
|
||||
}
|
||||
|
||||
}
|
8
src/SupplierType.java
Normal file
8
src/SupplierType.java
Normal file
@ -0,0 +1,8 @@
|
||||
import java.util.Date;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class SupplierType {
|
||||
public Supplier<Date> reportDate() {
|
||||
return Date::new;
|
||||
}
|
||||
}
|
7
src/ToIntType.java
Normal file
7
src/ToIntType.java
Normal file
@ -0,0 +1,7 @@
|
||||
import java.util.function.ToIntFunction;
|
||||
|
||||
public class ToIntType {
|
||||
public ToIntFunction<Integer> secondsPlayed() {
|
||||
return m -> m*60;
|
||||
}
|
||||
}
|
7
src/UnaryType.java
Normal file
7
src/UnaryType.java
Normal file
@ -0,0 +1,7 @@
|
||||
import java.util.function.UnaryOperator;
|
||||
|
||||
public class UnaryType {
|
||||
public UnaryOperator<Double> goalsPerMatch() {
|
||||
return x -> x / 38;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user