diff --git a/core-java-8/src/main/java/com/baeldung/interfaces/Electronic.java b/core-java-8/src/main/java/com/baeldung/interfaces/Electronic.java deleted file mode 100644 index bfbc381483..0000000000 --- a/core-java-8/src/main/java/com/baeldung/interfaces/Electronic.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.baeldung.interfaces; - -public interface Electronic { - //Constant variable - public static final String LED = "LED"; - - //Abstract method - public int getElectricityUse(); - - // Static method - public static boolean isEnergyEfficient(String electtronicType) { - if (electtronicType.equals(LED)) { - return true; - } - return false; - } - - //Default method - public default void printDescription() { - System.out.println("Electronic Description"); - } -} diff --git a/core-java-8/src/main/java/com/baeldung/interfaces/Motorcycle.java b/core-java-8/src/main/java/com/baeldung/interfaces/Motorcycle.java deleted file mode 100644 index 6003f476a3..0000000000 --- a/core-java-8/src/main/java/com/baeldung/interfaces/Motorcycle.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.baeldung.interfaces; - -import com.baeldung.interfaces.multiinheritance.Transform; - -public class Motorcycle implements Transform { - @Override - public void transform() { - // Implementation - } -} \ No newline at end of file diff --git a/core-java-8/src/main/java/com/baeldung/interfaces/Truck.java b/core-java-8/src/main/java/com/baeldung/interfaces/Truck.java deleted file mode 100644 index d78de23371..0000000000 --- a/core-java-8/src/main/java/com/baeldung/interfaces/Truck.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.baeldung.interfaces; - -public class Truck extends Vehicle { - @Override - public void transform() { - // implementation - } -} diff --git a/core-java-8/src/main/java/com/baeldung/interfaces/Vehicle.java b/core-java-8/src/main/java/com/baeldung/interfaces/Vehicle.java deleted file mode 100644 index 8b4662e1a3..0000000000 --- a/core-java-8/src/main/java/com/baeldung/interfaces/Vehicle.java +++ /dev/null @@ -1,6 +0,0 @@ -package com.baeldung.interfaces; - -import com.baeldung.interfaces.multiinheritance.Transform; - -public abstract class Vehicle implements Transform { -} diff --git a/core-java-8/src/main/java/com/baeldung/interfaces/multiinheritance/Vehicle.java b/core-java-8/src/main/java/com/baeldung/interfaces/multiinheritance/Vehicle.java deleted file mode 100644 index fb0d36e3e0..0000000000 --- a/core-java-8/src/main/java/com/baeldung/interfaces/multiinheritance/Vehicle.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.baeldung.interfaces.multiinheritance; - -public class Vehicle implements Fly, Transform { - @Override - public void fly() { - System.out.println("I can Fly!!"); - } - - @Override - public void transform() { - System.out.println("I can Transform!!"); - } -} diff --git a/core-java-8/src/main/java/com/baeldung/interfaces/polymorphysim/Circle.java b/core-java-8/src/main/java/com/baeldung/interfaces/polymorphysim/Circle.java deleted file mode 100644 index afb3142d96..0000000000 --- a/core-java-8/src/main/java/com/baeldung/interfaces/polymorphysim/Circle.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.baeldung.interfaces.polymorphysim; - -public class Circle implements Shape { - - private double radius; - - public Circle(double radius){ - this.radius = radius; - } - - @Override - public String name() { - return "Circle"; - } - - @Override - public double area() { - return Math.PI * (radius * radius); - } - - @Override - public String getColor() { - return "green"; - } -} diff --git a/core-java-8/src/main/java/com/baeldung/interfaces/polymorphysim/DisplayShape.java b/core-java-8/src/main/java/com/baeldung/interfaces/polymorphysim/DisplayShape.java deleted file mode 100644 index d9c9dd107a..0000000000 --- a/core-java-8/src/main/java/com/baeldung/interfaces/polymorphysim/DisplayShape.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.baeldung.interfaces.polymorphysim; - -import java.util.ArrayList; - -public class DisplayShape { - - private ArrayList shapes; - - public ArrayList getShapes() { - return shapes; - } - - public DisplayShape() { - shapes = new ArrayList<>(); - } - - public void add(Shape shape) { - shapes.add(shape); - } - - public void display() { - for (Shape shape : shapes) { - System.out.println(shape.name() + " area: " + shape.area()); - } - } -} diff --git a/core-java-8/src/main/java/com/baeldung/interfaces/polymorphysim/FunctionalMain.java b/core-java-8/src/main/java/com/baeldung/interfaces/polymorphysim/FunctionalMain.java deleted file mode 100644 index 5316dd7db7..0000000000 --- a/core-java-8/src/main/java/com/baeldung/interfaces/polymorphysim/FunctionalMain.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.baeldung.interfaces.polymorphysim; - -import java.util.function.Predicate; - -public class FunctionalMain { - -public static void main(String[] args) { - Shape circleShape = new Circle(2); - Shape squareShape = new Square(2); - - DisplayShape DisplayShape = new DisplayShape(); - DisplayShape.add(circleShape); - DisplayShape.add(squareShape); - - Predicate checkArea = (shape) -> shape.area() < 5; - - for (Shape shape : DisplayShape.getShapes()) { - if (checkArea.test(shape)) { - System.out.println(shape.name() + " " + shape.area()); - } - } -} -} diff --git a/core-java-8/src/main/java/com/baeldung/interfaces/polymorphysim/MainPolymorphic.java b/core-java-8/src/main/java/com/baeldung/interfaces/polymorphysim/MainPolymorphic.java deleted file mode 100644 index cc43c1300b..0000000000 --- a/core-java-8/src/main/java/com/baeldung/interfaces/polymorphysim/MainPolymorphic.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.baeldung.interfaces.polymorphysim; - -public class MainPolymorphic { - public static void main(String[] args){ - - Shape circleShape = new Circle(2); - Shape squareShape = new Square(2); - - DisplayShape displayShape = new DisplayShape(); - displayShape.add(circleShape); - displayShape.add(squareShape); - - displayShape.display(); - } -} diff --git a/core-java-8/src/main/java/com/baeldung/interfaces/polymorphysim/Shape.java b/core-java-8/src/main/java/com/baeldung/interfaces/polymorphysim/Shape.java deleted file mode 100644 index 560e07a80a..0000000000 --- a/core-java-8/src/main/java/com/baeldung/interfaces/polymorphysim/Shape.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.baeldung.interfaces.polymorphysim; - -import com.baeldung.interfaces.HasColor; - -public interface Shape extends HasColor { - - public abstract String name(); - public abstract double area(); -} diff --git a/core-java-8/src/main/java/com/baeldung/interfaces/polymorphysim/Square.java b/core-java-8/src/main/java/com/baeldung/interfaces/polymorphysim/Square.java deleted file mode 100644 index 00b75ace20..0000000000 --- a/core-java-8/src/main/java/com/baeldung/interfaces/polymorphysim/Square.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.baeldung.interfaces.polymorphysim; - -public class Square implements Shape { - - private double width; - - public Square(double width) { - this.width = width; - } - - @Override - public String name() { - return "Square"; - } - - @Override - public double area() { - return width * width; - } - - @Override - public String getColor() { - return "red"; - } -} diff --git a/core-java-8/src/test/java/com/baeldung/interfaces/PolymorphysimUnitTest.java b/core-java-8/src/test/java/com/baeldung/interfaces/PolymorphysimUnitTest.java deleted file mode 100644 index 7ded5e6621..0000000000 --- a/core-java-8/src/test/java/com/baeldung/interfaces/PolymorphysimUnitTest.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.baeldung.interfaces; - -import com.baeldung.interfaces.polymorphysim.Circle; -import com.baeldung.interfaces.polymorphysim.Shape; -import com.baeldung.interfaces.polymorphysim.Square; -import org.assertj.core.api.Assertions; -import org.junit.Test; - -public class PolymorphysimUnitTest { - - @Test - public void whenInterfacePointsToCircle_CircleAreaMethodisBeingCalled(){ - double expectedArea = 12.566370614359172; - Shape circle = new Circle(2); - double actualArea = circle.area(); - Assertions.assertThat(actualArea).isEqualTo(expectedArea); - } - - @Test - public void whenInterfacePointsToSquare_SquareAreaMethodisBeingCalled(){ - double expectedArea = 4; - Shape square = new Square(2); - double actualArea = square.area(); - Assertions.assertThat(actualArea).isEqualTo(expectedArea); - } -} diff --git a/core-java/src/main/java/com/baeldung/interfaces/Box.java b/core-java/src/main/java/com/baeldung/interfaces/Box.java new file mode 100644 index 0000000000..0bb6560465 --- /dev/null +++ b/core-java/src/main/java/com/baeldung/interfaces/Box.java @@ -0,0 +1,5 @@ +package com.baeldung.interfaces; + +public interface Box extends HasColor { + int getHeight(); +} diff --git a/core-java-8/src/main/java/com/baeldung/interfaces/Employee.java b/core-java/src/main/java/com/baeldung/interfaces/Employee.java similarity index 99% rename from core-java-8/src/main/java/com/baeldung/interfaces/Employee.java rename to core-java/src/main/java/com/baeldung/interfaces/Employee.java index 903bc81e6f..8c6bd3f7f3 100644 --- a/core-java-8/src/main/java/com/baeldung/interfaces/Employee.java +++ b/core-java/src/main/java/com/baeldung/interfaces/Employee.java @@ -11,5 +11,4 @@ public class Employee { public void setSalary(double salary) { this.salary = salary; } - } diff --git a/core-java-8/src/main/java/com/baeldung/interfaces/EmployeeSalaryComparator.java b/core-java/src/main/java/com/baeldung/interfaces/EmployeeSalaryComparator.java similarity index 67% rename from core-java-8/src/main/java/com/baeldung/interfaces/EmployeeSalaryComparator.java rename to core-java/src/main/java/com/baeldung/interfaces/EmployeeSalaryComparator.java index cfa4226c1a..5c841b7c2b 100644 --- a/core-java-8/src/main/java/com/baeldung/interfaces/EmployeeSalaryComparator.java +++ b/core-java/src/main/java/com/baeldung/interfaces/EmployeeSalaryComparator.java @@ -6,12 +6,11 @@ public class EmployeeSalaryComparator implements Comparator { @Override public int compare(Employee employeeA, Employee employeeB) { - - if(employeeA.getSalary() < employeeB.getSalary()){ + if (employeeA.getSalary() < employeeB.getSalary()) { return -1; - }else if(employeeA.getSalary() > employeeB.getSalary()){ + } else if (employeeA.getSalary() > employeeB.getSalary()) { return 1; - }else{ + } else { return 0; } } diff --git a/core-java-8/src/main/java/com/baeldung/interfaces/HasColor.java b/core-java/src/main/java/com/baeldung/interfaces/HasColor.java similarity index 66% rename from core-java-8/src/main/java/com/baeldung/interfaces/HasColor.java rename to core-java/src/main/java/com/baeldung/interfaces/HasColor.java index 6eface2d47..d9688ea866 100644 --- a/core-java-8/src/main/java/com/baeldung/interfaces/HasColor.java +++ b/core-java/src/main/java/com/baeldung/interfaces/HasColor.java @@ -1,5 +1,4 @@ package com.baeldung.interfaces; public interface HasColor { - public String getColor(); -} \ No newline at end of file +} diff --git a/core-java-8/src/main/java/com/baeldung/interfaces/multiinheritance/Car.java b/core-java/src/main/java/com/baeldung/interfaces/multiinheritance/Car.java similarity index 84% rename from core-java-8/src/main/java/com/baeldung/interfaces/multiinheritance/Car.java rename to core-java/src/main/java/com/baeldung/interfaces/multiinheritance/Car.java index b951fc0273..d9b30a1e7b 100644 --- a/core-java-8/src/main/java/com/baeldung/interfaces/multiinheritance/Car.java +++ b/core-java/src/main/java/com/baeldung/interfaces/multiinheritance/Car.java @@ -1,6 +1,7 @@ package com.baeldung.interfaces.multiinheritance; -public class Car implements Fly, Transform { +public class Car implements Fly,Transform { + @Override public void fly() { System.out.println("I can Fly!!"); diff --git a/core-java-8/src/main/java/com/baeldung/interfaces/multiinheritance/Fly.java b/core-java/src/main/java/com/baeldung/interfaces/multiinheritance/Fly.java similarity index 69% rename from core-java-8/src/main/java/com/baeldung/interfaces/multiinheritance/Fly.java rename to core-java/src/main/java/com/baeldung/interfaces/multiinheritance/Fly.java index d84182aec6..611e51c67b 100644 --- a/core-java-8/src/main/java/com/baeldung/interfaces/multiinheritance/Fly.java +++ b/core-java/src/main/java/com/baeldung/interfaces/multiinheritance/Fly.java @@ -1,5 +1,6 @@ package com.baeldung.interfaces.multiinheritance; -public abstract interface Fly{ +public interface Fly { + void fly(); } diff --git a/core-java-8/src/main/java/com/baeldung/interfaces/multiinheritance/Transform.java b/core-java/src/main/java/com/baeldung/interfaces/multiinheritance/Transform.java similarity index 100% rename from core-java-8/src/main/java/com/baeldung/interfaces/multiinheritance/Transform.java rename to core-java/src/main/java/com/baeldung/interfaces/multiinheritance/Transform.java diff --git a/core-java/src/main/java/com/baeldung/interfaces/multiinheritance/Vehicle.java b/core-java/src/main/java/com/baeldung/interfaces/multiinheritance/Vehicle.java new file mode 100644 index 0000000000..be25e112ee --- /dev/null +++ b/core-java/src/main/java/com/baeldung/interfaces/multiinheritance/Vehicle.java @@ -0,0 +1,4 @@ +package com.baeldung.interfaces.multiinheritance; + +public abstract class Vehicle implements Transform { +} diff --git a/core-java/src/main/java/com/baeldung/interfaces/polymorphysim/Circle.java b/core-java/src/main/java/com/baeldung/interfaces/polymorphysim/Circle.java new file mode 100644 index 0000000000..b4d97bd53a --- /dev/null +++ b/core-java/src/main/java/com/baeldung/interfaces/polymorphysim/Circle.java @@ -0,0 +1,9 @@ +package com.baeldung.interfaces.polymorphysim; + +public class Circle implements Shape { + + @Override + public String name() { + return "Circle"; + } +} diff --git a/core-java/src/main/java/com/baeldung/interfaces/polymorphysim/MainTestClass.java b/core-java/src/main/java/com/baeldung/interfaces/polymorphysim/MainTestClass.java new file mode 100644 index 0000000000..5cce3c3af0 --- /dev/null +++ b/core-java/src/main/java/com/baeldung/interfaces/polymorphysim/MainTestClass.java @@ -0,0 +1,20 @@ +package com.baeldung.interfaces.polymorphysim; + +import java.util.ArrayList; +import java.util.List; + +public class MainTestClass { + + public static void main(String[] args) { + List shapes = new ArrayList<>(); + Shape circleShape = new Circle(); + Shape squareShape = new Square(); + + shapes.add(circleShape); + shapes.add(squareShape); + + for (Shape shape : shapes) { + System.out.println(shape.name()); + } + } +} diff --git a/core-java/src/main/java/com/baeldung/interfaces/polymorphysim/Shape.java b/core-java/src/main/java/com/baeldung/interfaces/polymorphysim/Shape.java new file mode 100644 index 0000000000..885dc73de2 --- /dev/null +++ b/core-java/src/main/java/com/baeldung/interfaces/polymorphysim/Shape.java @@ -0,0 +1,6 @@ +package com.baeldung.interfaces.polymorphysim; + +public interface Shape { + + String name(); +} diff --git a/core-java/src/main/java/com/baeldung/interfaces/polymorphysim/Square.java b/core-java/src/main/java/com/baeldung/interfaces/polymorphysim/Square.java new file mode 100644 index 0000000000..c17bdd902d --- /dev/null +++ b/core-java/src/main/java/com/baeldung/interfaces/polymorphysim/Square.java @@ -0,0 +1,9 @@ +package com.baeldung.interfaces.polymorphysim; + +public class Square implements Shape { + + @Override + public String name() { + return "Square"; + } +}