瀏覽代碼

day11 和day12 代码

fjl123 9 月之前
父節點
當前提交
2c81f9b14a
共有 46 個文件被更改,包括 1053 次插入0 次删除
  1. 二進制
      product.dat
  2. 9 0
      src/main/java/com/sf/day11/_01_interface_def/IEatAble.java
  3. 12 0
      src/main/java/com/sf/day11/_01_interface_def/ISwimable.java
  4. 20 0
      src/main/java/com/sf/day11/_01_interface_def/IWalkable.java
  5. 25 0
      src/main/java/com/sf/day11/_01_interface_def/impl/DogWalkableImpl.java
  6. 42 0
      src/main/java/com/sf/day11/_01_interface_def/impl/PersonWalkableImpl.java
  7. 30 0
      src/main/java/com/sf/day11/_01_interface_def/test/InterfaceTest.java
  8. 8 0
      src/main/java/com/sf/day11/_02_interface_practice/ISwimAble.java
  9. 19 0
      src/main/java/com/sf/day11/_02_interface_practice/dt/Dog.java
  10. 18 0
      src/main/java/com/sf/day11/_02_interface_practice/dt/Frog.java
  11. 20 0
      src/main/java/com/sf/day11/_02_interface_practice/dt/Pet.java
  12. 11 0
      src/main/java/com/sf/day11/_02_interface_practice/dt/Rabbit.java
  13. 19 0
      src/main/java/com/sf/day11/_02_interface_practice/test/Test.java
  14. 9 0
      src/main/java/com/sf/day11/_03_polymorphic/ISwimAble.java
  15. 18 0
      src/main/java/com/sf/day11/_03_polymorphic/dt/Anmail.java
  16. 15 0
      src/main/java/com/sf/day11/_03_polymorphic/dt/Cat.java
  17. 22 0
      src/main/java/com/sf/day11/_03_polymorphic/dt/Dog.java
  18. 37 0
      src/main/java/com/sf/day11/_03_polymorphic/test/Test.java
  19. 12 0
      src/main/java/com/sf/day12/_01_type_conver/Anmail.java
  20. 15 0
      src/main/java/com/sf/day12/_01_type_conver/Cat.java
  21. 15 0
      src/main/java/com/sf/day12/_01_type_conver/Dog.java
  22. 7 0
      src/main/java/com/sf/day12/_01_type_conver/IFunAble.java
  23. 16 0
      src/main/java/com/sf/day12/_01_type_conver/Person.java
  24. 42 0
      src/main/java/com/sf/day12/_01_type_conver/Test.java
  25. 9 0
      src/main/java/com/sf/day12/_02_usb_contact/IUSBAble.java
  26. 10 0
      src/main/java/com/sf/day12/_02_usb_contact/Keyboard.java
  27. 23 0
      src/main/java/com/sf/day12/_02_usb_contact/MotherBoard.java
  28. 11 0
      src/main/java/com/sf/day12/_02_usb_contact/Mouse.java
  29. 13 0
      src/main/java/com/sf/day12/_02_usb_contact/Test.java
  30. 23 0
      src/main/java/com/sf/day12/_03_interface_contact/IFunctionAble.java
  31. 23 0
      src/main/java/com/sf/day12/_03_interface_contact/Test1.java
  32. 26 0
      src/main/java/com/sf/day12/_03_interface_contact/dt/Circle.java
  33. 38 0
      src/main/java/com/sf/day12/_03_interface_contact/dt/Department.java
  34. 36 0
      src/main/java/com/sf/day12/_03_interface_contact/dt/Rectangle.java
  35. 9 0
      src/main/java/com/sf/day12/_03_interface_contact/dt/Shape.java
  36. 62 0
      src/main/java/com/sf/day12/_03_interface_contact/impl/FunctionAbleImpl.java
  37. 43 0
      src/main/java/com/sf/day12/_03_interface_contact/test/Test.java
  38. 52 0
      src/main/java/com/sf/day12/_04_this/Student.java
  39. 18 0
      src/main/java/com/sf/day12/_04_this/Test.java
  40. 40 0
      src/main/java/com/sf/day12/_05_super/Person.java
  41. 31 0
      src/main/java/com/sf/day12/_05_super/Student.java
  42. 16 0
      src/main/java/com/sf/day12/_05_super/Test.java
  43. 25 0
      src/main/java/com/sf/day12/_06_static/AjaxResult.java
  44. 22 0
      src/main/java/com/sf/day12/_06_static/JsonResult.java
  45. 43 0
      src/main/java/com/sf/day12/_06_static/Person.java
  46. 39 0
      src/main/java/com/sf/day12/_06_static/Test.java

二進制
product.dat


+ 9 - 0
src/main/java/com/sf/day11/_01_interface_def/IEatAble.java

@@ -0,0 +1,9 @@
+package com.sf.day11._01_interface_def;
+
+/**
+ * create By  fjl
+ */
+public interface IEatAble {
+
+    void eat();
+}

+ 12 - 0
src/main/java/com/sf/day11/_01_interface_def/ISwimable.java

@@ -0,0 +1,12 @@
+package com.sf.day11._01_interface_def;
+
+/**
+ * create By  fjl
+ */
+public interface ISwimable extends IEatAble {
+
+    /**
+     * 定义有用方法
+     */
+    void swim();
+}

+ 20 - 0
src/main/java/com/sf/day11/_01_interface_def/IWalkable.java

@@ -0,0 +1,20 @@
+package com.sf.day11._01_interface_def;
+
+/**
+ * create By  fjl
+ */
+
+/**
+ * 接口: 是一个规范
+ *
+ * 一般在接口当中定义一些抽象方法, 这些方法具体实现交给实现类去进行视线
+ */
+public interface IWalkable extends IEatAble{
+
+    /**
+     * 定义接口抽象方法
+     *
+     */
+    void walk();
+
+}

+ 25 - 0
src/main/java/com/sf/day11/_01_interface_def/impl/DogWalkableImpl.java

@@ -0,0 +1,25 @@
+package com.sf.day11._01_interface_def.impl;
+
+import com.sf.day11._01_interface_def.ISwimable;
+import com.sf.day11._01_interface_def.IWalkable;
+
+/**
+ * create By  fjl
+ */
+public class DogWalkableImpl implements IWalkable, ISwimable {
+
+    @Override
+    public void walk() {
+        System.out.println("狗走路");
+    }
+
+    @Override
+    public void swim() {
+        System.out.println("狗刨");
+    }
+
+    @Override
+    public void eat() {
+        System.out.println("吃骨头");
+    }
+}

+ 42 - 0
src/main/java/com/sf/day11/_01_interface_def/impl/PersonWalkableImpl.java

@@ -0,0 +1,42 @@
+package com.sf.day11._01_interface_def.impl;
+
+import com.sf.day11._01_interface_def.ISwimable;
+import com.sf.day11._01_interface_def.IWalkable;
+
+/**
+ * create By  fjl
+ * 问:  这个类此时和接口有关系吗?
+ * 没有关系
+ *
+ * 问: 如何让类和接口有实现
+ * 使用implments 让他们有实现关系
+ *
+ * 问: 一个接口只能够有一个实现类吗?
+ * 答 接口可以有多个实现
+ *
+ * 问: 一个可不可以实现多个接口
+ * 一个类可以实现多个接口
+ *
+ * 问: 接口与接口之间关系
+ * 答 继承
+ *
+ *
+ *
+ */
+public class PersonWalkableImpl implements IWalkable, ISwimable {
+
+    @Override
+    public void walk() {
+        System.out.println("人散步");
+    }
+
+    @Override
+    public void swim() {
+        System.out.println("蛙泳");
+    }
+
+    @Override
+    public void eat() {
+        System.out.println("吃肉 吃面");
+    }
+}

+ 30 - 0
src/main/java/com/sf/day11/_01_interface_def/test/InterfaceTest.java

@@ -0,0 +1,30 @@
+package com.sf.day11._01_interface_def.test;
+
+import com.sf.day11._01_interface_def.IWalkable;
+import com.sf.day11._01_interface_def.impl.DogWalkableImpl;
+import com.sf.day11._01_interface_def.impl.PersonWalkableImpl;
+
+/**
+ * create By  fjl
+ */
+public class InterfaceTest {
+
+    public static void main(String[] args) {
+        /**
+         * 想要调用DogWalableImpl 当中walk 方法
+         * 如何操作?
+         * 这是一个类, 类当中方法: 静态方法 , 实例方法
+         * 实例方法: 对象.方法名()
+         */
+        DogWalkableImpl impl = new DogWalkableImpl();
+        impl.walk();
+
+        // 相同需求: 调用PersonWalkabaleImpl 当中walk 方法
+        PersonWalkableImpl personWalkableImpl = new PersonWalkableImpl();
+        personWalkableImpl.walk();
+
+        // 后面我们用的更多一种调用方式
+        IWalkable walkable = new PersonWalkableImpl();
+        walkable.walk();
+    }
+}

+ 8 - 0
src/main/java/com/sf/day11/_02_interface_practice/ISwimAble.java

@@ -0,0 +1,8 @@
+package com.sf.day11._02_interface_practice;
+
+/**
+ * create By  fjl
+ */
+public interface ISwimAble {
+    void swimg();
+}

+ 19 - 0
src/main/java/com/sf/day11/_02_interface_practice/dt/Dog.java

@@ -0,0 +1,19 @@
+package com.sf.day11._02_interface_practice.dt;
+
+import com.sf.day11._01_interface_def.ISwimable;
+import com.sun.scenario.effect.impl.sw.sse.SSEBlend_SRC_OUTPeer;
+
+/**
+ * create By  fjl
+ */
+public class Dog extends Pet implements ISwimable {
+    @Override
+    public void eat() {
+        System.out.println("吃骨头");
+    }
+
+    @Override
+    public void swim() {
+        System.out.println("狗刨");
+    }
+}

+ 18 - 0
src/main/java/com/sf/day11/_02_interface_practice/dt/Frog.java

@@ -0,0 +1,18 @@
+package com.sf.day11._02_interface_practice.dt;
+
+import com.sf.day11._01_interface_def.ISwimable;
+
+/**
+ * create By  fjl
+ */
+public class Frog extends Pet implements ISwimable {
+    @Override
+    public void eat() {
+        System.out.println("吃昆虫");
+    }
+
+    @Override
+    public void swim() {
+        System.out.println("蛙泳");
+    }
+}

+ 20 - 0
src/main/java/com/sf/day11/_02_interface_practice/dt/Pet.java

@@ -0,0 +1,20 @@
+package com.sf.day11._02_interface_practice.dt;
+
+/**
+ * create By  fjl
+ */
+public abstract class Pet {
+    private String name;
+
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public abstract void eat();
+
+}

+ 11 - 0
src/main/java/com/sf/day11/_02_interface_practice/dt/Rabbit.java

@@ -0,0 +1,11 @@
+package com.sf.day11._02_interface_practice.dt;
+
+/**
+ * create By  fjl
+ */
+public class Rabbit extends Pet {
+    @Override
+    public void eat() {
+        System.out.println("吃胡萝卜");
+    }
+}

+ 19 - 0
src/main/java/com/sf/day11/_02_interface_practice/test/Test.java

@@ -0,0 +1,19 @@
+package com.sf.day11._02_interface_practice.test;
+
+import com.sf.day11._01_interface_def.ISwimable;
+import com.sf.day11._02_interface_practice.dt.Dog;
+import com.sf.day11._02_interface_practice.dt.Frog;
+
+/**
+ * create By  fjl
+ */
+public class Test {
+
+    public static void main(String[] args) {
+        ISwimable swimable = new Dog();
+        swimable.swim();
+
+        ISwimable swimable1 = new Frog();
+        swimable1.swim();
+    }
+}

+ 9 - 0
src/main/java/com/sf/day11/_03_polymorphic/ISwimAble.java

@@ -0,0 +1,9 @@
+package com.sf.day11._03_polymorphic;
+
+/**
+ * create By  fjl
+ */
+public interface ISwimAble {
+
+    void  swim();
+}

+ 18 - 0
src/main/java/com/sf/day11/_03_polymorphic/dt/Anmail.java

@@ -0,0 +1,18 @@
+package com.sf.day11._03_polymorphic.dt;
+
+/**
+ * create By  fjl
+ */
+public abstract class Anmail {
+    private String name;
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public abstract void eat();
+}

+ 15 - 0
src/main/java/com/sf/day11/_03_polymorphic/dt/Cat.java

@@ -0,0 +1,15 @@
+package com.sf.day11._03_polymorphic.dt;
+
+/**
+ * create By  fjl
+ */
+public class Cat extends Anmail {
+    @Override
+    public void eat() {
+        System.out.println("吃鱼");
+    }
+
+    public void catchTo(){
+        System.out.println("抓老鼠");
+    }
+}

+ 22 - 0
src/main/java/com/sf/day11/_03_polymorphic/dt/Dog.java

@@ -0,0 +1,22 @@
+package com.sf.day11._03_polymorphic.dt;
+
+import com.sf.day11._03_polymorphic.ISwimAble;
+
+/**
+ * create By  fjl
+ */
+public class Dog extends Anmail implements ISwimAble {
+    @Override
+    public void eat() {
+        System.out.println("吃骨头");
+    }
+
+    @Override
+    public void swim() {
+        System.out.println("狗游泳");
+    }
+
+    public void houseKeeping(){
+        System.out.println("看家");
+    }
+}

+ 37 - 0
src/main/java/com/sf/day11/_03_polymorphic/test/Test.java

@@ -0,0 +1,37 @@
+package com.sf.day11._03_polymorphic.test;
+
+import com.sf.day11._03_polymorphic.ISwimAble;
+import com.sf.day11._03_polymorphic.dt.Anmail;
+import com.sf.day11._03_polymorphic.dt.Cat;
+import com.sf.day11._03_polymorphic.dt.Dog;
+
+/**
+ * create By  fjl
+ */
+public class Test {
+    public static void main(String[] args) {
+        // 需求: 分别调用子类当中eat 方法
+        // 调用方式2中: 1种 直接创建子类, 调用子类当中方法
+        //            2种 父类 f = new 子类();
+
+        // 调用方法运行时期, 调用是子类的方法
+        Anmail anmail = new Dog();
+        anmail.eat();
+
+        Anmail anmail1 = new Cat();
+        anmail1.eat();
+
+        // 接口多态语法
+        // 接口 名字 = new 接口实现类();
+        ISwimAble swimAble = new Dog();
+        swimAble.swim();
+
+        // 想要调用dog 看家的方法要求不能够自己new dog 对象
+        // 把Anmail 类型转换成了Dog 类型
+        Dog dog = (Dog) anmail;
+        Cat cat  = (Cat) anmail1;
+        dog.houseKeeping();
+        //思考:  出错原因是什么?
+        cat.catchTo();
+    }
+}

+ 12 - 0
src/main/java/com/sf/day12/_01_type_conver/Anmail.java

@@ -0,0 +1,12 @@
+package com.sf.day12._01_type_conver;
+
+/**
+ * create By  fjl
+ */
+public abstract class Anmail {
+    private String name;
+
+    public abstract void eat();
+
+    public void slepp(){}
+}

+ 15 - 0
src/main/java/com/sf/day12/_01_type_conver/Cat.java

@@ -0,0 +1,15 @@
+package com.sf.day12._01_type_conver;
+
+/**
+ * create By  fjl
+ */
+public class Cat extends Anmail {
+    @Override
+    public void eat() {
+        System.out.println("吃鱼");
+    }
+
+    public void catchToMouse(){
+        System.out.println("抓老鼠");
+    }
+}

+ 15 - 0
src/main/java/com/sf/day12/_01_type_conver/Dog.java

@@ -0,0 +1,15 @@
+package com.sf.day12._01_type_conver;
+
+/**
+ * create By  fjl
+ */
+public class Dog extends Anmail {
+    @Override
+    public void eat() {
+        System.out.println("吃骨头");
+    }
+
+    public void lookHome(){
+        System.out.println("看家");
+    }
+}

+ 7 - 0
src/main/java/com/sf/day12/_01_type_conver/IFunAble.java

@@ -0,0 +1,7 @@
+package com.sf.day12._01_type_conver;
+
+/**
+ * create By  fjl
+ */
+public interface IFunAble {
+}

+ 16 - 0
src/main/java/com/sf/day12/_01_type_conver/Person.java

@@ -0,0 +1,16 @@
+package com.sf.day12._01_type_conver;
+
+/**
+ * create By  fjl
+ */
+public class Person {
+
+    public void playPet(Anmail anmail){
+        if(anmail instanceof Cat){
+            System.out.println("陪猫玩");
+        }else if(anmail instanceof Dog){
+            System.out.println("陪狗玩");
+        }
+
+    }
+}

+ 42 - 0
src/main/java/com/sf/day12/_01_type_conver/Test.java

@@ -0,0 +1,42 @@
+package com.sf.day12._01_type_conver;
+
+/**
+ * create By  fjl
+ */
+public class Test {
+    public static void main(String[] args) {
+        // 需求1 : 先调用dog eat 方法要求用多态
+//        Anmail anmail = new Dog();   // 真实类型dog
+//        anmail.eat();
+//        // 需求2 : 调用dog 看家方法
+//        // 为啥不可以: 因为编译时期会上父类当中寻找方法, 招不到就爆红
+//        // 解决: 进行类型转换
+//        //想要调用dog 方法
+//        Dog dog = (Dog) anmail;
+//        dog.lookHome();
+//
+//        // 需求: 调用cat 当中抓老鼠的方法
+////        Cat cat = (Cat) anmail;
+//        Anmail anmail1 = new Cat();  // 真实类型cat
+//        Cat cat = (Cat) anmail1;
+//        cat.catchToMouse();
+//
+//        // instalceof
+//        /**
+//         * 简单理解  判断他的真实类型是什么 , 如果符合返回true 如果不符合返回false
+//         */
+//        System.out.println(anmail instanceof Dog);   //true
+//        System.out.println(anmail1 instanceof Cat);  //true
+//        System.out.println(anmail instanceof Cat);   //false
+
+
+        // 要求: 要求定义一个Person 类 , person 类中有一个playPet(参数) ,
+        // 要求如果传递的狗就打印陪狗玩,如果是猫就打印陪猫玩
+        // 关键点方法参数如何设计, 如何判断他是猫还是狗  instanceof
+        Cat cat = new Cat();
+        Dog dog = new Dog();
+        Person p = new Person();
+//        p.playPet(cat);
+        p.playPet(dog);
+    }
+}

+ 9 - 0
src/main/java/com/sf/day12/_02_usb_contact/IUSBAble.java

@@ -0,0 +1,9 @@
+package com.sf.day12._02_usb_contact;
+
+/**
+ * create By  fjl
+ */
+public interface IUSBAble {
+
+    void work();
+}

+ 10 - 0
src/main/java/com/sf/day12/_02_usb_contact/Keyboard.java

@@ -0,0 +1,10 @@
+package com.sf.day12._02_usb_contact;
+
+/**
+ * create By  fjl
+ */
+public class Keyboard implements IUSBAble{
+    public void work(){
+        System.out.println("键盘在打印");
+    }
+}

+ 23 - 0
src/main/java/com/sf/day12/_02_usb_contact/MotherBoard.java

@@ -0,0 +1,23 @@
+package com.sf.day12._02_usb_contact;
+
+/**
+ * create By  fjl
+ */
+public class MotherBoard {
+
+    /**
+     * 主办要插入键盘和鼠标
+     * 假设现在没有统一规范 , 就好比没有USB接口, 各个厂商按照自己习惯去制造借口
+     */
+//
+//    public void plugin(Mouse mouse){
+//        mouse.work();
+//    }
+//
+//    public void plugin(Keyboard keyboard){
+//        keyboard.work();
+//    }
+    public void plugin(IUSBAble iusbAble){
+        iusbAble.work();
+    }
+}

+ 11 - 0
src/main/java/com/sf/day12/_02_usb_contact/Mouse.java

@@ -0,0 +1,11 @@
+package com.sf.day12._02_usb_contact;
+
+/**
+ * create By  fjl
+ */
+public class Mouse implements IUSBAble {
+
+    public void work(){
+        System.out.println("鼠标在移动");
+    }
+}

+ 13 - 0
src/main/java/com/sf/day12/_02_usb_contact/Test.java

@@ -0,0 +1,13 @@
+package com.sf.day12._02_usb_contact;
+
+/**
+ * create By  fjl
+ */
+public class Test {
+    public static void main(String[] args) {
+        Mouse mouse = new Mouse();
+        MotherBoard motherBoard = new MotherBoard();
+        motherBoard.plugin(mouse);
+        motherBoard.plugin(new Keyboard());
+    }
+}

+ 23 - 0
src/main/java/com/sf/day12/_03_interface_contact/IFunctionAble.java

@@ -0,0 +1,23 @@
+package com.sf.day12._03_interface_contact;
+
+/**
+ * create By  fjl
+ */
+public interface IFunctionAble {
+
+    /**
+     * 检查用户名是否存在
+     */
+    boolean checkByUsername(String username);
+
+    /**
+     * 登录方法
+     */
+
+    void login(String username,String password);
+
+    /**
+     * 注册方法
+     */
+    void register(String name,String sn);
+}

+ 23 - 0
src/main/java/com/sf/day12/_03_interface_contact/Test1.java

@@ -0,0 +1,23 @@
+package com.sf.day12._03_interface_contact;
+
+import com.sf.day12._03_interface_contact.dt.Circle;
+import com.sf.day12._03_interface_contact.dt.Department;
+import com.sf.day12._03_interface_contact.dt.Rectangle;
+import com.sf.day12._03_interface_contact.dt.Shape;
+
+/**
+ * create By  fjl
+ */
+public class Test1 {
+    public static void main(String[] args) {
+        Shape shape = new Circle(3);
+        shape.calculateArea();
+
+        Shape shape1 = new Rectangle(3,4);
+        shape1.calculateArea();
+        while (true){
+            Department department = new Department("123","!23");
+
+        }
+    }
+}

+ 26 - 0
src/main/java/com/sf/day12/_03_interface_contact/dt/Circle.java

@@ -0,0 +1,26 @@
+package com.sf.day12._03_interface_contact.dt;
+
+/**
+ * create By  fjl
+ */
+public class Circle extends Shape {
+    private double radius;
+
+    public Circle(double radius) {
+        this.radius = radius;
+    }
+
+    public double getRadius() {
+        return radius;
+    }
+
+    public void setRadius(double radius) {
+        this.radius = radius;
+    }
+
+    @Override
+    public void calculateArea() {
+        double v = Math.PI * Math.pow(radius, 2);
+        System.out.println(v);
+    }
+}

+ 38 - 0
src/main/java/com/sf/day12/_03_interface_contact/dt/Department.java

@@ -0,0 +1,38 @@
+package com.sf.day12._03_interface_contact.dt;
+
+/**
+ * create By  fjl
+ */
+public class Department {
+    private String name;
+    private String sn;
+
+    public Department(String name, String sn) {
+        this.name = name;
+        this.sn = sn;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    @Override
+    public String toString() {
+        return "Department{" +
+                "name='" + name + '\'' +
+                ", sn='" + sn + '\'' +
+                '}';
+    }
+
+    public String getSn() {
+        return sn;
+    }
+
+    public void setSn(String sn) {
+        this.sn = sn;
+    }
+}

+ 36 - 0
src/main/java/com/sf/day12/_03_interface_contact/dt/Rectangle.java

@@ -0,0 +1,36 @@
+package com.sf.day12._03_interface_contact.dt;
+
+/**
+ * create By  fjl
+ */
+public class Rectangle extends Shape {
+    private double weigth;
+    private double heigth;
+
+    public Rectangle(double weigth, double heigth) {
+        this.weigth = weigth;
+        this.heigth = heigth;
+    }
+
+    public double getWeigth() {
+        return weigth;
+    }
+
+    public void setWeigth(double weigth) {
+        this.weigth = weigth;
+    }
+
+    public double getHeigth() {
+        return heigth;
+    }
+
+    public void setHeigth(double heigth) {
+        this.heigth = heigth;
+    }
+
+    @Override
+    public void calculateArea() {
+        double area = this.weigth * this.heigth;
+        System.out.println(area);
+    }
+}

+ 9 - 0
src/main/java/com/sf/day12/_03_interface_contact/dt/Shape.java

@@ -0,0 +1,9 @@
+package com.sf.day12._03_interface_contact.dt;
+
+/**
+ * create By  fjl
+ */
+public abstract class Shape {
+
+    public abstract void calculateArea();
+}

+ 62 - 0
src/main/java/com/sf/day12/_03_interface_contact/impl/FunctionAbleImpl.java

@@ -0,0 +1,62 @@
+package com.sf.day12._03_interface_contact.impl;
+
+import com.sf.day12._03_interface_contact.IFunctionAble;
+import com.sf.day12._03_interface_contact.dt.Department;
+
+/**
+ * create By  fjl
+ */
+public class FunctionAbleImpl implements IFunctionAble {
+
+    @Override
+    public boolean checkByUsername(String username) {
+        // 判断数组当中是否包含username 如果包含的话返回true ,如果不包含返回false
+        // 1 定义一个数组
+        String[] arr = {"admin","root","test"};
+        // 2 如何判断数组当中是否元素呢?
+        // 解决: 遍历数组,可以拿到数组当中每一个元素,拿方法参数和数组当中元素进行对比
+        // 如果相等表示他在数组当中, 如果没有呢表示不在我们数组中返回false
+        for (int i = 0; i < arr.length; i++) {
+            String item = arr[i];
+            if(item.equals(username)){
+                return true;
+            }
+        }
+        return false;
+    }
+
+    @Override
+    public void login(String username, String password) {
+        //1 判断账号密码是否否null
+        if(username==null || password==null){
+            System.out.println("账号或者密码不能为空");
+            return;
+        }
+        //2 判断用户名是否存在
+        boolean flag = checkByUsername(username);
+        if(!flag){
+            System.out.println("账号不存在");
+            return;
+        }
+        //3 判断账号是否为admin 密码是否为123
+        if("admin".equals(username) && "123".equals(password)){
+            System.out.println("登录成功");
+        }else{
+            System.out.println("账号密码错误");
+        }
+    }
+
+    @Override
+    public void register(String name, String sn) {
+        // 1 判断name 和sn 不能为空
+        if(name ==null || sn == null){
+            System.out.println("name 和sn 不能为空");
+        }
+        // 2 如果不为空吧name 和sn 封装到department 对象当中
+        Department department = new Department(name,sn);
+        // 3 打印department 对象
+        // object 是所有对象最顶层父类,在打印的时候默认是调用Object当中toString()方法
+        // 默认打印是对象地址值
+        System.out.println(department);
+    }
+}

+ 43 - 0
src/main/java/com/sf/day12/_03_interface_contact/test/Test.java

@@ -0,0 +1,43 @@
+package com.sf.day12._03_interface_contact.test;
+
+import com.sf.day12._03_interface_contact.IFunctionAble;
+import com.sf.day12._03_interface_contact.impl.FunctionAbleImpl;
+
+import java.util.Scanner;
+
+/**
+ * create By  fjl
+ */
+public class Test {
+
+    public static void main(String[] args) {
+//        Scanner scanner = new Scanner(System.in);
+//
+//        IFunctionAble functionAble = new FunctionAbleImpl();
+//        while (true){
+//            System.out.println("请输入用户名:");
+//            String username = scanner.nextLine();
+//            boolean flag = functionAble.checkByUsername(username);
+//            if(flag){
+//                System.out.println("用户存在");
+//                break;
+//            }
+//        }
+//        System.out.println("结束");
+
+        IFunctionAble able = new FunctionAbleImpl();
+//        able.login("admin","123123");
+        Scanner scanner = new Scanner(System.in);
+        System.out.println("请输入部门的名称:");
+        String name = scanner.nextLine();
+        System.out.println("请输入部门的sn:");
+        String sn = scanner.nextLine();
+
+        // 调用接口当中注册方法
+        able.register(name,sn);
+
+
+
+
+    }
+}

+ 52 - 0
src/main/java/com/sf/day12/_04_this/Student.java

@@ -0,0 +1,52 @@
+package com.sf.day12._04_this;
+
+/**
+ * create By  fjl
+ */
+public class Student {
+    private String name;
+    private int age;
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    @Override
+    public String toString() {
+        return "Student{" +
+                "name='" + name + '\'' +
+                ", age=" + age +
+                '}';
+    }
+
+    public int getAge() {
+        return age;
+    }
+
+    public void setAge(int age) {
+        this.age = age;
+    }
+
+    public Student() {
+    }
+
+    public Student(String name){
+//        this.name = name;
+        this(name,18);
+    }
+
+    public Student(String name, int age) {
+        // 场景1 解决局部变量和成员变量同名赋值问题
+//        this.showInfo();
+        this.name = name;
+        this.age = age;
+    }
+
+    public void showInfo(){
+        System.out.println("打印信息");
+    }
+}

+ 18 - 0
src/main/java/com/sf/day12/_04_this/Test.java

@@ -0,0 +1,18 @@
+package com.sf.day12._04_this;
+
+/**
+ * create By  fjl
+ */
+public class Test {
+
+    public static void main(String[] args) {
+//        Student student = new Student();
+//        System.out.println(student);
+        // 构造器 在new 的时候会被调用
+//        Student student = new Student("test",10);
+        // new Student 的时候如果不传入年龄 默认年龄是18岁,名称必须要传递
+        Student student = new Student("test");
+        System.out.println(student);
+    }
+
+}

+ 40 - 0
src/main/java/com/sf/day12/_05_super/Person.java

@@ -0,0 +1,40 @@
+package com.sf.day12._05_super;
+
+/**
+ * create By  fjl
+ */
+public class Person {
+    private String name;
+    private int age;
+
+
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public int getAge() {
+        return age;
+    }
+
+    public void setAge(int age) {
+        this.age = age;
+    }
+
+    public Person(String name, int age) {
+        this.name = name;
+        this.age = age;
+    }
+
+    public Person() {
+    }
+
+    public void showInfo(){
+        System.out.println("名称为:"+ this.name);
+        System.out.println("年龄为:"+ this.age);
+    }
+}

+ 31 - 0
src/main/java/com/sf/day12/_05_super/Student.java

@@ -0,0 +1,31 @@
+package com.sf.day12._05_super;
+
+/**
+ * create By  fjl
+ */
+public class Student extends Person {
+    private String sn;
+
+    public Student() {
+    }
+
+    public Student(String name,int age,String sn){
+        // 要求一会再new Student("zhangsan",10,"01");
+        super(name,age);
+        this.sn = sn;
+    }
+
+    @Override
+    public String toString() {
+        return "Student{" +
+                "sn='" + sn + '\'' +
+
+                '}';
+    }
+
+    public void show(){
+        // 打印name sn age
+        super.showInfo();
+        System.out.println("sn值为:"+ this.sn);
+    }
+}

+ 16 - 0
src/main/java/com/sf/day12/_05_super/Test.java

@@ -0,0 +1,16 @@
+package com.sf.day12._05_super;
+
+/**
+ * create By  fjl
+ */
+public class Test {
+
+    public static void main(String[] args) {
+        Student student = new Student("xiaozhang",10,"01");
+
+        // 要在student 当中定义一个show方法 , 在这方法需要打印出来name,age,sn
+        student.show();
+    }
+
+
+}

+ 25 - 0
src/main/java/com/sf/day12/_06_static/AjaxResult.java

@@ -0,0 +1,25 @@
+package com.sf.day12._06_static;
+
+/**
+ * create By  fjl
+ */
+public class AjaxResult {
+    private boolean success;
+    private String msg;
+
+    public AjaxResult() {
+    }
+
+    public AjaxResult(boolean success, String msg) {
+        this.success = success;
+        this.msg = msg;
+    }
+
+    @Override
+    public String toString() {
+        return "AjaxResult{" +
+                "success=" + success +
+                ", msg='" + msg + '\'' +
+                '}';
+    }
+}

+ 22 - 0
src/main/java/com/sf/day12/_06_static/JsonResult.java

@@ -0,0 +1,22 @@
+package com.sf.day12._06_static;
+
+/**
+ * create By  fjl
+ */
+public class JsonResult {
+
+    private JsonResult(){}
+
+
+    /**
+     * success 成功: AjaxReuslt(success=true,msg="操作成功")
+     * fail  失败: AjaxResult(success=false,msg="操作失败")
+     */
+    public static AjaxResult success(){
+        return new AjaxResult(true,"操作成功");
+    }
+
+    public static AjaxResult fail(){
+        return new AjaxResult(false,"操作失败");
+    }
+}

+ 43 - 0
src/main/java/com/sf/day12/_06_static/Person.java

@@ -0,0 +1,43 @@
+package com.sf.day12._06_static;
+
+/**
+ * create By  fjl
+ */
+public class Person {
+
+    // 成员变量
+    private String name;
+    private int age;
+
+    // 静态变量
+    public static String st;
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public int getAge() {
+        return age;
+    }
+
+    public void setAge(int age) {
+        this.age = age;
+    }
+
+    public static String getSt() {
+        return st;
+    }
+
+    public static void setSt(String st) {
+        Person.st = st;
+    }
+
+
+    public static void eat(){
+        System.out.println("吃东西");
+    }
+}

+ 39 - 0
src/main/java/com/sf/day12/_06_static/Test.java

@@ -0,0 +1,39 @@
+package com.sf.day12._06_static;
+
+import java.util.Arrays;
+
+/**
+ * create By  fjl
+ */
+public class Test {
+
+    public static void main(String[] args) {
+        // 两种方式
+        // 方式1  类名.属性名    方式2: 对象.属性名
+//        Person.st = "123";
+//        System.out.println(Person.st);
+
+//        Person person = new Person();
+//        person.st = "123";
+//        System.out.println(person.st);
+
+        // 调用静态方法 两种方式  方式1: 类名.方法名 调用  方式2: 对象.方法名
+//        Person.eat();
+
+        //  以后我们用到的很多工具类他们提供方法都是静态方法
+        //  有一些情况我们需要自己去封装一些工具类 .
+        /**
+         * 需求: 封装一个工具类
+         *
+         * 工具类名字 JsonResult
+         *  里面要有两个方法 : 一个success 方法 一个是fail 方法
+         *  要求返回值 成功返回 对象AjaxResult(success=true,msg="操作成功")
+         *           失败返回 对象AjaxResult(success=false,msg="操作失败")
+         *  要求工具类当中方法都是静态的
+         *
+         */
+
+        AjaxResult fail = JsonResult.fail();
+        System.out.println(fail);
+    }
+}