four 1 ヶ月 前
コミット
2844a456f9

+ 11 - 0
day06/day06.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>

+ 2 - 0
day06/src/com/four/day06/DemoMethod01.java

@@ -0,0 +1,2 @@
+package com.four.day06;public class DemoMethod01 {
+}

+ 237 - 0
day06/src/com/four/day06/DemoMethod02.java

@@ -0,0 +1,237 @@
+package com.four.day06;
+
+import java.util.Arrays;
+import java.util.Random;
+import java.util.Scanner;
+
+public class DemoMethod01 {
+
+    public static void main(String[] args) {
+//        double 头等舱 = calculate(101, "qq", 1000);
+//        System.out.println(头等舱);
+
+
+//        String code = createCode(4);
+//        System.out.println(code);
+//
+//
+//        System.out.println((int)'a');
+//        System.out.println((int)'z');
+
+
+//        double averageScore = getAverageScore(4);
+//        System.out.println(averageScore);
+
+
+//        int encrypt = encrypt(1983);
+//        System.out.println(encrypt);
+
+        int[] arr = {11,22,33};
+        System.out.println(arr);
+        int[] ints = copyArr(arr);
+        System.out.println(ints);
+
+        //源码
+        int[] ints1 = Arrays.copyOf(arr,2);
+        System.out.println(ints1);
+
+        int[] arr2 = {11,22,33,44,55};
+        System.out.println(arr2);
+        int[] ints2 = copyArr2(arr2);
+        System.out.println(ints2);
+
+        /*
+
+
+
+        src – the source array.
+        srcPos – starting position in the source array.
+        dest – the destination array.
+        destPos – starting position in the destination data.
+        length – the number of array elements to be copied.
+        System.arraycopy(original, 0, copy, 0,
+                         Math.min(original.length, newLength));
+
+        //nactive 本地方法 底层 用c 编写。
+        public static native void arraycopy(Object src,  int  srcPos,
+                                        Object dest, int destPos,
+                                        int length);
+         */
+
+    }
+    /*
+     * - 参数  原价、月份、舱位类型
+     * - 返回值 :机票价格,类型double
+     * - 业务逻辑
+     *        5-10 头 9  经济 8.5
+     *        11-4  头 7  经济 6.5
+     *  根据 月份判断  根据船舱类型
+     */
+
+    public static double calculate( int month , String type , int price ) {
+        //健壮性判断
+        //月份判断
+        if ( month < 1 || month > 12 ){
+            System.out.println("月份不符合规范");
+            return -1;
+        }
+
+        //单或者
+        if ( !type.equals("头等舱")  && !type.equals("经济舱") ){
+            System.out.println("类型不符合规范");
+            return -1;
+        }
+
+        //折扣价
+        double resultPrice = -1;
+
+        //判断类型
+        switch ( type ){
+            case "头等舱":
+                if ( month >= 5 && month <= 10  ){
+                    resultPrice = price * 0.9;
+                }else{
+                    resultPrice =  price * 0.8;
+                }
+                break;
+            case "经济舱":
+                if ( month >= 5 && month <= 10  ){
+                    resultPrice = price * 0.85;
+                }else{
+                    resultPrice =  price * 0.65;
+                }
+                break;
+        }
+        return resultPrice;
+    }
+
+
+    public static String createCode( int num ){
+        //数字  字母  大小写
+
+        //循环
+        //随机   数字 0  大字母 1  小写字母 2
+        //数字 0-9
+        //大字母 A-Z   65 + 26
+        //小写字母 a-z 97+26
+        Random r = new Random();
+        String str = "";
+
+        for (int i = 0; i < num ; i++) {
+            //随机数
+            int number = r.nextInt(3);
+            //switch
+            switch (number){
+                case 0:
+                    str += r.nextInt(10);
+                    break;
+
+                case 1:
+                    str += (char) (r.nextInt(26) + 65);
+                    break;
+                case 2:
+                    str += (char) (r.nextInt(26) + 97);
+                    break;
+            }
+        }
+        return str;
+    }
+
+
+
+    public static double getAverageScore( int n ){
+        Scanner sc = new Scanner(System.in);
+        //健壮性
+        //数组的长度 = n
+        int[] arr = new int[n];
+        //赋值
+        for (int i = 0; i < n ; i++) {
+            System.out.println("请输入0-100之间的数字");
+            int number = sc.nextInt();
+            if ( number < 0  || number > 100 ){
+                System.out.println("输入的不符号规范,请重新输入");
+                i--;
+            }
+            //赋值
+            arr[i] = number;
+        }
+
+        //获取数组中的最大值和最小值
+        //最大值  最小值 和
+        int max = arr[0];
+        int min = arr[0];
+        int sum = 0;
+
+        for (int i = 0; i < arr.length; i++) {
+            if ( arr[i] > max ){
+                max = arr[i];
+            }
+            if ( arr[i] < min ){
+                min = arr[i];
+            }
+            sum += arr[i];
+        }
+        return (sum - max -min)  / (n-2);
+    }
+
+    public static int encrypt(int n){
+        if ( n <1000 || n >= 10000 ){
+            System.out.println("数字不符合四位数");
+            return -1;
+        }
+        //数组
+        int[] arr = new int[4];
+        arr[0] = n/1000;
+        arr[1] = n /100 % 10;
+        arr[2] = n /10  % 10;
+        arr[3] = n % 10;
+
+        //+ 5 取余数
+        for (int i = 0; i < arr.length; i++) {
+            arr[i] += 5;
+            //余数
+            arr[i] %= 10;
+        }
+        //反转
+        for (int i = 0,j= arr.length-1; i < j ; i++,j--) {
+            int temp = arr[i];
+            arr[i] = arr[j];
+            arr[j] = temp;
+        }
+
+        String str = "";
+        //获取每一位数字
+        for (int i = 0; i < arr.length; i++) {
+            str+=arr[i];
+        }
+        //转换
+        return Integer.parseInt(str);
+    }
+
+
+    public static int[] copyArr(int[] source  ){
+        //健壮性
+        // null 长度
+        //创建数组长度
+        int[] dest = new int[source.length];
+
+        //赋值内容
+        for (int i = 0; i < source.length; i++) {
+            dest[i] = source[i];
+        }
+
+        return dest;
+    }
+
+    public static int[] copyArr2(int[] source  ){
+        //健壮性
+        // null 长度
+        //创建数组长度
+        int[] dest = new int[source.length];
+        //复制数组
+        System.arraycopy(source,0,dest,0,source.length);
+
+        return dest;
+    }
+
+}

+ 126 - 0
day06/src/com/four/day06/DemoMethod03.java

@@ -0,0 +1,126 @@
+package com.four.day06;
+
+import java.util.Arrays;
+import java.util.Random;
+import java.util.Scanner;
+
+public class DemoMethod02 {
+
+    public static void main(String[] args) {
+
+//        int[] arr = {8,100,520,1333,8,19};
+//
+//        start(arr);
+
+
+//        int[] ints = start2(10, 200);
+//        System.out.println(Arrays.toString(ints));
+
+
+        int search = search(100, 10000);
+        System.out.println(search); //97 14 3
+
+    }
+
+
+    public static void start(int[] arr) {
+        //抽取
+        //输入抽取
+        // 随机的
+        // 抽取到红包  恭喜您抽中了:红包
+        //  9 改变 = 0
+        // =0 未抽中 :提示 未中奖,请继续。
+        Scanner sc = new Scanner(System.in);
+        Random r = new Random();
+
+        for (int i = 0; i < arr.length; i++) {
+            System.out.println("请输入名称抽奖");
+            String name = sc.next();
+            //随机值
+            int num = r.nextInt(arr.length);
+            //根据随机的下表
+            int money = arr[num];
+            if ( money != 0 ){
+                System.out.println("恭喜:"+name+":抽中了:"+money);
+                //改变为0
+                arr[num] = 0;
+            }else {
+                System.out.println("未抽中请继续");
+                i--;
+            }
+        }
+    }
+
+    /**
+     * 参数 个数  金额
+     * 举例:
+     * 红包金额: 200
+     * 个数: 10
+     * 100,50,10,10,10,10,1,1,1,7
+     *
+     *  需要让后面的红包  够分。
+     */
+    public static int[] start2(int number ,int money) {
+
+        //数组
+        //循环数组赋值
+        //总金额 - 剩余红包个数 =  随机 赋值给数组
+        //总金额 -= 随机数
+        Random r = new Random();
+        //数组
+        int[] arr = new int[number];
+        //循环
+        for (int i = 0; i < arr.length-1 ; i++) {
+            //赋值
+            int e = r.nextInt(money - (arr.length - 1 - i))+1;
+            arr[i] = e ;
+            //金额
+            money -= e;
+        }
+
+        //最后一个赋值
+        arr[arr.length-1] = money;
+
+        return arr;
+    }
+
+
+    /**
+     * search
+     * 101~200之间的素数
+     */
+    public static int search( int start, int end ){
+        //循环 101~200
+        //判断 99
+            // 从2开始 取余  2-98
+            // 从2 - 数字的平方。     25   2-5 确定素数
+        //对结果取值
+        // 是 true 计数 ++
+        long s = System.currentTimeMillis();
+        int count = 0;
+
+        for (int i = start; i <= end ; i++) {
+
+            //判断
+            if ( check(i) ){
+                count++;
+            }
+        }
+        long e = System.currentTimeMillis();
+        System.out.println(e-s);
+        return count;
+    }
+
+
+    public static boolean check( int number ) {
+        //判断
+        for (int j = 2; j <= Math.sqrt(number) ; j++) {
+            if ( number % j == 0 ) {
+
+                return false;
+            }
+        }
+        return true;
+    }
+
+}

+ 11 - 0
day07/day07.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>

+ 2 - 0
day07/src/com/four/day07/demo04/Demo.java

@@ -0,0 +1,2 @@
+package com.four.day07.demo04;public class Demo {
+}

+ 2 - 0
day07/src/com/four/day07/demo04/Triangle.java

@@ -0,0 +1,2 @@
+package com.four.day07.demo04;public class Triangle {
+}

+ 28 - 0
day07/src/com/four/day07/demo04/TriangleUtils.java

@@ -0,0 +1,28 @@
+package com.four.day07.demo04;
+
+public class Triangle {
+
+    public int a;
+    public int b;
+    public int c;
+
+
+    /**
+     * 获取面积的方法
+     * 海伦公式
+     */
+    public double getArea(){
+        //健壮性验证。
+
+        double p = (a+b+c)/2;
+        return Math.sqrt(p * (p - a) * (p - b) * (p - c));
+    }
+
+    /**
+     * 获取周长
+     */
+    public double getPerimeter(){
+        return a+b+c;
+    }
+
+}

+ 4 - 0
day07/src/com/four/day07/demo05/Demo01.java

@@ -0,0 +1,4 @@
+package com.four.day07.demo05;
+
+public class Demo01 {
+}

+ 2 - 0
day07/src/com/four/day07/demo05/Person.java

@@ -0,0 +1,2 @@
+package com.four.day07.demo05;public class Person {
+}

+ 35 - 0
day07/src/com/four/day07/demo1/Demo01.java

@@ -0,0 +1,35 @@
+package com.four.day07;
+
+public class Demo01 {
+    public static void main(String[] args) {
+        //创建对象
+        //类就是类型
+        Student s1 = new Student();
+        //类似地址
+        System.out.println(s1);
+        // 地址值 01010011001010101010011
+
+        //面向对象思想
+        //指挥者
+        //属性
+        System.out.println(s1.name); //? null
+
+        //赋值
+        s1.name = "赵四";
+        s1.idCard = "20240101001";
+        s1.age = 19;
+        s1.marjoy = "计算机";
+
+        System.out.println(s1.name);
+        System.out.println(s1.idCard);
+        System.out.println(s1.age);
+        System.out.println(s1.marjoy);
+
+
+        //方法
+        s1.study();
+        s1.up();
+
+
+    }
+}

+ 26 - 0
day07/src/com/four/day07/demo1/Demo02.java

@@ -0,0 +1,26 @@
+package com.four.day07;
+
+public class Demo02 {
+
+    public static void main(String[] args) {
+        //类变量
+        //Teacher.schoolName = "哈三中";
+
+        //所有对象共享
+        Teacher teacher1 = new Teacher();
+        //不推荐
+        System.out.println(teacher1.schoolName);
+
+        //Teacher.schoolName ="哈九中";
+        teacher1.schoolName = "哈九中";
+
+        Teacher teacher2 = new Teacher();
+        //不推荐
+        System.out.println(teacher2.schoolName);
+
+        //不推荐
+        System.out.println(teacher1.schoolName);
+
+
+    }
+}

+ 22 - 0
day07/src/com/four/day07/demo1/Student.java

@@ -0,0 +1,22 @@
+package com.four.day07;
+
+public class Student {
+
+    //成员变量 : 属于类的变量
+    String idCard;
+    String name;
+    int age;
+    String marjoy;
+
+    //成员方法
+    public void study(){
+        System.out.println("学生 学习");
+    }
+
+
+    public void up(){
+        System.out.println("上专业课");
+    }
+
+
+}

+ 13 - 0
day07/src/com/four/day07/demo1/Teacher.java

@@ -0,0 +1,13 @@
+package com.four.day07;
+
+public class Teacher {
+
+
+    //静态变量
+    //public static String schoolName;
+    public  String schoolName = "哈三中";
+
+
+
+
+}

+ 2 - 0
day07/src/com/four/day07/demo2/Clazz.java

@@ -0,0 +1,2 @@
+package com.four.day07.demo2;public class Clazz {
+}

+ 2 - 0
day07/src/com/four/day07/demo2/Demo01.java

@@ -0,0 +1,2 @@
+package com.four.day07.demo2;public class Demo01 {
+}

+ 2 - 0
day07/src/com/four/day07/demo2/Student.java

@@ -0,0 +1,2 @@
+package com.four.day07.demo2;public class Student {
+}

+ 2 - 0
day07/src/com/four/day07/demo3/Demo.java

@@ -0,0 +1,2 @@
+package com.four.day07.demo3;public class Demo {
+}

+ 2 - 0
day07/src/com/four/day07/demo3/Person.java

@@ -0,0 +1,2 @@
+package com.four.day07.demo3;public class Person {
+}