guyanqing 1 year ago
parent
commit
19c32b7489
32 changed files with 446 additions and 0 deletions
  1. 25 0
      src/main/java/com/sf/day06/Test.java
  2. 37 0
      src/main/java/com/sf/day07/Animal.java
  3. 14 0
      src/main/java/com/sf/day07/AnimalTest.java
  4. 11 0
      src/main/java/com/sf/day07/BSX.java
  5. 13 0
      src/main/java/com/sf/day07/Car.java
  6. 19 0
      src/main/java/com/sf/day07/CarTest.java
  7. 12 0
      src/main/java/com/sf/day07/DP.java
  8. 14 0
      src/main/java/com/sf/day07/FDJ.java
  9. 21 0
      src/main/java/com/sf/day07/MethodTest.java
  10. 43 0
      src/main/java/com/sf/day07/Person.java
  11. 13 0
      src/main/java/com/sf/day07/PersonTest.java
  12. 26 0
      src/main/java/com/sf/day07/Phone.java
  13. 14 0
      src/main/java/com/sf/day07/PhoneTest.java
  14. 21 0
      src/main/java/com/sf/day07/Student.java
  15. 16 0
      src/main/java/com/sf/day07/StudentTest.java
  16. 147 0
      src/main/java/com/sf/day07/Test.java
  17. BIN
      target/classes/com/sf/day06/Test.class
  18. BIN
      target/classes/com/sf/day07/Animal.class
  19. BIN
      target/classes/com/sf/day07/AnimalTest.class
  20. BIN
      target/classes/com/sf/day07/BSX.class
  21. BIN
      target/classes/com/sf/day07/Car.class
  22. BIN
      target/classes/com/sf/day07/CarTest.class
  23. BIN
      target/classes/com/sf/day07/DP.class
  24. BIN
      target/classes/com/sf/day07/FDJ.class
  25. BIN
      target/classes/com/sf/day07/MethodTest.class
  26. BIN
      target/classes/com/sf/day07/Person.class
  27. BIN
      target/classes/com/sf/day07/PersonTest.class
  28. BIN
      target/classes/com/sf/day07/Phone.class
  29. BIN
      target/classes/com/sf/day07/PhoneTest.class
  30. BIN
      target/classes/com/sf/day07/Student.class
  31. BIN
      target/classes/com/sf/day07/StudentTest.class
  32. BIN
      target/classes/com/sf/day07/Test.class

+ 25 - 0
src/main/java/com/sf/day06/Test.java

@@ -1,5 +1,6 @@
 package com.sf.day06;
 
+import java.io.PipedOutputStream;
 import java.util.Scanner;
 
 public class Test {
@@ -237,4 +238,28 @@ public class Test {
         System.out.println(sum/count);
 
     }
+
+    @org.junit.Test
+    public void t10(){
+        int x = 1,y = 1;
+        if(x++==1 || ++y==1){
+            x =7;
+        }
+        System.out.println("x="+x+",y="+y);
+    }
+
+
+    @org.junit.Test
+    public void t12() {
+        char[] letter = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};
+        for (int i = 0; i < letter.length / 2; i++) {
+            letter[i] = letter[letter.length - 1 - i];
+        }
+        for (int i = 0; i < letter.length; i++) {
+            System.out.print(letter[i] + ",");
+            if ((i + 1) % 10 == 0) {
+                System.out.println();
+            }
+        }
+    }
 }

+ 37 - 0
src/main/java/com/sf/day07/Animal.java

@@ -0,0 +1,37 @@
+package com.sf.day07;
+
+/**
+ * 动物类
+ */
+public class Animal {
+
+    String name;
+
+    int age;
+
+    double weight;
+
+    double height;
+
+    /**
+     * 吃
+     */
+    public void eat(){
+        System.out.println("吃");
+    }
+
+    /**
+     * drink
+     */
+    public void drink(){
+        System.out.println("喝水");
+    }
+
+    /**
+     * run
+     */
+    public void run(){
+        System.out.println("跑步");
+    }
+
+}

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

@@ -0,0 +1,14 @@
+package com.sf.day07;
+
+public class AnimalTest {
+    public static void main(String[] args) {
+        Animal animal = new Animal();  //创建animal对象
+        animal.name = "小猫";
+        animal.age = 12;
+        animal.weight = 11.23;
+        animal.height = 120;
+
+        System.out.println(animal.name);
+        animal.eat();
+    }
+}

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

@@ -0,0 +1,11 @@
+package com.sf.day07;
+
+/**
+ * 变速箱类
+ */
+public class BSX {
+   int dwCount;
+   public String getInfo(){
+       return  "dwCount = "+dwCount;
+   }
+}

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

@@ -0,0 +1,13 @@
+package com.sf.day07;
+
+public class Car {
+    String carName;
+    FDJ fdj;
+    BSX bsx;
+    DP dp;
+    public void printInfo(){
+        System.out.println(fdj.getInfo());
+        System.out.println(bsx.getInfo());
+        System.out.println(dp.getInfo());
+    }
+}

+ 19 - 0
src/main/java/com/sf/day07/CarTest.java

@@ -0,0 +1,19 @@
+package com.sf.day07;
+
+public class CarTest {
+    public static void main(String[] args) {
+        Car car = new Car();
+        FDJ fdj = new FDJ();
+        fdj.pl = 2;
+        fdj.ml = 300;
+        car.fdj = fdj;
+        BSX bsx = new BSX();
+        bsx.dwCount = 9;
+        car.bsx = bsx;
+        DP dp = new DP();
+        dp.XGType = 1;
+        car.dp =dp;
+        car.printInfo();
+
+    }
+}

+ 12 - 0
src/main/java/com/sf/day07/DP.java

@@ -0,0 +1,12 @@
+package com.sf.day07;
+
+/**
+ * 底盘类
+ */
+public class DP {
+    int XGType;  //  1 独立悬挂  2   非独立悬挂
+    public String getInfo(){
+        return "XGType = "+XGType;
+    }
+
+}

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

@@ -0,0 +1,14 @@
+package com.sf.day07;
+
+import java.util.Deque;
+
+/**
+ * 发动机类
+ */
+public class FDJ {
+    int ml;
+    int pl;
+    public String getInfo(){
+        return "ml = "+ml+", pl = "+pl;
+    }
+}

+ 21 - 0
src/main/java/com/sf/day07/MethodTest.java

@@ -0,0 +1,21 @@
+package com.sf.day07;
+
+public class MethodTest {
+    /**
+     * 静态方法调用其他方法
+     * @param args
+     */
+    public static void main(String[] args) {
+        //先调用Test类里的实例方法
+        Test test = new Test();
+        test.method2();
+        Test.methodStatic();
+    }
+
+    @org.junit.Test
+    public void t1(){
+        Test test = new Test();
+        test.method2();
+        Test.methodStatic();
+    }
+}

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

@@ -0,0 +1,43 @@
+package com.sf.day07;
+
+public class Person {
+
+    String name;
+    int age;
+
+    Phone phone;
+
+    public void study(){
+        System.out.println("studying");
+    }
+    public void setName(String name){
+        System.out.println("setName方法");
+        this.name = name;
+    }
+
+    public String getName(){
+       return name;
+    }
+
+    public void setAge(int age){
+        this.age = age;
+        System.out.println("setAge方法");
+    }
+
+    public int getAge(){
+       return age;
+    }
+
+    public void getInfo(){
+        System.out.println("name = "+name+",age = "+age);
+    }
+
+    @Override
+    public String toString() {
+        return "Person{" +
+                "name='" + name + '\'' +
+                ", age=" + age +
+                ", phone=" + phone +
+                '}';
+    }
+}

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

@@ -0,0 +1,13 @@
+package com.sf.day07;
+
+public class PersonTest {
+    public static void main(String[] args) {
+        Person person = new Person();
+        person.name = "zs";
+        person.age = 19;
+        person.study();
+        person.setName(person.name);
+        person.setAge(person.age);
+        person.getInfo();
+    }
+}

+ 26 - 0
src/main/java/com/sf/day07/Phone.java

@@ -0,0 +1,26 @@
+package com.sf.day07;
+
+public class Phone {
+    int cpu;
+    String ram;
+    String rom;
+
+    public String getInfo(Phone phone){
+
+        return "cpu="+phone.cpu+",ram="+phone.ram+",rom="+rom;
+    }
+
+    public void printInfo(Phone p){
+        String info = getInfo(p);
+        System.out.println(info);
+    }
+
+    @Override
+    public String toString() {
+        return "Phone{" +
+                "cpu=" + cpu +
+                ", ram='" + ram + '\'' +
+                ", rom='" + rom + '\'' +
+                '}';
+    }
+}

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

@@ -0,0 +1,14 @@
+package com.sf.day07;
+
+public class PhoneTest {
+    public static void main(String[] args) {
+        Person person = new Person();
+        Phone phone = new Phone();
+        phone.cpu = 8;
+        phone.rom = "1111";
+        phone.ram = "128";
+
+        person.phone = phone;
+        phone.printInfo(phone);
+    }
+}

+ 21 - 0
src/main/java/com/sf/day07/Student.java

@@ -0,0 +1,21 @@
+package com.sf.day07;
+
+public class Student {
+    //共同属性
+    int no;
+
+    String name;
+
+    String sex;
+
+    double score;
+
+    double height;
+
+
+    //行为
+    public void study(){
+        System.out.println("学生学习");
+    }
+
+}

+ 16 - 0
src/main/java/com/sf/day07/StudentTest.java

@@ -0,0 +1,16 @@
+package com.sf.day07;
+
+public class StudentTest {
+    public static void main(String[] args) {
+        //创建学生类的对象
+        Student student = new Student();
+        student.name = "zhangsan";
+        student.height = 180.0;
+        student.sex = "nan";
+        student.no = 123;
+
+        student.study();
+        String name = student.name;
+        System.out.println(name);
+    }
+}

+ 147 - 0
src/main/java/com/sf/day07/Test.java

@@ -0,0 +1,147 @@
+package com.sf.day07;
+
+
+import com.sun.org.apache.regexp.internal.RE;
+import org.omg.CORBA.PUBLIC_MEMBER;
+
+import java.awt.image.PackedColorModel;
+import java.util.*;
+
+/**
+ * Arrays工具类的使用
+ */
+public class Test {
+
+    @org.junit.Test
+    public void t1(){
+    //toString(Object[] obj)
+        int[] arr =  new int[5];
+        for (int i = 0; i < arr.length; i++) {
+           arr[i] =  i+1;
+        }
+//        for (int i = 0; i < arr.length; i++) {
+//            System.out.println(arr[i]);
+//        }
+        System.out.println(Arrays.toString(arr));
+    }
+
+    @org.junit.Test
+    public void t2(){
+        int[] arr = {9,2,5,3,7,4};
+        //排序
+//        Arrays.sort(arr);
+////        System.out.println(Arrays.toString(arr));
+//        Arrays.sort(arr,1,5);
+////        System.out.println(Arrays.toString(arr));
+//        int i = Arrays.binarySearch(arr, 2);
+//        System.out.println(i);
+//        int[] newArr = Arrays.copyOf(arr, 7);
+//        System.out.println(Arrays.toString(newArr));
+        int[] ints = Arrays.copyOfRange(arr, 1, 5);
+//        System.out.println(Arrays.toString(ints));
+        System.out.println(Arrays.equals(arr,ints));
+        Arrays.fill(ints,1,3,99);
+        System.out.println(Arrays.toString(ints));
+    }
+
+    @org.junit.Test
+    public void t3(){
+        /**
+         * 方法的语法结构
+         * 权限修饰符 public  [其他修饰符]  返回值类型(有/无返回值void)  方法名 (参数列表) 抛出异常{
+         *     代码体
+         * }
+         *
+         * 有无返回值方法
+         * 有无参数的方法
+         * 重载方法
+         * 方法的调用
+         */
+
+    }
+
+    /**
+     * 有返回值方法
+     */
+    public String getChars(){
+        System.out.println("有返回值无入参的方法");
+        return "abcd";
+    }
+
+    /**
+     * 无返回值方法
+     */
+    public void getChars2(){
+        System.out.println("无返回值&&无入参的方法");
+    }
+
+    /**
+     * 有入参的方法无返回值
+     */
+
+    public void method1(Object...args){
+        System.out.println("有参数无返回值的方法");
+    }
+
+    public int method2(Object...args){
+        System.out.println("有参数无返回值的方法");
+        return 1;
+    }
+
+    /**
+     * 含有其他修饰符号的方法
+     */
+    public static int methodStatic(Object...args){
+        System.out.println("含有其他修饰符号的方法");
+        return 1;
+    }
+
+    /**
+     * 方法的调用
+     *      在同一个类中
+     */
+
+    public static void main(String[] args) {
+        methodStatic();
+    }
+
+    @org.junit.Test
+    public void t5(){
+        methodStatic();
+        method2();
+    }
+
+    /**
+     * 重载方法  : 方法名相同但是参数列表的方法
+     */
+
+    public void eat(){
+        System.out.println("不指定名称吃");
+    }
+
+    public void eat(String name){
+        System.out.println("指定"+name+"名称吃");
+    }
+
+
+    /**
+     * 错误案例  和上面不是重载方法
+     */
+//    private int eat(String name){
+//        System.out.println("指定"+name+"名称吃");
+//        return 1;
+//    }
+
+    @org.junit.Test
+    public void t6(){
+        System.out.println(getChar(65,90));
+        System.out.println((char)90);
+    }
+    /**
+     * 定一个方法   随机 生成A-Z
+     */
+
+    public char getChar(int start,int end){
+       return  (char)  (Math.random()*(end - start +1)+start);
+    }
+}

BIN
target/classes/com/sf/day06/Test.class


BIN
target/classes/com/sf/day07/Animal.class


BIN
target/classes/com/sf/day07/AnimalTest.class


BIN
target/classes/com/sf/day07/BSX.class


BIN
target/classes/com/sf/day07/Car.class


BIN
target/classes/com/sf/day07/CarTest.class


BIN
target/classes/com/sf/day07/DP.class


BIN
target/classes/com/sf/day07/FDJ.class


BIN
target/classes/com/sf/day07/MethodTest.class


BIN
target/classes/com/sf/day07/Person.class


BIN
target/classes/com/sf/day07/PersonTest.class


BIN
target/classes/com/sf/day07/Phone.class


BIN
target/classes/com/sf/day07/PhoneTest.class


BIN
target/classes/com/sf/day07/Student.class


BIN
target/classes/com/sf/day07/StudentTest.class


BIN
target/classes/com/sf/day07/Test.class