Skip to content

Commit

Permalink
java3 lesson1 v1.0 2020-01-30 22-59
Browse files Browse the repository at this point in the history
  • Loading branch information
popovichia committed Jan 30, 2020
1 parent 28f9b0b commit 7ab7f6a
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 4 deletions.
3 changes: 3 additions & 0 deletions java3/lesson1/src/main/java/javacore/lesson1/Tests.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/
package javacore.lesson1;

import javacore.lesson1.task4.Task4;
import javacore.lesson1.task3.Task3;

/**
Expand All @@ -19,5 +20,7 @@ public static void main(String[] args) {
task2.test();
Task3 task3 = new Task3();
task3.test();
Task4 task4 = new Task4();
task4.test();
}
}
11 changes: 10 additions & 1 deletion java3/lesson1/src/main/java/javacore/lesson1/task3/Box.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,18 @@ public float getWeight() {
}
return resultWeight;
}
public boolean compare(Box<T> anotherBox) {
public ArrayList<T> getFruits() {
return this.fruits;
}
public boolean compare(Box anotherBox) {
return this.getWeight() == anotherBox.getWeight() ? true : false;
}
public void putTo(Box anotherBox) {
if (anotherBox.getFruits().isEmpty()) {
anotherBox.getFruits().addAll(this.getFruits());
this.getFruits().clear();
}
}
@Override
public String toString() {
return this.fruits.toString();
Expand Down
7 changes: 7 additions & 0 deletions java3/lesson1/src/main/java/javacore/lesson1/task3/Task3.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ public void test() {

System.out.println("Compare boxOranges and boxApples - " + boxOranges.compare(boxApples));

Box boxFruit = new Box();
System.out.println("boxApples - " + boxApples);
System.out.println("boxFruit - " + boxFruit);
boxApples.putTo(boxFruit);
System.out.println("boxApples - " + boxApples);
System.out.println("boxFruit - " + boxFruit);

System.out.println("--------------------------\n");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package javacore.lesson1;
package javacore.lesson1.task4;

/**
*
* @author igor
*/
public class Task4 {

public interface Lambda {
int calculate(int a, int b);
}
21 changes: 21 additions & 0 deletions java3/lesson1/src/main/java/javacore/lesson1/task4/Task4.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package javacore.lesson1.task4;

/**
*
* @author igor
*/
public class Task4 {
public void test() {
Lambda lambdaSum = (x, y) -> x + y;
System.out.println("Лямбда для суммы: " + lambdaSum.calculate(20, 5));
Lambda lambdaDiv = (x, y) -> x / y;
System.out.println("Лямбда для деления: " + lambdaDiv.calculate(20, 5));
Lambda lambdaMul = (x, y) -> x * y;
System.out.println("Лямбда для умножения: " + lambdaMul.calculate(20, 5));
}
}

0 comments on commit 7ab7f6a

Please sign in to comment.