guyanqing 6 bulan lalu
induk
melakukan
983c010709
90 mengubah file dengan 865 tambahan dan 0 penghapusan
  1. 38 0
      src/main/java/com/sf/day07/homework/Apple.java
  2. 13 0
      src/main/java/com/sf/day07/homework/CompareAble.java
  3. 14 0
      src/main/java/com/sf/day07/homework/CompareBig.java
  4. 14 0
      src/main/java/com/sf/day07/homework/CompareColor.java
  5. 7 0
      src/main/java/com/sf/day07/homework/Person.java
  6. 11 0
      src/main/java/com/sf/day07/homework/TestApple.java
  7. 31 0
      src/main/java/com/sf/day08/Circle.java
  8. 10 0
      src/main/java/com/sf/day08/FightAble.java
  9. 8 0
      src/main/java/com/sf/day08/Mage.java
  10. 25 0
      src/main/java/com/sf/day08/Player.java
  11. 58 0
      src/main/java/com/sf/day08/Rectangle.java
  12. 16 0
      src/main/java/com/sf/day08/ShapeInterface.java
  13. 16 0
      src/main/java/com/sf/day08/Te.java
  14. 34 0
      src/main/java/com/sf/day08/Triangle.java
  15. 12 0
      src/main/java/com/sf/day08/Warrior.java
  16. 38 0
      src/main/java/com/sf/day08/apple/Apple.java
  17. 6 0
      src/main/java/com/sf/day08/apple/CompareAble.java
  18. 14 0
      src/main/java/com/sf/day08/apple/CompareBig.java
  19. 14 0
      src/main/java/com/sf/day08/apple/CompareColor.java
  20. 20 0
      src/main/java/com/sf/day08/apple/Worker.java
  21. 6 0
      src/main/java/com/sf/day08/flay/Bird.java
  22. 42 0
      src/main/java/com/sf/day08/flay/Chicken.java
  23. 5 0
      src/main/java/com/sf/day08/flay/Flyable.java
  24. 13 0
      src/main/java/com/sf/day08/flay/Penguin.java
  25. 21 0
      src/main/java/com/sf/day08/flay/Swan.java
  26. 6 0
      src/main/java/com/sf/day08/flay/Swimming.java
  27. 34 0
      src/main/java/com/sf/day08/innerclass/Demo.java
  28. 26 0
      src/main/java/com/sf/day08/innerclass/Outer01.java
  29. 20 0
      src/main/java/com/sf/day08/innerclass/Outer02.java
  30. 21 0
      src/main/java/com/sf/day08/innerclass/OuterClass.java
  31. 8 0
      src/main/java/com/sf/day08/innerclass/Student.java
  32. 17 0
      src/main/java/com/sf/day08/innerclass/Swim.java
  33. 15 0
      src/main/java/com/sf/day08/lambda/Data.java
  34. 6 0
      src/main/java/com/sf/day08/lambda/IPrintable.java
  35. 17 0
      src/main/java/com/sf/day08/lambda/IPrintableTest.java
  36. 6 0
      src/main/java/com/sf/day08/lambda/IRandomable.java
  37. 31 0
      src/main/java/com/sf/day08/lambda/IRandomableTest.java
  38. 7 0
      src/main/java/com/sf/day08/lambda/IShowable.java
  39. 24 0
      src/main/java/com/sf/day08/lambda/IShowableTest.java
  40. 6 0
      src/main/java/com/sf/day08/lambda/MyPredicate.java
  41. 61 0
      src/main/java/com/sf/day08/lambda/Product.java
  42. 39 0
      src/main/java/com/sf/day08/lambda/Te.java
  43. 35 0
      src/main/java/com/sf/day08/lambda/Te2.java
  44. TEMPAT SAMPAH
      target/classes/com/sf/day07/homework/Apple.class
  45. TEMPAT SAMPAH
      target/classes/com/sf/day07/homework/CompareAble.class
  46. TEMPAT SAMPAH
      target/classes/com/sf/day07/homework/CompareBig.class
  47. TEMPAT SAMPAH
      target/classes/com/sf/day07/homework/CompareColor.class
  48. TEMPAT SAMPAH
      target/classes/com/sf/day07/homework/Person.class
  49. TEMPAT SAMPAH
      target/classes/com/sf/day07/homework/TestApple.class
  50. TEMPAT SAMPAH
      target/classes/com/sf/day07/lx/BuildCarsInterface2.class
  51. TEMPAT SAMPAH
      target/classes/com/sf/day07/lx/BuildCarsInterfaceImpl.class
  52. TEMPAT SAMPAH
      target/classes/com/sf/day08/Circle.class
  53. TEMPAT SAMPAH
      target/classes/com/sf/day08/FightAble.class
  54. TEMPAT SAMPAH
      target/classes/com/sf/day08/Mage.class
  55. TEMPAT SAMPAH
      target/classes/com/sf/day08/Player.class
  56. TEMPAT SAMPAH
      target/classes/com/sf/day08/Rectangle.class
  57. TEMPAT SAMPAH
      target/classes/com/sf/day08/ShapeInterface.class
  58. TEMPAT SAMPAH
      target/classes/com/sf/day08/Te.class
  59. TEMPAT SAMPAH
      target/classes/com/sf/day08/Triangle.class
  60. TEMPAT SAMPAH
      target/classes/com/sf/day08/Warrior.class
  61. TEMPAT SAMPAH
      target/classes/com/sf/day08/apple/Apple.class
  62. TEMPAT SAMPAH
      target/classes/com/sf/day08/apple/CompareAble.class
  63. TEMPAT SAMPAH
      target/classes/com/sf/day08/apple/CompareBig.class
  64. TEMPAT SAMPAH
      target/classes/com/sf/day08/apple/CompareColor.class
  65. TEMPAT SAMPAH
      target/classes/com/sf/day08/apple/Worker.class
  66. TEMPAT SAMPAH
      target/classes/com/sf/day08/flay/Bird.class
  67. TEMPAT SAMPAH
      target/classes/com/sf/day08/flay/Chicken.class
  68. TEMPAT SAMPAH
      target/classes/com/sf/day08/flay/Flyable.class
  69. TEMPAT SAMPAH
      target/classes/com/sf/day08/flay/Penguin.class
  70. TEMPAT SAMPAH
      target/classes/com/sf/day08/flay/Swan.class
  71. TEMPAT SAMPAH
      target/classes/com/sf/day08/flay/Swimming.class
  72. TEMPAT SAMPAH
      target/classes/com/sf/day08/innerclass/Demo$1.class
  73. TEMPAT SAMPAH
      target/classes/com/sf/day08/innerclass/Demo$2.class
  74. TEMPAT SAMPAH
      target/classes/com/sf/day08/innerclass/Demo.class
  75. TEMPAT SAMPAH
      target/classes/com/sf/day08/innerclass/Outer01$inner01.class
  76. TEMPAT SAMPAH
      target/classes/com/sf/day08/innerclass/Outer01.class
  77. TEMPAT SAMPAH
      target/classes/com/sf/day08/innerclass/Outer02$Inner02.class
  78. TEMPAT SAMPAH
      target/classes/com/sf/day08/innerclass/Outer02.class
  79. TEMPAT SAMPAH
      target/classes/com/sf/day08/innerclass/OuterClass$1LocalInnerClass.class
  80. TEMPAT SAMPAH
      target/classes/com/sf/day08/innerclass/OuterClass.class
  81. TEMPAT SAMPAH
      target/classes/com/sf/day08/innerclass/Student.class
  82. TEMPAT SAMPAH
      target/classes/com/sf/day08/innerclass/Swim$1.class
  83. TEMPAT SAMPAH
      target/classes/com/sf/day08/innerclass/Swim.class
  84. TEMPAT SAMPAH
      target/classes/com/sf/day08/lambda/Data.class
  85. TEMPAT SAMPAH
      target/classes/com/sf/day08/lambda/MyPredicate.class
  86. TEMPAT SAMPAH
      target/classes/com/sf/day08/lambda/Product.class
  87. TEMPAT SAMPAH
      target/classes/com/sf/day08/lambda/Te.class
  88. TEMPAT SAMPAH
      target/classes/com/sf/day08/lambda/Te2$1.class
  89. TEMPAT SAMPAH
      target/classes/com/sf/day08/lambda/Te2$2.class
  90. TEMPAT SAMPAH
      target/classes/com/sf/day08/lambda/Te2.class

+ 38 - 0
src/main/java/com/sf/day07/homework/Apple.java

@@ -0,0 +1,38 @@
+package com.sf.day07.homework;
+
+public class Apple {
+    private Double size;
+    private String color;
+
+    public Apple() {
+    }
+
+    public Apple(Double size, String color) {
+        this.size = size;
+        this.color = color;
+    }
+
+    public Double getSize() {
+        return size;
+    }
+
+    public void setSize(Double size) {
+        this.size = size;
+    }
+
+    public String getColor() {
+        return color;
+    }
+
+    public void setColor(String color) {
+        this.color = color;
+    }
+
+    @Override
+    public String toString() {
+        return "Apple{" +
+                "size=" + size +
+                ", color='" + color + '\'' +
+                '}';
+    }
+}

+ 13 - 0
src/main/java/com/sf/day07/homework/CompareAble.java

@@ -0,0 +1,13 @@
+package com.sf.day07.homework;
+
+public interface CompareAble {
+
+    default void compare(Apple a1, Apple a2){
+        System.out.println("默认挑大的:");
+        if(a1.getSize() > a2.getSize()){
+            System.out.println(a1.getSize()+"=="+a1.getColor());
+        }else{
+            System.out.println(a2.getSize()+"=="+a2.getColor());
+        }
+    }
+}

+ 14 - 0
src/main/java/com/sf/day07/homework/CompareBig.java

@@ -0,0 +1,14 @@
+package com.sf.day07.homework;
+
+public class CompareBig implements CompareAble{
+
+    @Override
+    public void compare(Apple a1, Apple a2) {
+        System.out.println("默认挑大的:");
+        if(a1.getSize() > a2.getSize()){
+            System.out.println(a1.getSize()+"=="+a1.getColor());
+        }else{
+            System.out.println(a2.getSize()+"=="+a2.getColor());
+        }
+    }
+}

+ 14 - 0
src/main/java/com/sf/day07/homework/CompareColor.java

@@ -0,0 +1,14 @@
+package com.sf.day07.homework;
+
+public class CompareColor implements CompareAble{
+    @Override
+    public void compare(Apple a1, Apple a2) {
+        System.out.println("挑红的:");
+        if("红色".equals(a1.getColor())){
+            System.out.println(a1.getSize()+"=="+a1.getColor());
+        }
+        if("红色".equals(a2.getColor())){
+            System.out.println(a2.getSize()+"=="+a2.getColor());
+        }
+    }
+}

+ 7 - 0
src/main/java/com/sf/day07/homework/Person.java

@@ -0,0 +1,7 @@
+package com.sf.day07.homework;
+
+public class Person {
+    public void pickApple(CompareAble compareAble, Apple a1, Apple a2){
+        compareAble.compare(a1, a2);
+    }
+}

+ 11 - 0
src/main/java/com/sf/day07/homework/TestApple.java

@@ -0,0 +1,11 @@
+package com.sf.day07.homework;
+
+public class TestApple {
+    public static void main(String[] args) {
+        Apple a1 = new Apple(5.0, "青色");
+        Apple a2 = new Apple(3.0, "红色");
+        Person person = new Person();
+        person.pickApple(new CompareBig(),a1,a2);
+        person.pickApple(new CompareColor(),a1,a2);
+    }
+}

+ 31 - 0
src/main/java/com/sf/day08/Circle.java

@@ -0,0 +1,31 @@
+package com.sf.day08;
+
+public class Circle implements ShapeInterface{
+
+    private double radius;
+
+
+    @Override
+    public double getArea() {
+        return Math.PI*radius*radius;
+    }
+
+    @Override
+    public double getPerimeter() {
+        return 2*Math.PI*radius;
+    }
+
+    @Override
+    public String display() {
+        return "Circle{" +
+                "radius=" + radius +
+                '}';
+    }
+
+    @Override
+    public String toString() {
+        return "Circle{" +
+                "radius=" + radius +
+                '}';
+    }
+}

+ 10 - 0
src/main/java/com/sf/day08/FightAble.java

@@ -0,0 +1,10 @@
+package com.sf.day08;
+
+public interface FightAble {
+
+    void specialFight();
+
+    default  void commonFight(){
+        System.out.println("普通打击~");
+
+    }}

+ 8 - 0
src/main/java/com/sf/day08/Mage.java

@@ -0,0 +1,8 @@
+package com.sf.day08;
+
+public class Mage implements FightAble{
+    @Override
+    public void specialFight() {
+        System.out.println("法术攻击~");
+    }
+}

+ 25 - 0
src/main/java/com/sf/day08/Player.java

@@ -0,0 +1,25 @@
+package com.sf.day08;
+
+import java.util.Scanner;
+
+public class Player {
+    public static  FightAble select(String str){
+        FightAble fightAble = null;
+        if(str.equals("法力角色")){
+            fightAble = new Mage();
+            fightAble.specialFight();
+            fightAble.commonFight();
+        }else if (str.equals("武力角色")){
+            fightAble = new Warrior();
+            fightAble.specialFight();
+            fightAble.commonFight();
+        }
+        return fightAble;
+    }
+
+
+    public static void main(String[] args) {
+        Scanner scanner = new Scanner(System.in);
+        select(scanner.next());
+    }
+}

+ 58 - 0
src/main/java/com/sf/day08/Rectangle.java

@@ -0,0 +1,58 @@
+package com.sf.day08;
+
+public class Rectangle implements ShapeInterface{
+
+    private double length;
+    private double wide;
+
+    public Rectangle() {
+    }
+
+    public Rectangle(double length, double wide) {
+        this.length = length;
+        this.wide = wide;
+    }
+
+    public double getLength() {
+        return length;
+    }
+
+    public void setLength(double length) {
+        this.length = length;
+    }
+
+    public double getWide() {
+        return wide;
+    }
+
+    public void setWide(double wide) {
+        this.wide = wide;
+    }
+
+    @Override
+    public double getArea() {
+        return length*wide;
+    }
+
+    @Override
+    public double getPerimeter() {
+        return 2*(length+wide);
+    }
+
+    @Override
+    public String display() {
+        return "Rectangle{" +
+                "length=" + length +
+                ", wide=" + wide +
+                ",Area"+getArea()+",Perimeter"+getPerimeter()+
+                '}';
+    }
+
+    @Override
+    public String toString() {
+        return "Rectangle{" +
+                "length=" + length +
+                ", wide=" + wide +
+                '}';
+    }
+}

+ 16 - 0
src/main/java/com/sf/day08/ShapeInterface.java

@@ -0,0 +1,16 @@
+package com.sf.day08;
+
+public interface ShapeInterface {
+
+    double getArea();
+    double getPerimeter();
+    String display();
+
+    public static  double compareToArea(ShapeInterface s1 ,ShapeInterface s2){
+        return s1.getArea() - s2.getArea();
+    }
+
+    public static double compareToPerimeter(ShapeInterface s1 ,ShapeInterface s2){
+        return s1.getPerimeter()- s2.getPerimeter();
+    }
+}

+ 16 - 0
src/main/java/com/sf/day08/Te.java

@@ -0,0 +1,16 @@
+package com.sf.day08;
+
+public class Te {
+    //  测试 当前图形
+    public static void main(String[] args) {
+    ShapeInterface shapeInterface    =    new Rectangle(5.0,6.0);
+    ShapeInterface shapeInterface1   =    new Rectangle(15.0,16.0);
+    shapeInterface.getPerimeter();
+    shapeInterface.getArea();
+    System.out.println(shapeInterface.display());
+    double compareToArea = ShapeInterface.compareToArea(shapeInterface, shapeInterface1);
+    System.out.println(compareToArea);
+    double compareToPerimeter = ShapeInterface.compareToPerimeter(shapeInterface, shapeInterface1);
+    System.out.println(compareToPerimeter);
+    }
+}

+ 34 - 0
src/main/java/com/sf/day08/Triangle.java

@@ -0,0 +1,34 @@
+package com.sf.day08;
+
+public class Triangle implements ShapeInterface{
+
+    private double dbLength;
+    private  double height;
+
+
+    @Override
+    public double getArea() {
+        return 0.5*dbLength*height;
+    }
+
+    @Override
+    public double getPerimeter() {
+        return 3*dbLength;
+    }
+
+    @Override
+    public String display() {
+        return  "Triangle{" +
+                "dbLength=" + dbLength +
+                ", height=" + height +
+                '}';
+    }
+
+    @Override
+    public String toString() {
+        return "Triangle{" +
+                "dbLength=" + dbLength +
+                ", height=" + height +
+                '}';
+    }
+}

+ 12 - 0
src/main/java/com/sf/day08/Warrior.java

@@ -0,0 +1,12 @@
+package com.sf.day08;
+
+
+/**
+ * 战士类
+ */
+public class Warrior  implements  FightAble{
+    @Override
+    public void specialFight() {
+        System.out.println("武器攻击~");
+    }
+}

+ 38 - 0
src/main/java/com/sf/day08/apple/Apple.java

@@ -0,0 +1,38 @@
+package com.sf.day08.apple;
+
+public class Apple {
+    private double size;
+    private String color;
+
+    public Apple() {
+    }
+
+    public Apple(double size, String color) {
+        this.size = size;
+        this.color = color;
+    }
+
+    public double getSize() {
+        return size;
+    }
+
+    public void setSize(double size) {
+        this.size = size;
+    }
+
+    public String getColor() {
+        return color;
+    }
+
+    public void setColor(String color) {
+        this.color = color;
+    }
+
+    @Override
+    public String toString() {
+        return "Apple{" +
+                "size=" + size +
+                ", color='" + color + '\'' +
+                '}';
+    }
+}

+ 6 - 0
src/main/java/com/sf/day08/apple/CompareAble.java

@@ -0,0 +1,6 @@
+package com.sf.day08.apple;
+
+public interface CompareAble {
+
+    void compare(Apple apple1,Apple apple2);
+}

+ 14 - 0
src/main/java/com/sf/day08/apple/CompareBig.java

@@ -0,0 +1,14 @@
+package com.sf.day08.apple;
+
+public class CompareBig implements CompareAble{
+
+    @Override
+    public void compare(Apple a1, Apple a2) {
+            System.out.println("默认挑选最大的苹果");
+            if(a1.getSize() > a2.getSize()){
+                System.out.println("这是大苹果  尺寸"+a1.getSize()+"~~~颜色"+a1.getColor());
+            }else {
+                System.out.println("这是大苹果  尺寸"+a2.getSize()+"~~~颜色"+a2.getColor());
+            }
+    }
+}

+ 14 - 0
src/main/java/com/sf/day08/apple/CompareColor.java

@@ -0,0 +1,14 @@
+package com.sf.day08.apple;
+
+public class CompareColor implements CompareAble{
+    @Override
+    public void compare(Apple apple1, Apple apple2) {
+        System.out.println("挑选红色的苹果~");
+        if("红色".equals(apple1.getColor())){
+            System.out.println(apple1.getSize()+"=="+apple1.getColor());
+        }
+        if("红色".equals(apple2.getColor())){
+            System.out.println(apple2.getSize()+"=="+apple2.getColor());
+        }
+    }
+}

+ 20 - 0
src/main/java/com/sf/day08/apple/Worker.java

@@ -0,0 +1,20 @@
+package com.sf.day08.apple;
+
+public class Worker {
+    public void pickApple(CompareAble compareAble,Apple a1,Apple a2){
+        compareAble.compare(a1,a2);
+    }
+
+
+    /**
+     * 苹果测试类
+     * @param args
+     */
+    public static void main(String[] args) {
+        Apple a1 = new Apple(5, "青色");
+        Apple a2 = new Apple(3, "红色");
+        Worker worker = new Worker();
+        worker.pickApple(new CompareBig(),a1,a2);
+        worker.pickApple(new CompareColor(),a1,a2);
+    }
+}

+ 6 - 0
src/main/java/com/sf/day08/flay/Bird.java

@@ -0,0 +1,6 @@
+package com.sf.day08.flay;
+
+public abstract class Bird {
+
+    public abstract void eat();
+}

+ 42 - 0
src/main/java/com/sf/day08/flay/Chicken.java

@@ -0,0 +1,42 @@
+package com.sf.day08.flay;
+
+import java.util.Arrays;
+
+public class Chicken extends Bird implements Flyable{
+    @Override
+    public void eat() {
+        System.out.println("鸡吃谷子~");
+    }
+
+    @Override
+    public void fly() {
+        System.out.println("鸡上房揭瓦,满院子乱扑腾~");
+    }
+
+
+    /**
+     * 各种鸟的测试类
+     * @param args
+     */
+    public static void main(String[] args) {
+        Bird[] birds = new  Bird[3];
+        birds[0] = new Penguin();
+        birds[1] = new Swan();
+        birds[2] = new Chicken();
+//        System.out.println(Arrays.toString(birds));
+        for (Bird bird : birds) {
+            bird.eat();
+            if(bird instanceof Flyable){
+                Flyable flyable = (Flyable) bird;
+                flyable.fly();
+            }
+            if(bird instanceof Swimming){
+                Swimming swimming = (Swimming) bird;
+                swimming.swim();
+            }
+
+        }
+
+
+    }
+}

+ 5 - 0
src/main/java/com/sf/day08/flay/Flyable.java

@@ -0,0 +1,5 @@
+package com.sf.day08.flay;
+
+public interface Flyable {
+    void fly();
+}

+ 13 - 0
src/main/java/com/sf/day08/flay/Penguin.java

@@ -0,0 +1,13 @@
+package com.sf.day08.flay;
+
+public class Penguin extends Bird implements Swimming{
+    @Override
+    public void eat() {
+        System.out.println("企鹅吃南极磷虾~");
+    }
+
+    @Override
+    public void swim() {
+        System.out.println("企鹅下海捉虾~");
+    }
+}

+ 21 - 0
src/main/java/com/sf/day08/flay/Swan.java

@@ -0,0 +1,21 @@
+package com.sf.day08.flay;
+
+import com.sf.day08.FightAble;
+
+public class Swan extends Bird implements Flyable,Swimming {
+    @Override
+    public void eat() {
+        System.out.println("天鹅吃水生植物的根茎和种子、水生昆虫、螺类和小鱼");
+    }
+
+
+    @Override
+    public void fly() {
+        System.out.println("鹅展翅高飞,天南海北任我游~");
+    }
+
+    @Override
+    public void swim() {
+        System.out.println("天鹅把羽毛洗的锃亮,顺便捉条鱼~");
+    }
+}

+ 6 - 0
src/main/java/com/sf/day08/flay/Swimming.java

@@ -0,0 +1,6 @@
+package com.sf.day08.flay;
+
+public interface Swimming {
+    void swim();
+
+}

+ 34 - 0
src/main/java/com/sf/day08/innerclass/Demo.java

@@ -0,0 +1,34 @@
+package com.sf.day08.innerclass;
+
+public class Demo {
+    public static void main(String[] args) {
+        //  一
+        Student student = new Student();
+        goSwimming(student);
+
+        //二
+
+       Swim swim = new Swim() {
+            @Override
+            public void swimming() {
+                System.out.println("~~~~");
+            }
+        };
+        goSwimming(swim);
+
+
+        //   三
+        goSwimming(new Swim() {
+            @Override
+            public void swimming() {
+                System.out.println("~~~~");
+            }
+        });
+
+        //四
+        goSwimming(() -> System.out.println("~~~~"));
+    }
+
+    public static void goSwimming(Swim swim){
+        swim.swimming();
+    }}

+ 26 - 0
src/main/java/com/sf/day08/innerclass/Outer01.java

@@ -0,0 +1,26 @@
+package com.sf.day08.innerclass;
+
+public class Outer01 {
+    private static String sc_name = "java程序员";
+    private static String name = "web程序员";
+
+
+    public static class  inner01{
+        private String name;
+
+        public inner01(String name) {
+            this.name = name;
+        }
+        public void show(){
+            System.out.println(this.name);
+            System.out.println(sc_name);
+            System.out.println(Outer01.name);
+        }
+    }
+
+
+    public static void main(String[] args) {
+        Outer01.inner01 in = new Outer01.inner01("admin");
+        in.show();
+    }
+}

+ 20 - 0
src/main/java/com/sf/day08/innerclass/Outer02.java

@@ -0,0 +1,20 @@
+package com.sf.day08.innerclass;
+
+public class Outer02 {
+    public static void main(String[] args) {
+        Outer02.Inner02 in = new Outer02().new Inner02();
+        in.show();
+    }
+    private String name = "java";
+
+    public class Inner02{
+        private String name = "web";
+
+        public void show(){
+            System.out.println(name);
+            Outer02 outer02 = new Outer02();
+            System.out.println(outer02.name);
+
+        }
+    }
+}

+ 21 - 0
src/main/java/com/sf/day08/innerclass/OuterClass.java

@@ -0,0 +1,21 @@
+package com.sf.day08.innerclass;
+
+public class OuterClass {
+    public void method() {
+        final int outerVar = 10; // 或者只是effectively final
+
+        class LocalInnerClass {
+            public void display() {
+                System.out.println("Outer var: " + outerVar);
+            }
+        }
+
+        LocalInnerClass inner = new LocalInnerClass();
+        inner.display();
+    }
+
+    public static void main(String[] args) {
+        OuterClass outer = new OuterClass();
+        outer.method(); // 调用包含局部内部类的方法
+    }
+}

+ 8 - 0
src/main/java/com/sf/day08/innerclass/Student.java

@@ -0,0 +1,8 @@
+package com.sf.day08.innerclass;
+
+public class Student implements Swim{
+    @Override
+    public void swimming() {
+        System.out.println("~~~~");
+    }
+}

+ 17 - 0
src/main/java/com/sf/day08/innerclass/Swim.java

@@ -0,0 +1,17 @@
+package com.sf.day08.innerclass;
+
+import com.sf.day08.flay.Swimming;
+
+public interface Swim {
+    void swimming();
+
+    public static void main(String[] args) {
+        new Swim() {
+            @Override
+            public void swimming() {
+                System.out.println("swimming~");
+            }
+        }.swimming();
+
+    }
+}

+ 15 - 0
src/main/java/com/sf/day08/lambda/Data.java

@@ -0,0 +1,15 @@
+package com.sf.day08.lambda;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class Data {
+    public static List<Product> products = new ArrayList<>();
+    static {
+        products.add(new Product(1L, "苹果手机", 8888.88,"手机"));
+        products.add(new Product(2L, "华为手机", 6666.66,"手机"));
+        products.add(new Product(3L, "联想笔记本",7777.77,"电脑"));
+        products.add(new Product(4L, "机械键盘", 999.99,"键盘"));
+        products.add(new Product(5L, "雷蛇鼠标", 222.22,"鼠标"));
+    }
+}

+ 6 - 0
src/main/java/com/sf/day08/lambda/IPrintable.java

@@ -0,0 +1,6 @@
+package com.sf.day08.lambda;
+@FunctionalInterface
+public interface IPrintable {
+
+    void print(String msg);
+}

+ 17 - 0
src/main/java/com/sf/day08/lambda/IPrintableTest.java

@@ -0,0 +1,17 @@
+package com.sf.day08.lambda;
+
+public class IPrintableTest {
+    public static void main(String[] args) {
+        usePrintable(new IPrintable() {
+            @Override
+            public void print(String msg) {
+                System.out.println("~~~");
+            }
+        });
+        usePrintable((msg) ->   System.out.println("~~~"));
+    }
+
+
+    public static void usePrintable(IPrintable iPrintable){
+     iPrintable.print("msg~~");
+    }}

+ 6 - 0
src/main/java/com/sf/day08/lambda/IRandomable.java

@@ -0,0 +1,6 @@
+package com.sf.day08.lambda;
+@FunctionalInterface
+public interface IRandomable {
+
+    int getRandom();
+}

+ 31 - 0
src/main/java/com/sf/day08/lambda/IRandomableTest.java

@@ -0,0 +1,31 @@
+package com.sf.day08.lambda;
+
+import java.util.Random;
+
+public class IRandomableTest {
+
+    public static void main(String[] args) {
+        useRandomable(new IRandomable() {
+            @Override
+            public int getRandom() {
+                return (int) (Math.random()*1000);
+            }
+        });
+
+
+        useRandomable( () ->  {
+            int nextInt = new Random().nextInt();
+            return nextInt;
+        });
+
+        useRandomable( () ->
+             new Random().nextInt()
+        );
+
+    }
+
+    public static void useRandomable(IRandomable iRandomable){
+        int random = iRandomable.getRandom();
+        System.out.println(random);
+
+    }}

+ 7 - 0
src/main/java/com/sf/day08/lambda/IShowable.java

@@ -0,0 +1,7 @@
+package com.sf.day08.lambda;
+
+public interface IShowable {
+
+
+    void show();
+}

+ 24 - 0
src/main/java/com/sf/day08/lambda/IShowableTest.java

@@ -0,0 +1,24 @@
+package com.sf.day08.lambda;
+
+import com.sun.xml.internal.messaging.saaj.soap.SOAPVersionMismatchException;
+
+public class IShowableTest {
+
+    public static void main(String[] args) {
+        //  匿名内部类的方式
+        useShowable(new IShowable() {
+            @Override
+            public void show() {
+                System.out.println("~~~~~~~~~");
+            }
+        });
+
+
+        //  lambda表达式的方式
+       useShowable(() -> System.out.println("~~~~~~~~~"));
+    }
+
+    public static void useShowable(IShowable iShowable){
+     iShowable.show();
+    }
+}

+ 6 - 0
src/main/java/com/sf/day08/lambda/MyPredicate.java

@@ -0,0 +1,6 @@
+package com.sf.day08.lambda;
+
+public interface MyPredicate {
+
+    boolean test(Product product);
+}

+ 61 - 0
src/main/java/com/sf/day08/lambda/Product.java

@@ -0,0 +1,61 @@
+package com.sf.day08.lambda;
+
+public class Product {
+
+    private Long    id;         // 序号
+    private String  name;       // 商品名称
+    private Double 	price;      // 价格
+    private String  type;       // 类型
+
+    public Product() {
+    }
+
+    public Product(Long id, String name, Double price, String type) {
+        this.id = id;
+        this.name = name;
+        this.price = price;
+        this.type = type;
+    }
+
+    public Long getId() {
+        return id;
+    }
+
+    public void setId(Long id) {
+        this.id = id;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public Double getPrice() {
+        return price;
+    }
+
+    public void setPrice(Double price) {
+        this.price = price;
+    }
+
+    public String getType() {
+        return type;
+    }
+
+    public void setType(String type) {
+        this.type = type;
+    }
+
+    @Override
+    public String toString() {
+        return "Product{" +
+                "id=" + id +
+                ", name='" + name + '\'' +
+                ", price=" + price +
+                ", type='" + type + '\'' +
+                '}';
+    }
+}

+ 39 - 0
src/main/java/com/sf/day08/lambda/Te.java

@@ -0,0 +1,39 @@
+package com.sf.day08.lambda;
+
+import org.junit.Test;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class Te {
+
+    public static void main(String[] args) {
+        List<Product> productByPrice = findProductByPrice(Data.products);
+        System.out.println(productByPrice);
+        List<Product> productByName = findProductByName(Data.products);
+        System.out.println(productByName);
+    }
+
+
+    //  筛选出所有商品中价格大于1000的商品
+    public static List<Product>  findProductByPrice(List<Product> products){
+        List<Product> lists = new ArrayList<>();
+        for (Product product : products) {
+            if(product.getPrice() > 1000){
+                lists.add(product);
+            }
+        }
+        return lists;
+    }
+
+    //  筛选出所有名称包含手机的商品
+    public static List<Product>  findProductByName(List<Product> products){
+        List<Product> lists = new ArrayList<>();
+        for (Product product : products) {
+            if(product.getName().contains("手机")){
+                lists.add(product);
+            }
+        }
+        return lists;
+    }
+}

+ 35 - 0
src/main/java/com/sf/day08/lambda/Te2.java

@@ -0,0 +1,35 @@
+package com.sf.day08.lambda;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class Te2 {
+
+
+    public static void main(String[] args) {
+        //   手机名称
+        List<Product> list = findProductByCondition(Data.products, product -> product.getName().contains("手机"));
+        System.out.println(list);
+
+
+        //  价格
+        List<Product> productByCondition = findProductByCondition(Data.products, new MyPredicate() {
+            @Override
+            public boolean test(Product product) {
+                return product.getPrice() > 1000;
+            }
+        });
+        System.out.println(productByCondition);
+    }
+
+
+    public static List<Product> findProductByCondition(List<Product> lists,MyPredicate myPredicate){
+        List<Product> list = new ArrayList<>();
+        for (Product product : lists) {
+            if(myPredicate.test(product)){
+                list.add(product);
+            }
+        }
+        return list;
+    }
+}

TEMPAT SAMPAH
target/classes/com/sf/day07/homework/Apple.class


TEMPAT SAMPAH
target/classes/com/sf/day07/homework/CompareAble.class


TEMPAT SAMPAH
target/classes/com/sf/day07/homework/CompareBig.class


TEMPAT SAMPAH
target/classes/com/sf/day07/homework/CompareColor.class


TEMPAT SAMPAH
target/classes/com/sf/day07/homework/Person.class


TEMPAT SAMPAH
target/classes/com/sf/day07/homework/TestApple.class


TEMPAT SAMPAH
target/classes/com/sf/day07/lx/BuildCarsInterface2.class


TEMPAT SAMPAH
target/classes/com/sf/day07/lx/BuildCarsInterfaceImpl.class


TEMPAT SAMPAH
target/classes/com/sf/day08/Circle.class


TEMPAT SAMPAH
target/classes/com/sf/day08/FightAble.class


TEMPAT SAMPAH
target/classes/com/sf/day08/Mage.class


TEMPAT SAMPAH
target/classes/com/sf/day08/Player.class


TEMPAT SAMPAH
target/classes/com/sf/day08/Rectangle.class


TEMPAT SAMPAH
target/classes/com/sf/day08/ShapeInterface.class


TEMPAT SAMPAH
target/classes/com/sf/day08/Te.class


TEMPAT SAMPAH
target/classes/com/sf/day08/Triangle.class


TEMPAT SAMPAH
target/classes/com/sf/day08/Warrior.class


TEMPAT SAMPAH
target/classes/com/sf/day08/apple/Apple.class


TEMPAT SAMPAH
target/classes/com/sf/day08/apple/CompareAble.class


TEMPAT SAMPAH
target/classes/com/sf/day08/apple/CompareBig.class


TEMPAT SAMPAH
target/classes/com/sf/day08/apple/CompareColor.class


TEMPAT SAMPAH
target/classes/com/sf/day08/apple/Worker.class


TEMPAT SAMPAH
target/classes/com/sf/day08/flay/Bird.class


TEMPAT SAMPAH
target/classes/com/sf/day08/flay/Chicken.class


TEMPAT SAMPAH
target/classes/com/sf/day08/flay/Flyable.class


TEMPAT SAMPAH
target/classes/com/sf/day08/flay/Penguin.class


TEMPAT SAMPAH
target/classes/com/sf/day08/flay/Swan.class


TEMPAT SAMPAH
target/classes/com/sf/day08/flay/Swimming.class


TEMPAT SAMPAH
target/classes/com/sf/day08/innerclass/Demo$1.class


TEMPAT SAMPAH
target/classes/com/sf/day08/innerclass/Demo$2.class


TEMPAT SAMPAH
target/classes/com/sf/day08/innerclass/Demo.class


TEMPAT SAMPAH
target/classes/com/sf/day08/innerclass/Outer01$inner01.class


TEMPAT SAMPAH
target/classes/com/sf/day08/innerclass/Outer01.class


TEMPAT SAMPAH
target/classes/com/sf/day08/innerclass/Outer02$Inner02.class


TEMPAT SAMPAH
target/classes/com/sf/day08/innerclass/Outer02.class


TEMPAT SAMPAH
target/classes/com/sf/day08/innerclass/OuterClass$1LocalInnerClass.class


TEMPAT SAMPAH
target/classes/com/sf/day08/innerclass/OuterClass.class


TEMPAT SAMPAH
target/classes/com/sf/day08/innerclass/Student.class


TEMPAT SAMPAH
target/classes/com/sf/day08/innerclass/Swim$1.class


TEMPAT SAMPAH
target/classes/com/sf/day08/innerclass/Swim.class


TEMPAT SAMPAH
target/classes/com/sf/day08/lambda/Data.class


TEMPAT SAMPAH
target/classes/com/sf/day08/lambda/MyPredicate.class


TEMPAT SAMPAH
target/classes/com/sf/day08/lambda/Product.class


TEMPAT SAMPAH
target/classes/com/sf/day08/lambda/Te.class


TEMPAT SAMPAH
target/classes/com/sf/day08/lambda/Te2$1.class


TEMPAT SAMPAH
target/classes/com/sf/day08/lambda/Te2$2.class


TEMPAT SAMPAH
target/classes/com/sf/day08/lambda/Te2.class