Procházet zdrojové kódy

day17代码 day18 day19

fanjialong před 14 hodinami
rodič
revize
92e329b5b2
55 změnil soubory, kde provedl 3243 přidání a 0 odebrání
  1. 11 0
      java-base-project10/day17/day17.iml
  2. 14 0
      java-base-project10/day17/src/com/sf/_01_uuid_code/Test.java
  3. 68 0
      java-base-project10/day17/src/com/sf/_02_list/demo1/Employee.java
  4. 40 0
      java-base-project10/day17/src/com/sf/_02_list/demo1/Test.java
  5. 113 0
      java-base-project10/day17/src/com/sf/_02_list/demo2/Goods.java
  6. 65 0
      java-base-project10/day17/src/com/sf/_02_list/demo2/Test.java
  7. 87 0
      java-base-project10/day17/src/com/sf/_02_list/demo3/Student.java
  8. 158 0
      java-base-project10/day17/src/com/sf/_02_list/demo3/StudentManagerSystem.java
  9. 52 0
      java-base-project10/day17/src/com/sf/_03_linked_list/demo/Test.java
  10. 85 0
      java-base-project10/day17/src/com/sf/_03_linked_list/demo1/BankQueueSystem.java
  11. 69 0
      java-base-project10/day17/src/com/sf/_03_linked_list/demo1/Customer.java
  12. 69 0
      java-base-project10/day17/src/com/sf/_03_linked_list/demo2/Express.java
  13. 83 0
      java-base-project10/day17/src/com/sf/_03_linked_list/demo2/ExpressSortStack.java
  14. 12 0
      java-base-project10/day17/src/com/sf/_04_泛型/AUtil.java
  15. 89 0
      java-base-project10/day17/src/com/sf/_04_泛型/MathUtils.java
  16. 55 0
      java-base-project10/day17/src/com/sf/_04_泛型/Point.java
  17. 48 0
      java-base-project10/day17/src/com/sf/_04_泛型/Test.java
  18. 9 0
      java-base-project10/day17/src/com/sf/_04_泛型/Test1.java
  19. 11 0
      java-base-project10/day18/day18.iml
  20. 29 0
      java-base-project10/day18/src/com/sf/_01_泛型/demo/AUtil.java
  21. 34 0
      java-base-project10/day18/src/com/sf/_01_泛型/demo/Point.java
  22. 28 0
      java-base-project10/day18/src/com/sf/_01_泛型/demo/Test.java
  23. 33 0
      java-base-project10/day18/src/com/sf/_01_泛型/demo1/Calculator.java
  24. 15 0
      java-base-project10/day18/src/com/sf/_01_泛型/demo1/Test.java
  25. 86 0
      java-base-project10/day18/src/com/sf/_02_遍历集合/Goods.java
  26. 40 0
      java-base-project10/day18/src/com/sf/_02_遍历集合/Test.java
  27. 50 0
      java-base-project10/day18/src/com/sf/_02_遍历集合/Test1.java
  28. 117 0
      java-base-project10/day18/src/com/sf/_02_遍历集合/Test2.java
  29. 66 0
      java-base-project10/day18/src/com/sf/_03_set/Student.java
  30. 53 0
      java-base-project10/day18/src/com/sf/_03_set/Test.java
  31. 33 0
      java-base-project10/day18/src/com/sf/_03_set/Test1.java
  32. 85 0
      java-base-project10/day18/src/com/sf/_04_set_contact/demo1/Book.java
  33. 118 0
      java-base-project10/day18/src/com/sf/_04_set_contact/demo1/BorrowManager.java
  34. 85 0
      java-base-project10/day18/src/com/sf/_04_set_contact/demo1/BorrowRecord.java
  35. 88 0
      java-base-project10/day18/src/com/sf/_04_set_contact/demo2/ExchangeGoods.java
  36. 146 0
      java-base-project10/day18/src/com/sf/_04_set_contact/demo2/ExchangeManager.java
  37. 91 0
      java-base-project10/day18/src/com/sf/_04_set_contact/demo2/ExchangeRecord.java
  38. 88 0
      java-base-project10/day18/src/com/sf/_04_set_contact/demo2/Member.java
  39. 11 0
      java-base-project10/day19/day19.iml
  40. 69 0
      java-base-project10/day19/src/com/sf/_01_treeset/demo/Student.java
  41. 39 0
      java-base-project10/day19/src/com/sf/_01_treeset/demo/Test.java
  42. 20 0
      java-base-project10/day19/src/com/sf/_01_treeset/demo/Test1.java
  43. 108 0
      java-base-project10/day19/src/com/sf/_01_treeset/demo1/Employee.java
  44. 46 0
      java-base-project10/day19/src/com/sf/_01_treeset/demo1/Test2.java
  45. 15 0
      java-base-project10/day19/src/com/sf/_01_treeset/demo2/Test.java
  46. 69 0
      java-base-project10/day19/src/com/sf/_01_treeset/demo2/User.java
  47. 76 0
      java-base-project10/day19/src/com/sf/_02_hashmap/Test.java
  48. 25 0
      java-base-project10/day19/src/com/sf/_02_hashmap/demo1/Test.java
  49. 99 0
      java-base-project10/day19/src/com/sf/_02_hashmap/demo2/ScoreManager.java
  50. 51 0
      java-base-project10/day19/src/com/sf/_02_hashmap/demo2/Student.java
  51. 29 0
      java-base-project10/day19/src/com/sf/_02_hashmap/demo3/LoginService.java
  52. 31 0
      java-base-project10/day19/src/com/sf/_02_hashmap/demo3/Test.java
  53. 50 0
      java-base-project10/day19/src/com/sf/_02_hashmap/demo3/User.java
  54. 61 0
      java-base-project10/day19/src/com/sf/_03_treemap/Student.java
  55. 21 0
      java-base-project10/day19/src/com/sf/_03_treemap/Test.java

+ 11 - 0
java-base-project10/day17/day17.iml

@@ -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>

+ 14 - 0
java-base-project10/day17/src/com/sf/_01_uuid_code/Test.java

@@ -0,0 +1,14 @@
+package com.sf._01_uuid_code;
+
+import java.util.UUID;
+
+public class Test {
+    /**
+     * 使用uuid 生成验证码
+     * uuid 生成唯一标识是没有规律
+     * 利用uuid 随机生成特性 利用字符串截取api substring(0,5)
+     */
+    public static void main(String[] args) {
+        System.out.println(UUID.randomUUID().toString().substring(0, 5));
+    }
+}

+ 68 - 0
java-base-project10/day17/src/com/sf/_02_list/demo1/Employee.java

@@ -0,0 +1,68 @@
+package com.sf._02_list.demo1;
+
+public class Employee {
+    private Long id;
+    private String name;
+    private Integer age;
+
+    public Employee() {
+    }
+
+    public Employee(Long id, String name, Integer age) {
+        this.id = id;
+        this.name = name;
+        this.age = age;
+    }
+
+    /**
+     * 获取
+     * @return id
+     */
+    public Long getId() {
+        return id;
+    }
+
+    /**
+     * 设置
+     * @param id
+     */
+    public void setId(Long id) {
+        this.id = id;
+    }
+
+    /**
+     * 获取
+     * @return name
+     */
+    public String getName() {
+        return name;
+    }
+
+    /**
+     * 设置
+     * @param name
+     */
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    /**
+     * 获取
+     * @return age
+     */
+    public Integer getAge() {
+        return age;
+    }
+
+    /**
+     * 设置
+     * @param age
+     */
+    public void setAge(Integer age) {
+        this.age = age;
+    }
+
+    public String toString() {
+        return "Employee{id = " + id + ", name = " + name + ", age = " + age + "}";
+    }
+}

+ 40 - 0
java-base-project10/day17/src/com/sf/_02_list/demo1/Test.java

@@ -0,0 +1,40 @@
+package com.sf._02_list.demo1;
+
+import java.util.ArrayList;
+
+public class Test {
+
+    public static void main(String[] args) {
+        /**
+         * 练习list 的api
+         *
+         * 需求
+         * 1定义一个Employee 类  类中有id  name   age
+         * 2 创建ArrayList, 往集合中添加三个employee
+         * 3 删除索引为0 元素
+         * 4 修改索引1 元素
+         * 5 查询索引为2 元素
+         * 6 查询集合数量
+         */
+        ArrayList<Employee> list = new ArrayList<>();
+        list.add(new Employee(1L,"zhangsan",10));
+        list.add(new Employee(2L,"lisi",11));
+        list.add(new Employee(3L,"wangwu",12));
+//        for (Employee employee : list) {
+//            System.out.println(employee);
+//        }
+        // 删除索引为0 元素
+//        list.remove(0);
+//        for (Employee employee : list) {
+//            System.out.println(employee);
+//        }
+        // 修改索引为1 元素
+//        list.set(1,new Employee(3L,"zhaoliu",30));
+//        for (Employee employee : list) {
+//            System.out.println(employee);
+//        }
+        // 查询索引为2 元素
+        System.out.println(list.get(2));
+        System.out.println("集合数量为:"+list.size());
+    }
+}

+ 113 - 0
java-base-project10/day17/src/com/sf/_02_list/demo2/Goods.java

@@ -0,0 +1,113 @@
+package com.sf._02_list.demo2;
+
+public class Goods {
+    private Long id;
+    private String name;
+    private double price;
+    private int stock;
+
+
+    /**
+     * 判断库存是否足够
+     */
+    public boolean isStockEnough(int buyNum){
+        if(buyNum<= stock){
+            return true;
+        }else{
+            return false;
+        }
+    }
+
+    /**
+     * 扣减库存
+     */
+    public void reduceStock(int buyNum){
+        // 1 判断库存是否
+        boolean stockEnough = isStockEnough(buyNum);
+        // 2 如果足够再去扣减库存
+        if(stockEnough){
+            this.stock -= buyNum;
+            System.out.println("扣减成功,扣减完以后还剩:"+ stock);
+        }else{
+            System.out.println("库存不足");
+        }
+    }
+
+    public Goods() {
+    }
+
+    public Goods(Long id, String name, double price, int stock) {
+        this.id = id;
+        this.name = name;
+        this.price = price;
+        this.stock = stock;
+    }
+
+    /**
+     * 获取
+     * @return id
+     */
+    public Long getId() {
+        return id;
+    }
+
+    /**
+     * 设置
+     * @param id
+     */
+    public void setId(Long id) {
+        this.id = id;
+    }
+
+    /**
+     * 获取
+     * @return name
+     */
+    public String getName() {
+        return name;
+    }
+
+    /**
+     * 设置
+     * @param name
+     */
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    /**
+     * 获取
+     * @return price
+     */
+    public double getPrice() {
+        return price;
+    }
+
+    /**
+     * 设置
+     * @param price
+     */
+    public void setPrice(double price) {
+        this.price = price;
+    }
+
+    /**
+     * 获取
+     * @return stock
+     */
+    public int getStock() {
+        return stock;
+    }
+
+    /**
+     * 设置
+     * @param stock
+     */
+    public void setStock(int stock) {
+        this.stock = stock;
+    }
+
+    public String toString() {
+        return "Goods{id = " + id + ", name = " + name + ", price = " + price + ", stock = " + stock + "}";
+    }
+}

+ 65 - 0
java-base-project10/day17/src/com/sf/_02_list/demo2/Test.java

@@ -0,0 +1,65 @@
+package com.sf._02_list.demo2;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Scanner;
+
+public class Test {
+    public static void main(String[] args) {
+        ArrayList<Goods> goods = new ArrayList<>();
+        goods.add(new Goods(1L,"手机",1000,10));
+        goods.add(new Goods(2L,"电脑",2000,10));
+        goods.add(new Goods(3L,"耳机",500,10));
+        printGoods(goods);
+        // 在控制台当中录入购买商品名称和商品数量
+        Scanner scanner = new Scanner(System.in);
+        System.out.println("请录入要购买商品名称");
+        String buyName = scanner.next();
+        System.out.println("请输入要购买商品数量");
+        int buyNum = scanner.nextInt();
+        // 判断商品是否存在 , 如果存在扣减库存
+        Goods good= contains(buyName, goods);
+        if(good != null){
+            System.out.println("购买商品存在");
+            // 扣减库存
+            good.reduceStock(buyNum);
+        }else{
+            System.out.println("购买商品不存在");
+        }
+        //计算总价
+        double stockTotalPrice = getStockTotalPrice(goods);
+        System.out.println("总价为:"+ stockTotalPrice);
+    }
+
+    /**
+     * 计算库存总价
+     */
+    public static double getStockTotalPrice(List<Goods> list){
+        double totalPrice=  0;
+        for (Goods goods : list) {
+            totalPrice+= goods.getPrice() * goods.getStock();
+        }
+        return totalPrice;
+    }
+
+    /**
+     * 判断商品是否存在
+     */
+    public static Goods contains(String name,List<Goods> goods){
+        for (Goods good : goods) {
+            if(good.getName().equals(name)){
+                return good;
+            }
+        }
+        return null;
+    }
+
+    /**
+     * 查询所有商品信息
+     */
+    public static void  printGoods(List<Goods> list){
+        for (Goods goods : list) {
+            System.out.println(goods);
+        }
+    }
+}

+ 87 - 0
java-base-project10/day17/src/com/sf/_02_list/demo3/Student.java

@@ -0,0 +1,87 @@
+package com.sf._02_list.demo3;
+
+public class Student {
+    private Long sid;
+    private String name;
+    private Integer age;
+    private String address;
+
+
+    public Student() {
+    }
+
+    public Student(Long sid, String name, Integer age, String address) {
+        this.sid = sid;
+        this.name = name;
+        this.age = age;
+        this.address = address;
+    }
+
+    /**
+     * 获取
+     * @return sid
+     */
+    public Long getSid() {
+        return sid;
+    }
+
+    /**
+     * 设置
+     * @param sid
+     */
+    public void setSid(Long sid) {
+        this.sid = sid;
+    }
+
+    /**
+     * 获取
+     * @return name
+     */
+    public String getName() {
+        return name;
+    }
+
+    /**
+     * 设置
+     * @param name
+     */
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    /**
+     * 获取
+     * @return age
+     */
+    public Integer getAge() {
+        return age;
+    }
+
+    /**
+     * 设置
+     * @param age
+     */
+    public void setAge(Integer age) {
+        this.age = age;
+    }
+
+    /**
+     * 获取
+     * @return address
+     */
+    public String getAddress() {
+        return address;
+    }
+
+    /**
+     * 设置
+     * @param address
+     */
+    public void setAddress(String address) {
+        this.address = address;
+    }
+
+    public String toString() {
+        return "Student{sid = " + sid + ", name = " + name + ", age = " + age + ", address = " + address + "}";
+    }
+}

+ 158 - 0
java-base-project10/day17/src/com/sf/_02_list/demo3/StudentManagerSystem.java

@@ -0,0 +1,158 @@
+package com.sf._02_list.demo3;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Scanner;
+
+public class StudentManagerSystem {
+
+
+    public static void main(String[] args) {
+        List<Student> list = new ArrayList<>();
+        // 搭建学生管理系统初始界面
+        while (true){
+            System.out.println("----------------------欢迎来到四福学生管理系统---------------------");
+            System.out.println("1: 添加学生");
+            System.out.println("2: 删除学生");
+            System.out.println("3: 修改学生");
+            System.out.println("4: 查询学生");
+            System.out.println("5: 退出");
+            // 通过键盘录入输入用户选择
+            Scanner scanner = new Scanner(System.in);
+            System.out.println("请输入您的选择:");
+            int inputNumber = scanner.nextInt();
+            if(inputNumber == 1){
+                addStudent(list);
+            }else if(inputNumber  == 2){
+                System.out.println("请输入要删除的学生id");
+                long sid = scanner.nextLong();
+                removeStudent(sid,list);
+            }else if(inputNumber == 3){
+                System.out.println("请输入要修改的学生id");
+                long sid = scanner.nextLong();
+                updateStudent(sid,list);
+            }else if(inputNumber == 4){
+                queryStudents(list);
+            }else if(inputNumber == 5){
+                break;
+            }else{
+                System.out.println("请输入1-5");
+            }
+
+        }
+    }
+
+    private static void queryStudents(List<Student> list) {
+        System.out.println("查询操作");
+        System.out.println("学生id    学生姓名   学生年龄   学生地址");
+        for (Student student : list) {
+            System.out.println(student.getSid() +"         " +student.getName()+"       "+student.getAge() +"     "+ student.getAddress());
+        }
+    }
+
+    private static void updateStudent(Long sid,List<Student> list) {
+        // 1 判断要更改sid 是否存在
+        // 如果flag = true 表示要修改id 数据是存在可以修改, 如果flag=false 不存在不允许修改
+        boolean flag = isStudentId(sid, list);
+
+        if(flag){
+            // 修改名称  修改年龄  修改 地址
+            // 一般修改信息的时候学号是不会变好
+            Student updateStudent = new Student();
+            updateStudent.setSid(sid);
+            Scanner scanner = new Scanner(System.in);
+
+            System.out.println("请录入要修改name");
+            String name = scanner.next();
+            updateStudent.setName(name);
+
+            System.out.println("请录入要修改age");
+            int age = scanner.nextInt();
+            updateStudent.setAge(age);
+
+            System.out.println("请录入要修改地址");
+            String address = scanner.next();
+            updateStudent.setAddress(address);
+
+            // 替换对应索引位置 student
+            // 找到索引位置
+            // {student1,student2 ,student3}
+            int index = findStudentIndex(sid,list);
+            list.set(index,updateStudent);
+        }else{
+            System.out.println("要修改数据不存在");
+        }
+    }
+
+    /**
+     * 找student 锁在的索引信息
+     */
+    private static int findStudentIndex(Long sid, List<Student> list) {
+        for (int i = 0; i < list.size(); i++) {
+            Student student = list.get(i);
+            if(sid == student.getSid()){
+                return i;
+            }
+        }
+        return -1;
+    }
+
+    private static void removeStudent(Long id ,List<Student> students) {
+        // 判断id 是否存在
+        boolean flag = isStudentId(id, students);
+        // flag = true 表存在  false 表示不存在
+        if(flag){
+            int studentIndex = findStudentIndex(id, students);
+            students.remove(studentIndex);
+            System.out.println("删除成功");
+        }else{
+            System.out.println("删除学生不存在");
+        }
+    }
+
+    private static void addStudent(List<Student> list) {
+        Scanner scanner = new Scanner(System.in);
+        Student student = new Student();
+        while (true){
+            System.out.println("请录入学生id");
+            long sid = scanner.nextLong();
+            boolean flag = isStudentId(sid,list);
+            if(!flag){
+                student.setSid(sid);
+                break;
+            }else{
+                System.out.println("id 已经存在请重新输入");
+            }
+        }
+        System.out.println("请输入学生姓名");
+        String name = scanner.next();
+        student.setName(name);
+
+        System.out.println("请输入学生年龄");
+        int age = scanner.nextInt();
+        student.setAge(age);
+
+        System.out.println("请输入学生地址");
+        String address = scanner.next();
+        student.setAddress(address);
+        // 把学生信息添加到集合中
+        list.add(student);
+//        System.out.println(list);
+    }
+
+    /**
+     * 判断学生id 是否存在
+     * @param sid
+     * @param list
+     * @return
+     */
+    private static boolean isStudentId(long sid, List<Student> list) {
+        boolean flag = false;
+        for (Student student : list) {
+            if(student.getSid() == sid){
+                flag = true;
+            }
+        }
+        return flag;
+    }
+}

+ 52 - 0
java-base-project10/day17/src/com/sf/_03_linked_list/demo/Test.java

@@ -0,0 +1,52 @@
+package com.sf._03_linked_list.demo;
+
+import java.util.LinkedList;
+
+public class Test {
+    public static void main(String[] args) {
+        LinkedList<String> list = new LinkedList<>();
+        /**
+         * addFirst: 从头开始添加
+         */
+        list.addFirst("zhangsan");
+        list.addFirst("lisi");
+        list.addFirst("wangwu");
+
+        /**
+         * addLast : 从尾开始进行添加
+         */
+        list.addLast("zhaoliu");
+
+        /**
+         * getFirst : 获取列表第一个元素
+         */
+        System.out.println(list.getFirst());
+        /**
+         * getLast: 获取列表最后一个元素
+         */
+        System.out.println(list.getLast());
+
+        /**
+         * removeFirst: 移除列表的第一个元素
+         * 返回值就是你移除的那个元素
+         * removeLast:  移除列表的最后一个元素
+         */
+//        list.removeFirst();
+        String str = list.removeLast();
+        System.out.println("移除元素"+ str);
+        System.out.println(list);
+
+
+        /**
+         * 栈的操作
+         * push () 入栈
+         *
+         * pop()  出栈
+         *
+         * peek();  获取栈顶部元素
+         */
+//        list.push();
+//        list.pop();
+//        list.peek();
+    }
+}

+ 85 - 0
java-base-project10/day17/src/com/sf/_03_linked_list/demo1/BankQueueSystem.java

@@ -0,0 +1,85 @@
+package com.sf._03_linked_list.demo1;
+
+import java.util.LinkedList;
+
+public class BankQueueSystem {
+    //创建LinkedList  存储排队用户信息
+    public static LinkedList<Customer> customers = new LinkedList<>();
+    // 设置id
+    public static Long nextId = 1L;
+
+    /**
+     * 普通用户取号
+     * name : 取款人名称
+     * businessType: 业务类型
+     */
+    public static void takeNumber(String name,String businessType){
+        // 封装成一个Customer
+        Customer customer = new Customer(nextId++,name,businessType);
+        // 把customer 存到linkedList 当中 addLast();
+        customers.addLast(customer);
+        System.out.println("【取号成功】" + customer + ",当前排队人数:" + customers.size());
+    }
+
+    /**
+     * vip 取号
+     */
+    public static void takeVipNumber(String name,String businessType){
+        // 封装成一个Customer
+        Customer customer = new Customer(nextId++,name,businessType);
+        // 把customer 存到linkedList 当中 addLast();
+        customers.addFirst(customer);
+        System.out.println("【取号成功】" + customer + ",当前排队人数:" + customers.size());
+    }
+
+
+
+    /**
+     * 叫号
+     * 把队列的做表变元素移除并返回就可以了
+     */
+    public static void callNumber(){
+        // 判断linkedList 是否有元素,如果没有元素提醒当前没有人排队
+        if(customers.size() == 0){
+            System.out.println("当前没有人排队办理业务");
+            return;
+        }
+        // 如果元素个数大于0 , 移除头部元素
+        Customer customer = customers.removeFirst();
+        System.out.println("请编号"+ customer.getId() +"姓名: "+customer.getName()+"办理业务");
+    }
+
+
+    /**
+     * 查看队列状态
+     */
+    public static void showQueueStatus(){
+        //判空操作
+        if(customers.size() == 0){
+            System.out.println("当前没有任何人排队");
+            return;
+        }
+        // 下一个叫号客户
+        Customer nextCusotmer = customers.getFirst();
+        // 最后一个叫号客户
+        Customer lastCustomer = customers.getLast();
+        System.out.println("下一号为:"+ nextCusotmer.getId() +"名称:"+ nextCusotmer.getName());
+        System.out.println("最后一个号码为:"+ lastCustomer.getId() +"名称:"+ lastCustomer.getName());
+        System.out.println("当前排队人数为:"+ customers.size());
+    }
+
+    public static void main(String[] args) {
+        takeNumber("zhangsan","取款");
+        takeNumber("lisi","转账");
+        takeNumber("wangwu","存款");
+
+        takeVipNumber("fanjialong","存款");
+
+        showQueueStatus();
+        // 叫号
+//        callNumber();
+//        callNumber();
+//        callNumber();
+//        callNumber();
+    }
+}

+ 69 - 0
java-base-project10/day17/src/com/sf/_03_linked_list/demo1/Customer.java

@@ -0,0 +1,69 @@
+package com.sf._03_linked_list.demo1;
+
+public class Customer {
+    private Long id;
+    private String name;
+    private String businessType;
+
+
+    public Customer() {
+    }
+
+    public Customer(Long id, String name, String businessType) {
+        this.id = id;
+        this.name = name;
+        this.businessType = businessType;
+    }
+
+    /**
+     * 获取
+     * @return id
+     */
+    public Long getId() {
+        return id;
+    }
+
+    /**
+     * 设置
+     * @param id
+     */
+    public void setId(Long id) {
+        this.id = id;
+    }
+
+    /**
+     * 获取
+     * @return name
+     */
+    public String getName() {
+        return name;
+    }
+
+    /**
+     * 设置
+     * @param name
+     */
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    /**
+     * 获取
+     * @return businessType
+     */
+    public String getBusinessType() {
+        return businessType;
+    }
+
+    /**
+     * 设置
+     * @param businessType
+     */
+    public void setBusinessType(String businessType) {
+        this.businessType = businessType;
+    }
+
+    public String toString() {
+        return "Customer{id = " + id + ", name = " + name + ", businessType = " + businessType + "}";
+    }
+}

+ 69 - 0
java-base-project10/day17/src/com/sf/_03_linked_list/demo2/Express.java

@@ -0,0 +1,69 @@
+package com.sf._03_linked_list.demo2;
+
+public class Express {
+    private String expressNo;
+    private String address;
+    private double weight;
+
+
+    public Express() {
+    }
+
+    public Express(String expressNo, String address, double weight) {
+        this.expressNo = expressNo;
+        this.address = address;
+        this.weight = weight;
+    }
+
+    /**
+     * 获取
+     * @return expressNo
+     */
+    public String getExpressNo() {
+        return expressNo;
+    }
+
+    /**
+     * 设置
+     * @param expressNo
+     */
+    public void setExpressNo(String expressNo) {
+        this.expressNo = expressNo;
+    }
+
+    /**
+     * 获取
+     * @return address
+     */
+    public String getAddress() {
+        return address;
+    }
+
+    /**
+     * 设置
+     * @param address
+     */
+    public void setAddress(String address) {
+        this.address = address;
+    }
+
+    /**
+     * 获取
+     * @return weight
+     */
+    public double getWeight() {
+        return weight;
+    }
+
+    /**
+     * 设置
+     * @param weight
+     */
+    public void setWeight(double weight) {
+        this.weight = weight;
+    }
+
+    public String toString() {
+        return "Express{expressNo = " + expressNo + ", address = " + address + ", weight = " + weight + "}";
+    }
+}

+ 83 - 0
java-base-project10/day17/src/com/sf/_03_linked_list/demo2/ExpressSortStack.java

@@ -0,0 +1,83 @@
+package com.sf._03_linked_list.demo2;
+
+import java.util.LinkedList;
+
+public class ExpressSortStack {
+    public static LinkedList<Express> expresses = new LinkedList<>();
+
+
+    /**
+     * 把快递放到分拣栈顶部
+     * 把expres 放到linkedList
+     */
+    public static void pushExpress(Express express){
+        expresses.push(express);
+        System.out.println("已经放进待分拣区域"+ express);
+    }
+
+    /**
+     * 分拣员从栈顶去除快递 标记已分拣
+     */
+    public static void popExpress(){
+        /**
+         * 判断集合size 是否大于0
+         */
+        if(expresses.size() == 0){
+            System.out.println("已经没有快递了");
+            return;
+        }
+        Express express = expresses.pop();
+        System.out.println("快递已分拣"+ express +"已经投放到"+ express.getAddress()+"区域");
+    }
+
+    /**
+     * 查看下次要分拣快递信息
+     * 查看栈顶信息 peek
+     */
+    public static void peekExpress(){
+        // 判断区域是否有快递
+        if(expresses.size() == 0){
+            System.out.println("已经没有快递了");
+            return;
+        }
+        // 查看一下栈顶信息  就是他下一次要分拣的快递
+        Express express = expresses.peek();
+        System.out.println("下一次要分拣快递信息为:"+express);
+    }
+
+    /**
+     * 查看栈里面快递总重量
+     */
+    public static void  statWeight(){
+        if(expresses.size() == 0){
+            System.out.println("已经没有快递了");
+            return;
+        }
+        double totalWeight = 0;
+        int overWeightCount = 0;
+
+        for (Express express : expresses) {
+            // 拿每一个快递重量累加
+            totalWeight += express.getWeight();
+            if(express.getWeight()>5){
+                overWeightCount++;
+            }
+        }
+        System.out.println("总重量为:"+ totalWeight);
+        System.out.println("超重快递:"+ overWeightCount);
+        System.out.println("快递总数量"+ expresses.size());
+    }
+
+    public static void main(String[] args) {
+        pushExpress(new Express("001","广州",1));
+        pushExpress(new Express("002","北京",6));
+        pushExpress(new Express("003","上海",10));
+//        System.out.println(expresses);
+
+//        popExpress();
+//
+//        peekExpress();
+        statWeight();
+    }
+
+}

+ 12 - 0
java-base-project10/day17/src/com/sf/_04_泛型/AUtil.java

@@ -0,0 +1,12 @@
+package com.sf._04_泛型;
+
+public class AUtil<T>  {
+
+    public T a(T a){
+        return a;
+    }
+
+    public static<T extends Number> double add(T a,T b){
+        return a.doubleValue() + b.doubleValue();
+    }
+}

+ 89 - 0
java-base-project10/day17/src/com/sf/_04_泛型/MathUtils.java

@@ -0,0 +1,89 @@
+package com.sf._04_泛型;
+
+/**
+ * 泛型类的使用
+ * @param <T>
+ */
+public class MathUtils<T extends Number> {
+    private T a;
+    private T b;
+
+
+    public MathUtils() {
+    }
+
+    public MathUtils(T a, T b) {
+        this.a = a;
+        this.b = b;
+    }
+
+    /**
+     * 获取
+     * @return a
+     */
+    public T getA() {
+        return a;
+    }
+
+    /**
+     * 设置
+     * @param a
+     */
+    public void setA(T a) {
+        this.a = a;
+    }
+
+    /**
+     * 获取
+     * @return b
+     */
+    public T getB() {
+        return b;
+    }
+
+    /**
+     * 设置
+     * @param b
+     */
+    public void setB(T b) {
+        this.b = b;
+    }
+
+    public String toString() {
+        return "MathUtils{a = " + a + ", b = " + b + "}";
+    }
+
+    /**
+     * 泛型方法
+     * @param a
+     * @param b
+     * @return
+     */
+    @SuppressWarnings("unchecked") // 抑制unchecked警告(因强制转换)
+    public static<T extends Number> T add(T a , T b){
+        // 判断类型是double 还是integer
+        if( a instanceof Integer && b instanceof Integer){
+            //a.intValue() + b.intValue()  把传入a  和 b 转成int 类型
+            // Integer.valueOf    d
+            return (T) Integer.valueOf(a.intValue() + b.intValue());
+        }else if(a instanceof Double && b instanceof Double){
+            return (T) Double.valueOf(a.doubleValue() + b.doubleValue());
+        }
+        return null;
+    }
+
+//    @SuppressWarnings("unchecked") // 抑制unchecked警告(因强制转换)
+//    public static <T extends Number> T add(T a, T b) {
+//        // 核心:将 Number 转为基本类型计算,再转回对应包装类
+//        if (a instanceof Integer && b instanceof Integer) {
+//            return (T) Integer.valueOf(a.intValue() + b.intValue());
+//        } else if (a instanceof Double && b instanceof Double) {
+//            return (T) Double.valueOf(a.doubleValue() + b.doubleValue());
+//        } else if (a instanceof Long && b instanceof Long) {
+//            return (T) Long.valueOf(a.longValue() + b.longValue());
+//        } else {
+//            // 其他数值类型(如 Float、Short)可按需扩展
+//            throw new IllegalArgumentException("不支持的数值类型");
+//        }
+//    }
+}

+ 55 - 0
java-base-project10/day17/src/com/sf/_04_泛型/Point.java

@@ -0,0 +1,55 @@
+package com.sf._04_泛型;
+
+/**
+ * point 存储横纵坐标信息
+ * x y
+ * xy  类型不是单一类型 可能String   Integer  double
+ */
+public class Point<T> {
+    T  x;
+    T  y;
+
+    public Point() {
+    }
+
+    public Point(T x, T y) {
+        this.x = x;
+        this.y = y;
+    }
+
+    /**
+     * 获取
+     * @return x
+     */
+    public T getX() {
+        return x;
+    }
+
+    /**
+     * 设置
+     * @param x
+     */
+    public void setX(T x) {
+        this.x = x;
+    }
+
+    /**
+     * 获取
+     * @return y
+     */
+    public T getY() {
+        return y;
+    }
+
+    /**
+     * 设置
+     * @param y
+     */
+    public void setY(T y) {
+        this.y = y;
+    }
+
+    public String toString() {
+        return "Point{x = " + x + ", y = " + y + "}";
+    }
+}

+ 48 - 0
java-base-project10/day17/src/com/sf/_04_泛型/Test.java

@@ -0,0 +1,48 @@
+package com.sf._04_泛型;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class Test {
+    /**
+     * MathUtils 类
+     * 这个类当中有两个变量 a  , b
+     *
+     * 要求在创建MathUtil这个类的时候可以创建Integer  double
+     *
+     *
+     * add方法 这个方法需要传递a , b
+     * 计算a + b
+     *
+     * @param args
+     */
+
+
+    public static void main(String[] args) {
+        /**
+         * 创建三个Point<Integer> <String><Double>
+         */
+//        Point<Integer> point =  new Point<>(10,20);
+//        System.out.println(point.getX());
+//
+//        Point<String> pointStr =  new Point<>("20","30");
+//        System.out.println(point.getX());
+//
+//        Point<Double> pointDouble = new Point<>(30.0,40.0);
+//        System.out.println(point.getX());
+
+        MathUtils<Integer> mathUtils = new MathUtils<>();
+
+        MathUtils.add(1,2);
+        MathUtils.add(3.1,3.2);
+
+        List list = new ArrayList();
+        list.add(1);
+        Object obj = list.get(0);
+
+        List<Integer> list1 = new ArrayList<>();
+        list1.add(1);
+        Integer integer = list1.get(0);
+
+    }
+}

+ 9 - 0
java-base-project10/day17/src/com/sf/_04_泛型/Test1.java

@@ -0,0 +1,9 @@
+package com.sf._04_泛型;
+
+public class Test1 {
+    public static void main(String[] args) {
+        AUtil<Integer> a = new AUtil<>();
+        System.out.println(a.a(1));
+        System.out.println(AUtil.add(1, 2));
+    }
+}

+ 11 - 0
java-base-project10/day18/day18.iml

@@ -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>

+ 29 - 0
java-base-project10/day18/src/com/sf/_01_泛型/demo/AUtil.java

@@ -0,0 +1,29 @@
+package com.sf._01_泛型.demo;
+
+public class AUtil {
+
+
+    public <T> T  method1(T a){
+        return a;
+    }
+    /**
+     * 因为在java 当中能够进行+- 运算只有  int  byte  shorg  Int  lonteger  Byte Short Long
+     * E 属于泛型 -> 表示任意类型包含对象  基本数据类   包装类型
+     * 如何解决
+     * 可以泛型extends Number  Number 他子类就只有数值类型
+     * 如果我们让我们泛型继承Number 我们泛型只能够传int  byte short...
+     *
+     * Number 这个接口中提供很多方法 intValue  doubleValue  longValu
+     * a Integer  Double
+     * 返回  int  double   long  float  数值
+     */
+    public static<E extends Number> Number add(E a,E b){
+        // 判断他类型如果int 做int 相加 如果double 就做double 返回double
+        if(a instanceof Integer && b instanceof Integer){
+            return a.intValue() + b.intValue();
+        }else if(a instanceof Double && b instanceof Double){
+            return a.doubleValue() + b.doubleValue();
+        }
+        return -1;
+    }
+}

+ 34 - 0
java-base-project10/day18/src/com/sf/_01_泛型/demo/Point.java

@@ -0,0 +1,34 @@
+package com.sf._01_泛型.demo;
+
+
+/**
+ * 泛型类:
+ * 如果的字段设计到多种数据类型, 我们还不希望在类当中写死就可以
+ * 使用泛型类
+ * @param <T>
+ */
+public class Point<T> {
+    T x;
+    T y;
+
+    public Point(T x, T y) {
+        this.x = x;
+        this.y = y;
+    }
+
+
+    /**
+     * method1 成员方法 生命method1 是一个泛型方法
+     */
+    public  T method1(T a){
+        System.out.println(a);
+        return a;
+    }
+
+    /**
+     * method2 静态方法, 声明method2 是一个静态方法
+     */
+    public static<E> E method2(E a){
+        return a;
+    }
+}

+ 28 - 0
java-base-project10/day18/src/com/sf/_01_泛型/demo/Test.java

@@ -0,0 +1,28 @@
+package com.sf._01_泛型.demo;
+
+public class Test {
+    public static void main(String[] args) {
+//        Point<Integer> point = new Point<>(10,20);
+//        Point<Double> point1 = new Point<>(3.1,2.8);
+//        Point<String> point2 = new Point<>("xx","xxx");
+//
+//        point.method1(1);
+//        point1.method1(1.2);
+//        point2.method1("ssss");
+//
+//
+//        Point.method2("xxx");
+//        Point.method2(123);
+//        Point.method2(3.4);
+
+        System.out.println(AUtil.add(10, 20));
+        System.out.println(AUtil.add(3.1,3.2));
+
+
+//        ArrayList<Integer> arrayList = new ArrayList();
+//        arrayList.add(10);
+//        Integer integer = arrayList.get(0);
+
+
+    }
+}

+ 33 - 0
java-base-project10/day18/src/com/sf/_01_泛型/demo1/Calculator.java

@@ -0,0 +1,33 @@
+package com.sf._01_泛型.demo1;
+
+public class Calculator<T extends Number> {
+    private T baseNum;
+
+    public Calculator(T baseNum) {
+        this.baseNum = baseNum;
+    }
+
+    public T getBaseNum() {
+        return baseNum;
+    }
+
+    /**
+     * 传入类型可以是 Integer 1  Double 1.1  Float 2
+     * 返回值类型 double
+     * Integer num=1 baseNum=1   返回 2.0
+     * Double  num=1.1  baseNum=1.1 返回值2.2
+     * flot    num=1.2  baseNum=1.2 返回2.2
+     *
+     *
+     * 传入类型Integer Double  Float
+     * 返回值类型也是Integer  double  float
+     *
+     */
+    public double add(T num){
+        return num.doubleValue() + baseNum.doubleValue();
+    }
+
+    public  <E extends Number> double multiply(E num){
+        return num.doubleValue() * baseNum.doubleValue();
+    }
+}

+ 15 - 0
java-base-project10/day18/src/com/sf/_01_泛型/demo1/Test.java

@@ -0,0 +1,15 @@
+package com.sf._01_泛型.demo1;
+
+public class Test {
+    public static void main(String[] args) {
+        Calculator<Integer> calculator = new Calculator<>(10);
+        Calculator<Double> calculator1 = new Calculator<>(3.4);
+
+        System.out.println(calculator.add(20));  // 传入int
+        System.out.println(calculator1.add(1.3)); // double
+
+        System.out.println(calculator.multiply(10));
+        System.out.println(calculator.multiply(3.4));
+
+    }
+}

+ 86 - 0
java-base-project10/day18/src/com/sf/_02_遍历集合/Goods.java

@@ -0,0 +1,86 @@
+package com.sf._02_遍历集合;
+
+public class Goods {
+    private int id;
+    private String name;
+    private int stock;
+    private double price;
+
+    public Goods() {
+    }
+
+    public Goods(int id, String name, int stock, double price) {
+        this.id = id;
+        this.name = name;
+        this.stock = stock;
+        this.price = price;
+    }
+
+    /**
+     * 获取
+     * @return id
+     */
+    public int getId() {
+        return id;
+    }
+
+    /**
+     * 设置
+     * @param id
+     */
+    public void setId(int id) {
+        this.id = id;
+    }
+
+    /**
+     * 获取
+     * @return name
+     */
+    public String getName() {
+        return name;
+    }
+
+    /**
+     * 设置
+     * @param name
+     */
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    /**
+     * 获取
+     * @return stock
+     */
+    public int getStock() {
+        return stock;
+    }
+
+    /**
+     * 设置
+     * @param stock
+     */
+    public void setStock(int stock) {
+        this.stock = stock;
+    }
+
+    /**
+     * 获取
+     * @return price
+     */
+    public double getPrice() {
+        return price;
+    }
+
+    /**
+     * 设置
+     * @param price
+     */
+    public void setPrice(double price) {
+        this.price = price;
+    }
+
+    public String toString() {
+        return "Goods{id = " + id + ", name = " + name + ", stock = " + stock + ", price = " + price + "}";
+    }
+}

+ 40 - 0
java-base-project10/day18/src/com/sf/_02_遍历集合/Test.java

@@ -0,0 +1,40 @@
+package com.sf._02_遍历集合;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+
+public class Test {
+    public static void main(String[] args) {
+        /**
+         * 创建ArrayList 往集合当中添加3 个元素进行遍历
+         */
+        ArrayList<Integer> list = new ArrayList<>();
+        list.add(1);
+        list.add(2);
+        list.add(3);
+        // 第一种使用for 循环进行遍历
+        for (int i = 0; i < list.size(); i++) {
+            System.out.println(list.get(i));
+        }
+        System.out.println("-------------------------------------------");
+        // 使用foreach 方式进行遍历
+        for (Integer integer : list) {
+            System.out.println(integer);
+        }
+        System.out.println("---------------------------------");
+        // 第三种使用迭代器进行遍历
+        // java 当中集合他们实现迭代器接口 , 这个迭起也可以帮我们进行比那里
+        /**
+         * 而且foreach 在遍历 会检查遍历元素是否实现了迭代器接口
+         * 如果实现了迭代器接口foeach 底层就使用迭代器进行 遍历
+         * 如果没有实现迭代器接口底层就是for 循环进行遍历
+         *
+         * foreach 遍历集合  他的底层使用都是迭代器进行遍历
+         */
+        Iterator<Integer> iterator = list.iterator();
+        while (iterator.hasNext()){
+            Integer ele = iterator.next();
+            System.out.println(ele);
+        }
+    }
+}

+ 50 - 0
java-base-project10/day18/src/com/sf/_02_遍历集合/Test1.java

@@ -0,0 +1,50 @@
+package com.sf._02_遍历集合;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+public class Test1 {
+    public static void main(String[] args) {
+        List<String> list = new ArrayList<>();
+        list.add("西施");
+        list.add("王昭君");
+        list.add("貂蝉");
+        list.add("杨玉环");
+
+        /**
+         * 并发修改异常
+         * ConcurrentModificationException
+         * 当我们在使用foreach 遍历的时候如果在遍历过程中删除了元素就会出现并发修改异常
+         *
+         * foreach 底层使用迭代器
+         * 迭代器遍历过程中做检查操作, 每次遍历的时候都会检查元素是否更改
+         * expectCount 0           count  1
+         * 如果发现更改了就会并发修改异常他认为是不安全的
+         *
+         *  使用迭代器remove  他在删除的时候会实时更新count 和expectCount 就不会有问题了
+         *
+         *  我去图书馆借书  我问图书馆管理员第一排都什么书
+         *  第一排 4 本数
+         *  西游记  十万个为什么   三国演义 红楼梦
+         *  西游记  十万个为什么  三国演义 红楼梦
+         *
+         *
+         */
+
+//        for (String str : list) {
+//            if(str.equals("王昭君")){
+//                list.remove(str);
+//            }
+//        }
+        // 遍历修改成使用迭代器遍历 , 删除王昭君
+        Iterator<String> iterator = list.iterator();
+        while (iterator.hasNext()){
+            String ele = iterator.next();
+            if("王昭君".equals(ele)){
+                iterator.remove();
+            }
+        }
+        System.out.println(list);
+    }
+}

+ 117 - 0
java-base-project10/day18/src/com/sf/_02_遍历集合/Test2.java

@@ -0,0 +1,117 @@
+package com.sf._02_遍历集合;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+public class Test2 {
+
+
+    public static void main(String[] args) {
+        List<Goods> goods = initGoods();
+        // 删除库存为0 商品
+//        removeGoods(goods);
+//        // 遍历商品信息
+//        queryGoods(goods);
+        // 添加商品库存
+        incrGoodsStock(goods);
+
+        queryGoods(goods);
+
+        totalGoodsPrice(goods);
+        // 根据商品名称查询商品信息
+        System.out.println(queryGoodByName("手机1", goods));
+    }
+
+    /**
+     * 根据商品名称查询商品信息
+     */
+    private static Goods queryGoodByName(String name, List<Goods> goods) {
+        for (Goods good : goods) {
+            if(name.equals(good.getName())){
+                return good;
+            }
+        }
+        return null;
+    }
+
+    /**
+     * 统计库存总价
+     * @param goods
+     */
+    private static void totalGoodsPrice(List<Goods> goods) {
+        double totalPrice = 0;
+        for (Goods good : goods) {
+            totalPrice += good.getStock() * good.getPrice();
+        }
+        System.out.println("库存总价为:"+ totalPrice);
+    }
+
+    /**
+     * 添加商品库存
+     * @param goods
+     */
+    private static void incrGoodsStock(List<Goods> goods) {
+        Iterator<Goods> iterator = goods.iterator();
+        while (iterator.hasNext()){
+            Goods good = iterator.next();
+            // 判断价格是否大于1000
+            if(good.getPrice() >1000){
+                good.setStock(good.getStock() + 5);
+            }
+        }
+    }
+
+    /**
+     * 删除库存为0的商品
+     * @param goods
+     */
+    private static void removeGoods(List<Goods> goods) {
+        Iterator<Goods> iterator = goods.iterator();
+        while (iterator.hasNext()){
+            Goods ele = iterator.next();
+            // 判断库存是否为0
+            if(ele.getStock() == 0){
+                iterator.remove();
+            }
+        }
+    }
+
+    /**
+     * 遍历集合信息
+     * fori 循环
+     * foreach 循环
+     * 迭代器
+     * @param goods
+     */
+    private static void queryGoods(List<Goods> goods) {
+//        for (int i = 0; i < goods.size(); i++) {
+//            System.out.println(goods.get(i));
+//        }
+//        System.out.println("----------------");
+//        for (Goods good : goods) {
+//            System.out.println(good);
+//        }
+//        System.out.println("-------------------");
+        Iterator<Goods> iterator = goods.iterator();
+        while (iterator.hasNext()){
+            Goods next = iterator.next();
+            System.out.println(next);
+        }
+    }
+
+
+    /**
+     * 初始化商品集合
+     * @return
+     */
+    public static List<Goods> initGoods(){
+        ArrayList<Goods> goods = new ArrayList<>();
+        goods.add(new Goods(1,"手机",10,1000));
+        goods.add(new Goods(2,"手机1",0,2000));
+        goods.add(new Goods(3,"手机2",10,2000));
+        goods.add(new Goods(4,"手机3",10,3100));
+        goods.add(new Goods(5,"手机4",10,2000));
+        return goods;
+    }
+}

+ 66 - 0
java-base-project10/day18/src/com/sf/_03_set/Student.java

@@ -0,0 +1,66 @@
+package com.sf._03_set;
+
+import java.util.Objects;
+
+public class Student {
+    private String name;
+    private int age;
+
+    public Student() {
+    }
+
+    public Student(String name, int age) {
+        this.name = name;
+        this.age = age;
+    }
+
+    @Override
+    public boolean equals(Object o) {
+        if (this == o) return true;
+        if (o == null || getClass() != o.getClass()) return false;
+        Student student = (Student) o;
+        return age == student.age &&
+                Objects.equals(name, student.name);
+    }
+
+    @Override
+    public int hashCode() {
+        return Objects.hash(name, age);
+    }
+
+    /**
+     * 获取
+     * @return name
+     */
+    public String getName() {
+        return name;
+    }
+
+    /**
+     * 设置
+     * @param name
+     */
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    /**
+     * 获取
+     * @return age
+     */
+    public int getAge() {
+        return age;
+    }
+
+    /**
+     * 设置
+     * @param age
+     */
+    public void setAge(int age) {
+        this.age = age;
+    }
+
+    public String toString() {
+        return "Student{name = " + name + ", age = " + age + "}";
+    }
+}

+ 53 - 0
java-base-project10/day18/src/com/sf/_03_set/Test.java

@@ -0,0 +1,53 @@
+package com.sf._03_set;
+
+import java.util.HashSet;
+
+public class Test {
+    /**
+     * Set 常用api 的练习
+     *
+     * set 特点: 无需 , 不允许重复
+     * set 实现类: HashSet  TreeSet
+     *
+     * set 添加数据 验证set 是无需不允许重复的
+     * 删除数据
+     * 查询数据
+     * @param args
+     */
+    public static void main(String[] args) {
+        HashSet<String> set = new HashSet<>();
+        /**
+         * hashSet 添加数据还是使用add 方法
+         */
+        set.add("西游记");
+        set.add("红楼梦");
+        set.add("水浒传");
+        set.add("三国演义");
+        set.add("三国演义");
+
+        System.out.println(set);
+
+        /**
+         * set.remove 可以删除元素
+         */
+        set.remove("西游记");
+        System.out.println(set);
+
+        /**
+         * 遍历查询
+         */
+        for (String str : set) {
+            System.out.println(str);
+        }
+
+        /**
+         * 迭代器遍历
+         */
+//        Iterator<String> iterator = set.iterator();
+//        while (iterator.hasNext()){
+//            System.out.println(iterator.next());
+//        }
+        System.out.println("set集合元素个数:"+ set.size());
+        System.out.println("是否包含元素"+ set.contains("红楼梦"));
+    }
+}

+ 33 - 0
java-base-project10/day18/src/com/sf/_03_set/Test1.java

@@ -0,0 +1,33 @@
+package com.sf._03_set;
+
+import java.util.HashSet;
+
+public class Test1 {
+    public static void main(String[] args) {
+        Student student = new Student("zhangsan",10);
+        Student student1 = new Student("zhangsan",10);
+        Student student2 = new Student("lisi",20);
+
+        HashSet<Student> students = new HashSet<>();
+        students.add(student);
+        students.add(student1);
+        students.add(student2);
+
+        for (Student student3 : students) {
+            System.out.println(student3);
+        }
+        //Object 当中hashCode 方法默认是根据 对象的地址值来进行计算
+//        System.out.println(student.hashCode());
+//        System.out.println(student1.hashCode());
+
+        /**
+         * 创建HashSet
+         * 创建3 个Student 对象往里面存储    3 个对象中 有个2 对象内容是相同
+         * 1 先不重写hashCode 和 equals 方法
+         * 2 重写hashCode 不重写equals 方法
+         * 3 重写hashCode 方法并且重写equlas 方法
+         *
+         * 遍历hashSet 观察结果
+         */
+    }
+}

+ 85 - 0
java-base-project10/day18/src/com/sf/_04_set_contact/demo1/Book.java

@@ -0,0 +1,85 @@
+package com.sf._04_set_contact.demo1;
+
+import java.util.Objects;
+
+public class Book {
+    private String isbn;
+    private String name;
+    private String author;
+
+    public Book() {
+    }
+
+    public Book(String isbn, String name, String author) {
+        this.isbn = isbn;
+        this.name = name;
+        this.author = author;
+    }
+
+    @Override
+    public boolean equals(Object o) {
+        if (this == o) return true;
+        if (o == null || getClass() != o.getClass()) return false;
+        Book book = (Book) o;
+        return Objects.equals(isbn, book.isbn) &&
+                Objects.equals(name, book.name) &&
+                Objects.equals(author, book.author);
+    }
+
+    @Override
+    public int hashCode() {
+        return Objects.hash(isbn, name, author);
+    }
+
+    /**
+     * 获取
+     * @return isbn
+     */
+    public String getIsbn() {
+        return isbn;
+    }
+
+    /**
+     * 设置
+     * @param isbn
+     */
+    public void setIsbn(String isbn) {
+        this.isbn = isbn;
+    }
+
+    /**
+     * 获取
+     * @return name
+     */
+    public String getName() {
+        return name;
+    }
+
+    /**
+     * 设置
+     * @param name
+     */
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    /**
+     * 获取
+     * @return author
+     */
+    public String getAuthor() {
+        return author;
+    }
+
+    /**
+     * 设置
+     * @param author
+     */
+    public void setAuthor(String author) {
+        this.author = author;
+    }
+
+    public String toString() {
+        return "Book{isbn = " + isbn + ", name = " + name + ", author = " + author + "}";
+    }
+}

+ 118 - 0
java-base-project10/day18/src/com/sf/_04_set_contact/demo1/BorrowManager.java

@@ -0,0 +1,118 @@
+package com.sf._04_set_contact.demo1;
+
+import java.util.HashSet;
+import java.util.Iterator;
+
+public class BorrowManager {
+    // 存储借阅记录信息
+    static HashSet<BorrowRecord> recordHashSet = new HashSet<>();
+
+
+    /**
+     * 添加借阅记录信息到hashSet BorrowRecord
+     * 参数: 解决记录信息
+     */
+    public static void addBorrowRecord(BorrowRecord borrowRecord){
+        //找到我们要借阅书籍
+        Book book = borrowRecord.getBook();   //红楼梦
+        // 遍历recordHashSet
+        //("zhangsan",book(西游记),"2026/1/13") , ("lisi",book1(三国演义),"2026/1/13")
+        boolean flag = false;
+        for (BorrowRecord record : recordHashSet) {
+            // 获取已经借阅书籍
+            Book borrowBook = record.getBook();
+            // 判断要借的书 和已经借阅的书是否相同
+            if(borrowBook.equals(book)){
+                // 进来表示这本书已经被被人借走了
+                flag = true;
+                break;
+            }
+        }
+        // flag =true 表示被接走  如果flag = false 表示书没被借走
+        if(flag){
+            System.out.println("书已经被借走了");
+        }else{
+            // 把他添加到set 集合当中
+            System.out.println("借阅成功-借阅人:" + borrowRecord.getBorrower());
+            recordHashSet.add(borrowRecord);
+        }
+    }
+
+    /**
+     * 根据借阅人姓名查询他的借阅记录信息
+     * 1 可能最开始还没人借书籍recoredSet 是一个空
+     * 2 这个人他可能没有借书
+     */
+    public static void queryBorrowRecordByName(String name) {
+        // 当set .size 大于0 才进行遍历
+        if (recordHashSet.size() > 0) {
+            boolean flag = false;
+            for (BorrowRecord borrowRecord : recordHashSet) {
+                // 比较name 和 借阅记录name 进行比较
+                if (borrowRecord.getBorrower().equals(name)) {
+                    flag = true;
+                    System.out.println("借阅人:"+ borrowRecord.getBorrower() +"借阅书籍:"+ borrowRecord.getBook().getName());
+                    break;
+                }
+            }
+            if(!flag){
+                System.out.println("借阅人没有借阅书籍");
+            }
+        }else{
+            System.out.println("当前没有人借阅书籍记录为空");
+        }
+
+    }
+
+    /**
+     * 查询借阅记录信息
+     */
+    public static void queryBorrowRecords(){
+        for (BorrowRecord borrowRecord : recordHashSet) {
+            System.out.println("借阅人:"+ borrowRecord.getBorrower()+"借阅书"+ borrowRecord.getBook().getName());
+        }
+    }
+
+    /**
+     * 根据书籍isbn 编号删除所有相关记录
+     * @param isbn
+     */
+    public static void removeRecordsByBookIsbn(String isbn){
+        if(recordHashSet.size()>0){
+            Iterator<BorrowRecord> iterator = recordHashSet.iterator();
+            while (iterator.hasNext()){
+                BorrowRecord borrowRecord = iterator.next();
+                if(borrowRecord.getBook().getIsbn().equals(isbn)){
+                    System.out.println("删除借阅记录借阅人:"+ borrowRecord.getBorrower()+"借阅书"+ borrowRecord.getBook().getName());
+                    iterator.remove();
+                }
+            }
+        }else{
+            System.out.println("现在没有任何记录");
+        }
+    }
+
+    public static void main(String[] args) {
+        Book book = new Book("01","西游记","吴承恩");
+        Book book1 = new Book("02" , "三国演义", "罗贯中");
+        //创建借阅记录
+        // 借阅人张三  借了 西游记 时间2026 1/13
+        BorrowRecord borrowRecord = new BorrowRecord("zhangsan",book,"2026/1/13");
+        BorrowRecord borrowRecord1 = new BorrowRecord("lisi",book1,"2026/1/13");
+        BorrowRecord borrowRecord2 = new BorrowRecord("lisi",book,"2026/1/13");
+        addBorrowRecord(borrowRecord);    //成功
+        // 同一个人不能够重复借阅同一本书
+        addBorrowRecord(borrowRecord1);   //成功
+//        // 为什么这步也成功了
+//        addBorrowRecord(borrowRecord2);
+////        addBorrowRecord(borrowRecord2);   //失败
+//        System.out.println("-----------------------------");
+////        queryBorrowRecords();
+//        queryBorrowRecordByName("zhangsan");
+//        queryBorrowRecordByName("wangwu");
+//
+        removeRecordsByBookIsbn("01");
+        queryBorrowRecords();
+
+    }
+}

+ 85 - 0
java-base-project10/day18/src/com/sf/_04_set_contact/demo1/BorrowRecord.java

@@ -0,0 +1,85 @@
+package com.sf._04_set_contact.demo1;
+
+import java.util.Objects;
+
+public class BorrowRecord {
+    private String borrower;
+    private Book book;
+    private String date;
+
+    @Override
+    public boolean equals(Object o) {
+        if (this == o) return true;
+        if (o == null || getClass() != o.getClass()) return false;
+        BorrowRecord that = (BorrowRecord) o;
+        return Objects.equals(borrower, that.borrower) &&
+                Objects.equals(book, that.book) &&
+                Objects.equals(date, that.date);
+    }
+
+    @Override
+    public int hashCode() {
+        return Objects.hash(borrower, book, date);
+    }
+
+    public BorrowRecord() {
+    }
+
+    public BorrowRecord(String borrower, Book book, String date) {
+        this.borrower = borrower;
+        this.book = book;
+        this.date = date;
+    }
+
+    /**
+     * 获取
+     * @return borrower
+     */
+    public String getBorrower() {
+        return borrower;
+    }
+
+    /**
+     * 设置
+     * @param borrower
+     */
+    public void setBorrower(String borrower) {
+        this.borrower = borrower;
+    }
+
+    /**
+     * 获取
+     * @return book
+     */
+    public Book getBook() {
+        return book;
+    }
+
+    /**
+     * 设置
+     * @param book
+     */
+    public void setBook(Book book) {
+        this.book = book;
+    }
+
+    /**
+     * 获取
+     * @return date
+     */
+    public String getDate() {
+        return date;
+    }
+
+    /**
+     * 设置
+     * @param date
+     */
+    public void setDate(String date) {
+        this.date = date;
+    }
+
+    public String toString() {
+        return "BorrowRecord{borrower = " + borrower + ", book = " + book + ", date = " + date + "}";
+    }
+}

+ 88 - 0
java-base-project10/day18/src/com/sf/_04_set_contact/demo2/ExchangeGoods.java

@@ -0,0 +1,88 @@
+package com.sf._04_set_contact.demo2;
+
+import java.util.Objects;
+
+/**
+ * 兑换商品类
+ */
+public class ExchangeGoods {
+    private String code;  // 商品编码
+    private String name;  // 商品名称
+    private int points;   // 所需积分
+
+    @Override
+    public boolean equals(Object o) {
+        if (this == o) return true;
+        if (o == null || getClass() != o.getClass()) return false;
+        ExchangeGoods goods = (ExchangeGoods) o;
+        return points == goods.points &&
+                Objects.equals(code, goods.code) &&
+                Objects.equals(name, goods.name);
+    }
+
+    @Override
+    public int hashCode() {
+        return Objects.hash(code, name, points);
+    }
+
+    public ExchangeGoods() {
+    }
+
+    public ExchangeGoods(String code, String name, int points) {
+        this.code = code;
+        this.name = name;
+        this.points = points;
+    }
+
+    /**
+     * 获取
+     * @return code
+     */
+    public String getCode() {
+        return code;
+    }
+
+    /**
+     * 设置
+     * @param code
+     */
+    public void setCode(String code) {
+        this.code = code;
+    }
+
+    /**
+     * 获取
+     * @return name
+     */
+    public String getName() {
+        return name;
+    }
+
+    /**
+     * 设置
+     * @param name
+     */
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    /**
+     * 获取
+     * @return points
+     */
+    public int getPoints() {
+        return points;
+    }
+
+    /**
+     * 设置
+     * @param points
+     */
+    public void setPoints(int points) {
+        this.points = points;
+    }
+
+    public String toString() {
+        return "ExchangeGoods{code = " + code + ", name = " + name + ", points = " + points + "}";
+    }
+}

+ 146 - 0
java-base-project10/day18/src/com/sf/_04_set_contact/demo2/ExchangeManager.java

@@ -0,0 +1,146 @@
+package com.sf._04_set_contact.demo2;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+
+public class ExchangeManager {
+    // 存储兑换记录信息集合
+    static HashSet<ExchangeRecord> records = new HashSet<>();
+    // 存储所有会员信息
+    static List<Member> members = new ArrayList<>();
+
+
+    /**
+     * 交换商品方法
+     *
+     */
+    public static void exchangeGoods(Member member,ExchangeGoods goods,String date){
+        // 1 判断会员是否存在
+        if(!members.contains(member)){
+            System.out.println("会员不存在");
+            return;
+        }
+        // 2 获取会员积分,和兑换商品积分进行比较
+        int leftPoints = member.getLeftPoints();
+        int points = goods.getPoints();
+        // 3 如果积分不足提醒积分不足
+        if(leftPoints < points){
+            System.out.println("积分不足");
+            return;
+        }
+        // 4 如果积分充足,创建兑换记录对象
+        ExchangeRecord exchangeRecord = new ExchangeRecord(member,goods,date);
+        // 5 把兑换记录添加set集合中
+        //exchangeRecords 兑换记录  (member(1,zhangsan,3000),exchanggood(1,玩具,1000),date)
+        // 判断用户之前是否已经兑换了商品
+        boolean flag = isMemberExchangeGood(goods,member);
+        if(!flag){
+            // 6 如果添加成功,提醒添加成功,扣减积分
+            // 修改set 集合当中积分  , set 集合没有获取单个数据方法也没有修改方法
+            // set 当中数据存储会员信息 可以进行去重操作 最简单方式就是把set 改成list
+            // memeber   List
+            // {id,name,剩余积分}     List( {1,zhangsan,3000} , {2,lisi,3000})
+            // 找到对应集合当中会员扣减相应积分
+            /**
+             * 1 如何找到对应会员信息  需要什么信息?   memberId
+             * 2 找到了扣减应该扣减多少需要什么信息?   goods.getPoints();
+             */
+            changePoints(member.getId(),goods.getPoints());
+            // 添加兑换记录
+            records.add(exchangeRecord);
+            System.out.println("恭喜"+member.getName()+"兑换成功"+goods.getName() +"扣减了"+ goods.getPoints());
+        }else{
+            // 7 如果添加失败,提醒已经兑换过次商品了
+            System.out.println("之前您已经对话过这个商品了请不要重复兑换");
+        }
+    }
+
+    /**
+     *
+     * 判断会员是否已经兑换了商品
+     * set({(1,zhangsan,2000),(1,玩具,1000),2026/1/14},{(1,zhangsan,2000),(1,玩具,1000),2026/1/14})
+     * @param goods   (1,玩具,1000)
+     * @param member  (1,zhangsan,2000)
+     * @return  如果是true 表示之前兑换过,如果是false 表示之前没有兑换过
+     */
+    private static boolean isMemberExchangeGood(ExchangeGoods goods, Member member) {
+        boolean flag = false;
+        for (ExchangeRecord record : records) {
+            Member recordMember = record.getMember();
+            ExchangeGoods recordExchangeGoods = record.getExchangeGoods();
+            // 判断此次操作会员id 如果和兑换记录id 想通 并且 兑换商品名称也和兑换记录商品名称相同
+            if(member.getId().equals(recordMember.getId()) &&
+                    recordExchangeGoods.getName().equals(goods.getName())){
+                return true;
+            }
+        }
+        return flag;
+    }
+
+    private static void changePoints(Long id, int points) {
+        // memberId 会员id   扣减积分
+        // 找到会员   list
+        for (int i = 0; i < members.size(); i++) {
+            Member member = members.get(i);
+            // 这个是要修改会员信息
+            if(member.getId().equals(id)){
+                // 修改积分 用会员剩余积分-兑换商品积分
+                member.setLeftPoints(member.getLeftPoints()-points);
+                // 重新设置到集合中
+                members.set(i,member);
+            }
+        }
+    }
+
+
+    public static void main(String[] args) {
+        // 创建3 个要兑换商品
+        ExchangeGoods goods1 = new ExchangeGoods("01","玩偶",1000);
+        ExchangeGoods goods2 = new ExchangeGoods("02","玩具",1000);
+        ExchangeGoods goods3 = new ExchangeGoods("03","水彩笔",1000);
+
+        // 创建会员信息
+        Member member = new Member(1l,"zhangsan",3000);
+        Member member1 = new Member(2l,"lisi",3000);
+        // 把这两个会员添加set 集合中
+        members.add(member);
+        members.add(member1);
+
+        exchangeGoods(member,goods1,"2026/1/13");
+        exchangeGoods(member,goods1,"2026/1/13");
+        exchangeGoods(member1,goods1,"2026/1/13");
+
+//        for (Member m : members) {
+//            System.out.println(m);
+//        }
+        printExchangeRecords();
+
+        queryExchangeGoodsCount("01");
+    }
+
+    /**
+     * 根据商品编码查询商品兑换了多少次
+     * 核心思路遍历看比较商品编码如果相同就让count++
+     */
+    public static void queryExchangeGoodsCount(String code){
+        // 遍历兑换记录  比较商品编码是否相同
+        int count = 0;
+        for (ExchangeRecord record : records) {
+            if(code.equals(record.getExchangeGoods().getCode())){
+                count++;
+            }
+        }
+        System.out.println("code :"+ code+"商品兑换了:"+ count+" 次");
+    }
+
+
+    /**
+     * 打印所有兑换记录信息
+     */
+    public static void printExchangeRecords(){
+        for (ExchangeRecord record : records) {
+            System.out.println("兑换人:"+ record.getMember().getName()+"兑换了商品:"+ record.getExchangeGoods().getName());
+        }
+    }
+}

+ 91 - 0
java-base-project10/day18/src/com/sf/_04_set_contact/demo2/ExchangeRecord.java

@@ -0,0 +1,91 @@
+package com.sf._04_set_contact.demo2;
+
+import java.util.Objects;
+
+/**
+ * 兑换记录类
+ */
+public class ExchangeRecord {
+    // 会员信息
+    private Member member;
+    // 兑换商品信息
+    private ExchangeGoods exchangeGoods;
+    // 兑换日期
+    private String date;
+
+    @Override
+    public boolean equals(Object o) {
+        if (this == o) return true;
+        if (o == null || getClass() != o.getClass()) return false;
+        ExchangeRecord that = (ExchangeRecord) o;
+        return Objects.equals(member, that.member) &&
+                Objects.equals(exchangeGoods, that.exchangeGoods) &&
+                Objects.equals(date, that.date);
+    }
+
+    @Override
+    public int hashCode() {
+        return Objects.hash(member, exchangeGoods, date);
+    }
+
+    public ExchangeRecord() {
+    }
+
+    public ExchangeRecord(Member member, ExchangeGoods exchangeGoods, String date) {
+        this.member = member;
+        this.exchangeGoods = exchangeGoods;
+        this.date = date;
+    }
+
+    /**
+     * 获取
+     * @return member
+     */
+    public Member getMember() {
+        return member;
+    }
+
+    /**
+     * 设置
+     * @param member
+     */
+    public void setMember(Member member) {
+        this.member = member;
+    }
+
+    /**
+     * 获取
+     * @return exchangeGoods
+     */
+    public ExchangeGoods getExchangeGoods() {
+        return exchangeGoods;
+    }
+
+    /**
+     * 设置
+     * @param exchangeGoods
+     */
+    public void setExchangeGoods(ExchangeGoods exchangeGoods) {
+        this.exchangeGoods = exchangeGoods;
+    }
+
+    /**
+     * 获取
+     * @return date
+     */
+    public String getDate() {
+        return date;
+    }
+
+    /**
+     * 设置
+     * @param date
+     */
+    public void setDate(String date) {
+        this.date = date;
+    }
+
+    public String toString() {
+        return "ExchangeRecord{member = " + member + ", exchangeGoods = " + exchangeGoods + ", date = " + date + "}";
+    }
+}

+ 88 - 0
java-base-project10/day18/src/com/sf/_04_set_contact/demo2/Member.java

@@ -0,0 +1,88 @@
+package com.sf._04_set_contact.demo2;
+
+import java.util.Objects;
+
+/**
+ * 会员类
+ */
+public class Member {
+    private Long id;    // 会员id
+    private String name;  // 会员名称
+    private int leftPoints;  // 会员剩余积分
+
+    @Override
+    public boolean equals(Object o) {
+        if (this == o) return true;
+        if (o == null || getClass() != o.getClass()) return false;
+        Member member = (Member) o;
+        return leftPoints == member.leftPoints &&
+                Objects.equals(id, member.id) &&
+                Objects.equals(name, member.name);
+    }
+
+    @Override
+    public int hashCode() {
+        return Objects.hash(id, name, leftPoints);
+    }
+
+    public Member() {
+    }
+
+    public Member(Long id, String name, int leftPoints) {
+        this.id = id;
+        this.name = name;
+        this.leftPoints = leftPoints;
+    }
+
+    /**
+     * 获取
+     * @return id
+     */
+    public Long getId() {
+        return id;
+    }
+
+    /**
+     * 设置
+     * @param id
+     */
+    public void setId(Long id) {
+        this.id = id;
+    }
+
+    /**
+     * 获取
+     * @return name
+     */
+    public String getName() {
+        return name;
+    }
+
+    /**
+     * 设置
+     * @param name
+     */
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    /**
+     * 获取
+     * @return leftPoints
+     */
+    public int getLeftPoints() {
+        return leftPoints;
+    }
+
+    /**
+     * 设置
+     * @param leftPoints
+     */
+    public void setLeftPoints(int leftPoints) {
+        this.leftPoints = leftPoints;
+    }
+
+    public String toString() {
+        return "Member{id = " + id + ", name = " + name + ", leftPoints = " + leftPoints + "}";
+    }
+}

+ 11 - 0
java-base-project10/day19/day19.iml

@@ -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>

+ 69 - 0
java-base-project10/day19/src/com/sf/_01_treeset/demo/Student.java

@@ -0,0 +1,69 @@
+package com.sf._01_treeset.demo;
+
+/**
+ * Comparable<T>
+ * 往树节点中存储数据类型
+ */
+public class Student implements Comparable<Student> {
+    private String name;
+    private int age;
+
+    public Student() {
+    }
+
+    public Student(String name, int age) {
+        this.name = name;
+        this.age = age;
+    }
+
+    /**
+     * 获取
+     * @return name
+     */
+    public String getName() {
+        return name;
+    }
+
+    /**
+     * 设置
+     * @param name
+     */
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    /**
+     * 获取
+     * @return age
+     */
+    public int getAge() {
+        return age;
+    }
+
+    /**
+     * 设置
+     * @param age
+     */
+    public void setAge(int age) {
+        this.age = age;
+    }
+
+    public String toString() {
+        return "Student{name = " + name + ", age = " + age + "}";
+    }
+
+    /**
+     * 要年龄
+     * @return
+     */
+    @Override
+    public int compareTo(Student stu) {
+        if(this.age > stu.getAge()){
+            return 1;
+        }else if(this.age < stu.getAge()){
+            return -1;
+        }else{
+            return 0;
+        }
+    }
+}

+ 39 - 0
java-base-project10/day19/src/com/sf/_01_treeset/demo/Test.java

@@ -0,0 +1,39 @@
+package com.sf._01_treeset.demo;
+
+import java.util.TreeSet;
+
+public class Test {
+    /**
+     * TreeSet
+     * 特点: 可以去除重复数据 , 并且有序
+     *
+     * 底层数据结构红黑树
+     *
+     * 往treeSet 当中存储元素要求必须要实现Comparable
+     * @param args
+     */
+    public static void main(String[] args) {
+        /**
+         * TreeSet 创建
+         * 往里面添加5个数据
+         * 2 1 1 3 4 5
+         * add()
+         */
+        TreeSet<Integer> treeSet = new TreeSet<>();
+        treeSet.add(2);
+        treeSet.add(1);
+        treeSet.add(1);
+        treeSet.add(3);
+        treeSet.add(4);
+        treeSet.add(5);
+        // 判断treeSet 是否包含某一个元素
+        System.out.println(treeSet.contains(2));
+        // 查看treeSet 集合大小
+        System.out.println(treeSet.size());
+        // remove 删除treeSet 当中元素内容
+        treeSet.remove(2);
+        // isEmpty()  判断treeSet 集合是否为空
+        System.out.println(treeSet.isEmpty());
+        System.out.println(treeSet);
+    }
+}

+ 20 - 0
java-base-project10/day19/src/com/sf/_01_treeset/demo/Test1.java

@@ -0,0 +1,20 @@
+package com.sf._01_treeset.demo;
+
+import java.util.TreeSet;
+
+public class Test1 {
+    public static void main(String[] args) {
+        /**
+         *  1 创建一个Student  name age
+         *  2 往treeset 存储 3 个student;
+         *
+         *  往treeSet 当中存储元素都必须要具备比较能力才能存储到树结构中
+         *  怎么让元素具备比较能力
+         */
+        TreeSet<Student> treeSet = new TreeSet<>();
+        treeSet.add(new Student("zhangsan",10));
+        treeSet.add(new Student("lisi",40));
+        treeSet.add(new Student("wangwu",30));
+        System.out.println(treeSet);
+    }
+}

+ 108 - 0
java-base-project10/day19/src/com/sf/_01_treeset/demo1/Employee.java

@@ -0,0 +1,108 @@
+package com.sf._01_treeset.demo1;
+
+public class Employee implements Comparable<Employee> {
+    private Long id;
+    private String name;
+    private int age;
+    private double salary;
+
+
+    public Employee() {
+    }
+
+    public Employee(Long id, String name, int age, double salary) {
+        this.id = id;
+        this.name = name;
+        this.age = age;
+        this.salary = salary;
+    }
+
+    /**
+     * 获取
+     * @return id
+     */
+    public Long getId() {
+        return id;
+    }
+
+    /**
+     * 设置
+     * @param id
+     */
+    public void setId(Long id) {
+        this.id = id;
+    }
+
+    /**
+     * 获取
+     * @return name
+     */
+    public String getName() {
+        return name;
+    }
+
+    /**
+     * 设置
+     * @param name
+     */
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    /**
+     * 获取
+     * @return age
+     */
+    public int getAge() {
+        return age;
+    }
+
+    /**
+     * 设置
+     * @param age
+     */
+    public void setAge(int age) {
+        this.age = age;
+    }
+
+    /**
+     * 获取
+     * @return salary
+     */
+    public double getSalary() {
+        return salary;
+    }
+
+    /**
+     * 设置
+     * @param salary
+     */
+    public void setSalary(double salary) {
+        this.salary = salary;
+    }
+
+    public String toString() {
+        return "Employee{id = " + id + ", name = " + name + ", age = " + age + ", salary = " + salary + "}";
+    }
+
+    /**
+     * 先按照年龄进行从小到大排序, 如果年龄相同按照薪资从大到小进行降序排序
+     */
+    @Override
+    public int compareTo(Employee e) {
+        if(this.age > e.getAge()){
+            return 1;
+        }else if(this.age < e.getAge()){
+            return -1;
+        }{
+            // 如果相同在按照薪资排序
+            if(this.salary > e.getSalary()){
+                return -1;
+            }else if(this.salary < e.getSalary()){
+                return 1;
+            }else{
+                return 0;
+            }
+        }
+    }
+}

+ 46 - 0
java-base-project10/day19/src/com/sf/_01_treeset/demo1/Test2.java

@@ -0,0 +1,46 @@
+package com.sf._01_treeset.demo1;
+
+import java.util.Comparator;
+import java.util.TreeSet;
+
+public class Test2 {
+    /**
+     * Employee
+     * id  name age  salary
+     * 把Employee 存储到TreeSet 中
+     * 按照salary 从大到小排序
+     *
+     * 默认规则是先按照年龄小到大 如果年龄相同就按照薪资从大到小
+     *
+     * 用我自己的规则 先按照薪资从大到小 , 如果薪资相同在按照年龄从小到大
+     */
+    public static void main(String[] args) {
+        TreeSet<Employee> treeSet = new TreeSet<>(new Comparator<Employee>() {
+            @Override
+            public int compare(Employee o1, Employee o2) {
+                if(o1.getSalary()> o2.getSalary()){
+                    return -1;
+                }else if(o1.getSalary()< o2.getSalary()){
+                    return 1;
+                }else{
+                    if(o1.getAge() > o2.getAge()){
+                        return 1;
+                    }else if(o1.getAge() < o2.getAge()){
+                        return -1;
+                    }else{
+                        return 0;
+                    }
+                }
+            }
+        });
+        treeSet.add(new Employee(1L,"zhangsan",40,30000));
+        treeSet.add(new Employee(2L,"zhangsan1",20,50000));
+        treeSet.add(new Employee(3L,"zhangsan2",20,30000));
+        treeSet.add(new Employee(4L,"zhangsan3",30,40000));
+        // 2 4 3 1
+        System.out.println(treeSet);
+        for (Employee employee : treeSet) {
+            System.out.println(employee);
+        }
+    }
+}

+ 15 - 0
java-base-project10/day19/src/com/sf/_01_treeset/demo2/Test.java

@@ -0,0 +1,15 @@
+package com.sf._01_treeset.demo2;
+
+import java.util.TreeSet;
+
+public class Test {
+    public static void main(String[] args) {
+        TreeSet<User> treeSet = new TreeSet<>();
+        treeSet.add(new User("zhangsan",10));
+        treeSet.add(new User("zhangsan1",20));
+        treeSet.add(new User("zhangsan2",5));
+        for (User user : treeSet) {
+            System.out.println(user);
+        }
+    }
+}

+ 69 - 0
java-base-project10/day19/src/com/sf/_01_treeset/demo2/User.java

@@ -0,0 +1,69 @@
+package com.sf._01_treeset.demo2;
+
+public class User implements Comparable<User>{
+    private String name;
+    private Integer age;
+
+    public User() {
+    }
+
+    public User(String name, Integer age) {
+        this.name = name;
+        this.age = age;
+    }
+
+    /**
+     * 获取
+     * @return name
+     */
+    public String getName() {
+        return name;
+    }
+
+    /**
+     * 设置
+     * @param name
+     */
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    /**
+     * 获取
+     * @return age
+     */
+    public Integer getAge() {
+        return age;
+    }
+
+    /**
+     * 设置
+     * @param age
+     */
+    public void setAge(Integer age) {
+        this.age = age;
+    }
+
+    public String toString() {
+        return "User{name = " + name + ", age = " + age + "}";
+    }
+//    根据用户名长度升序排序,如果名字相同按照年龄升序排序。
+    @Override
+    public int compareTo(User o) {
+        int length = this.name.length();
+        int length1 = o.getName().length();
+        if(length > length1){
+            return 1;
+        }else if(length< length1){
+            return -1;
+        }else{
+            if(this.getAge() > o.getAge()){
+                return 1;
+            }else if(this.getAge() < o.getAge()){
+                return -1;
+            }else{
+                return 0;
+            }
+        }
+    }
+}

+ 76 - 0
java-base-project10/day19/src/com/sf/_02_hashmap/Test.java

@@ -0,0 +1,76 @@
+package com.sf._02_hashmap;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+public class Test {
+    /**
+     * HashMap 常用api
+     * HashMap 数据特点是采用键值对  key-value  必须成对出现
+     *
+     * key 不能够重复    value 可以重复
+     * 一般hashMap key 通常情况下用string  value 类型不做限制
+     * @param args
+     */
+    public static void main(String[] args) {
+        /**
+         * put : 存储一个key-value 键值对
+         * putAll :  存储多个key-value
+         */
+        HashMap<String,Object> map = new HashMap<>();
+        map.put("name","zhangsan");
+        map.put("age",10);
+        map.put("email","123@qq.com");
+
+//        HashMap<String,Object> map1= new HashMap<>();
+//        map1.put("name1","zhangsan");
+//        map1.put("age1",10);
+//        map.putAll(map1);
+//        System.out.println(map);
+        /**
+         * remove(key)
+         * 删除name 键值对
+         */
+        map.remove("name");
+
+        /**
+         * map 当中没有特定修改的方法
+         * 如果想要修改数据直接调用put方法
+         *
+         * put 如果key 相同就会把value 的值给进行覆盖
+         */
+        map.put("age",20);
+//        System.out.println(map);
+//
+//        System.out.println("一共有:"+map.size()+"键值对");
+//        System.out.println("map 当中是否为空:"+map.isEmpty());
+//        System.out.println("age 的值是"+ map.get("age"));
+//        System.out.println("是否包含name 这个key"+ map.containsKey("name"));
+//        System.out.println("是否包含zhangsan 这个value"+ map.containsValue("zhangsan"));
+
+
+        Set<String> set = map.keySet();
+//        System.out.println(set);
+
+        Collection<Object> values = map.values();
+//        System.out.println(values);
+
+        /**
+         * 如果想要遍历map
+         * name - zhangsan
+         * age - 20
+         * email - 123@qq.com
+         */
+        // 方式一:
+        for (String key : set) {
+            System.out.println(key+"-"+map.get(key));
+        }
+        // 方式二:
+        // map.entry
+        for (Map.Entry<String, Object> entry : map.entrySet()) {
+            System.out.println(entry.getKey()+"-"+entry.getValue());
+        }
+    }
+}

+ 25 - 0
java-base-project10/day19/src/com/sf/_02_hashmap/demo1/Test.java

@@ -0,0 +1,25 @@
+package com.sf._02_hashmap.demo1;
+
+import java.util.HashMap;
+
+public class Test {
+    public static void main(String[] args) {
+        String str = "ABCDEFABCDEABCDABCABA";
+        // 1 把字符串转成字符数组 toCharArray
+        char[] chars = str.toCharArray();
+        // 2 HashMap<Character,Integer> map
+        HashMap<Character,Integer> map = new HashMap<>();
+        // 3 遍历字符数组
+        for (char ch : chars) {
+            // 4 在遍历的过程中map 判断key 是否存在
+            if(!map.containsKey(ch)){
+                //   4.1 如果不存在就put(ch,1);
+                map.put(ch,1);
+            }else{
+                //   4.2 如果存在就put(ch,value+1)
+                map.put(ch,map.get(ch)+1);
+            }
+        }
+        System.out.println(map);
+    }
+}

+ 99 - 0
java-base-project10/day19/src/com/sf/_02_hashmap/demo2/ScoreManager.java

@@ -0,0 +1,99 @@
+package com.sf._02_hashmap.demo2;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class ScoreManager {
+    // 存储学生成绩
+    private static Map<Student,Double> studentsMap = new HashMap<>();
+    // 存储学生集合信息  某一个班级的所有学生
+    static List<Student> oneStudents = new ArrayList<>();
+    /**
+     * 添加成绩
+     * 把信息保存map  ,map  key-value
+     * key - Student  value_ score
+     */
+    public static void addScore(Student student , Double score){
+        // 判断录入学生是否是这个班级的
+        if(!oneStudents.contains(student)){
+            System.out.println("学生不是这个班级的!");
+            return;
+        }
+        studentsMap.put(student,score);
+    }
+
+    /**
+     * 批量添加成绩
+     * addAll(Map map)
+     */
+    public static void addAllScore(HashMap<Student,Double> map){
+        studentsMap.putAll(map);
+    }
+
+    /**
+     * 修改成绩
+     * put(key , value)
+     * student  double
+     */
+    public static void changeScore(Student student,Double score){
+        studentsMap.put(student,score);
+    }
+
+    /**
+     * 删除成绩
+     * 跟key 进行删除
+     * key student
+     */
+    public static void removeScore(Student student){
+        studentsMap.remove(student);
+    }
+
+    /**
+     * 查询成绩
+     */
+    public static void queryScore(){
+        for (Map.Entry<Student, Double> studentDoubleEntry : studentsMap.entrySet()) {
+            System.out.println("学生姓名:"+studentDoubleEntry.getKey().getName() +"成绩为:"+ studentDoubleEntry.getValue());
+        }
+    }
+
+    /**
+     * 查看及格人数
+     */
+    public static void queryScorePass(){
+        int count = 0;
+        for (Double score : studentsMap.values()) {
+            if(score >= 60){
+                count++;
+            }
+        }
+        System.out.println("及格人数:"+ count);
+    }
+
+    public static void main(String[] args) {
+        Student student = new Student(1L,"zhangsan");
+        Student student1 = new Student(2L,"lisi");
+
+        // 这两个学生添加一班的集合中
+        oneStudents.add(student);
+        oneStudents.add(student1);
+
+//        Student student2 = new Student(3L,"wangwu");
+//        addScore(student1,80.0);
+//        addScore(student,90.0);
+//
+//        System.out.println(studentsMap);
+        HashMap<Student,Double> map = new HashMap<>();
+        map.put(student,90.0);
+        map.put(student1,80.0);
+        addAllScore(map);
+
+//        changeScore(student,100.0);
+        queryScore();
+        queryScorePass();
+
+
+    }
+}

+ 51 - 0
java-base-project10/day19/src/com/sf/_02_hashmap/demo2/Student.java

@@ -0,0 +1,51 @@
+package com.sf._02_hashmap.demo2;
+
+public class Student {
+    private Long id;
+    private String name;
+
+
+    public Student() {
+    }
+
+    public Student(Long id, String name) {
+        this.id = id;
+        this.name = name;
+    }
+
+    /**
+     * 获取
+     * @return id
+     */
+    public Long getId() {
+        return id;
+    }
+
+    /**
+     * 设置
+     * @param id
+     */
+    public void setId(Long id) {
+        this.id = id;
+    }
+
+    /**
+     * 获取
+     * @return name
+     */
+    public String getName() {
+        return name;
+    }
+
+    /**
+     * 设置
+     * @param name
+     */
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public String toString() {
+        return "Student{id = " + id + ", name = " + name + "}";
+    }
+}

+ 29 - 0
java-base-project10/day19/src/com/sf/_02_hashmap/demo3/LoginService.java

@@ -0,0 +1,29 @@
+package com.sf._02_hashmap.demo3;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class LoginService {
+    private Map<String,User> map = new HashMap<>();
+
+    public LoginService() {
+        map.put("zhangsan",new User("zhangsan","123"));
+        map.put("lisi",new User("lisi","123"));
+    }
+
+    public void login(User user){
+        String username = user.getUsername();
+        // 1 根据用户上map 获取信息看是否存在
+        if(!map.containsKey(username)){
+            System.out.println("账号不存在");
+            return;
+        }
+        User mapUser = map.get(username);
+        // 2 如果存在比对密码
+        if(mapUser.getPassword().equals(user.getPassword())){
+            System.out.println("登录成功");
+        }else{
+            System.out.println("登录失败");
+        }
+    }
+}

+ 31 - 0
java-base-project10/day19/src/com/sf/_02_hashmap/demo3/Test.java

@@ -0,0 +1,31 @@
+package com.sf._02_hashmap.demo3;
+
+import java.util.Scanner;
+
+public class Test {
+
+    /**
+     * 1 User类这个类当中有username,password 提供get和set方法
+     * 2 创建LoginService  这个LoginService 当中提供Map<String(username),User>
+     * 3 给LoginService 提供无参构造器, 在无参构造器当中对于map进行初始化
+     *   map.put("zhangsan",new User(zhangsa,123)) ,map.put("lisi",new User("lisi,123))
+     * 4 在LoginService 当中提供一个登录方法login(User user)
+     *   4.1 获取user用户名
+     *   4.2 根据用户名上map 当中获取信息看是否有信息,如果没有提醒用户名不存在
+     *   4.3 如果获取信息, 判断密码是否一致, 如果一致登录成功,如果不一致登录失败
+     * 在测试中
+     *    1在控制台当中录入username 和password , 把信息封装User中
+     *    2创建LoginService() , 调用login 方法
+     */
+    public static void main(String[] args) {
+        Scanner scanner = new Scanner(System.in);
+        System.out.println("请录入账号:");
+        String username = scanner.next();
+        System.out.println("请输入密码:");
+        String password = scanner.next();
+
+        User user = new User(username,password);
+        LoginService loginService = new LoginService();
+        loginService.login(user);
+    }
+}

+ 50 - 0
java-base-project10/day19/src/com/sf/_02_hashmap/demo3/User.java

@@ -0,0 +1,50 @@
+package com.sf._02_hashmap.demo3;
+
+public class User {
+    private String username;
+    private String password;
+
+    public User() {
+    }
+
+    public User(String username, String password) {
+        this.username = username;
+        this.password = password;
+    }
+
+    /**
+     * 获取
+     * @return username
+     */
+    public String getUsername() {
+        return username;
+    }
+
+    /**
+     * 设置
+     * @param username
+     */
+    public void setUsername(String username) {
+        this.username = username;
+    }
+
+    /**
+     * 获取
+     * @return password
+     */
+    public String getPassword() {
+        return password;
+    }
+
+    /**
+     * 设置
+     * @param password
+     */
+    public void setPassword(String password) {
+        this.password = password;
+    }
+
+    public String toString() {
+        return "User{username = " + username + ", password = " + password + "}";
+    }
+}

+ 61 - 0
java-base-project10/day19/src/com/sf/_03_treemap/Student.java

@@ -0,0 +1,61 @@
+package com.sf._03_treemap;
+
+public class Student implements Comparable<Student>{
+    private String name;
+    private Integer age;
+
+    public Student() {
+    }
+
+    public Student(String name, Integer age) {
+        this.name = name;
+        this.age = age;
+    }
+
+    @Override
+    public int compareTo(Student o) {
+        if(this.getAge() > o.getAge()){
+            return -1;
+        }else if(this.getAge() < o.getAge()){
+            return 1;
+        }else{
+            return 0;
+        }
+    }
+
+    /**
+     * 获取
+     * @return name
+     */
+    public String getName() {
+        return name;
+    }
+
+    /**
+     * 设置
+     * @param name
+     */
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    /**
+     * 获取
+     * @return age
+     */
+    public Integer getAge() {
+        return age;
+    }
+
+    /**
+     * 设置
+     * @param age
+     */
+    public void setAge(Integer age) {
+        this.age = age;
+    }
+
+    public String toString() {
+        return "Student{name = " + name + ", age = " + age + "}";
+    }
+}

+ 21 - 0
java-base-project10/day19/src/com/sf/_03_treemap/Test.java

@@ -0,0 +1,21 @@
+package com.sf._03_treemap;
+
+import java.util.TreeMap;
+
+public class Test {
+    public static void main(String[] args) {
+        // 往treemap 存储 student-score  , 按照student 年龄进行降序排序
+        TreeMap<Student,Integer> map = new TreeMap<>();
+        map.put(new Student("zhangsan",30),80);
+        map.put(new Student("zhangsan3",20),90);
+        map.put(new Student("zhangsan2",40),70);
+        map.put(new Student("zhangsan1",25),60);
+        System.out.println(map);
+
+//
+//        map.remove(1);
+//        System.out.println(map);
+//        System.out.println(map.get(4));
+
+    }
+}