guyanqing 11 hónapja
szülő
commit
43ec04b24e

+ 36 - 0
src/main/java/com/sf/Test1.java

@@ -0,0 +1,36 @@
+package com.sf;
+
+public class Test1 {
+    //程序启动的入口
+    /**
+     * int  main(){
+     *     return 0;
+     * }
+     */
+
+    public static void main(String[] args){
+
+        /**
+         *
+         * 1 字节   =  8位
+         * 基本数据类型  整型  byte  short int   long     int
+         *                   1      2      4    8
+         *                   i++  ++i
+         *              &  &&    和   | ||
+         *              a = true  b = false
+         *              a& b = F
+         *              a| b  = T
+         *               a && b = F   b && a = T/F
+         *
+         *               a || b = T/F
+         */
+
+    int  x = 1;
+    int  y = 1;
+    if(x++==2 || ++y==2){
+        x = 7;
+    }
+        System.out.println(x);
+        System.out.println(y);
+    }
+}

+ 0 - 46
src/main/java/com/sf/Test2.java

@@ -1,46 +0,0 @@
-package com.sf;
-
-public class Test2 {
-    //程序启动的入口   main
-    public static void main(String[] args){
-        /**
-         *   数据类型  整型  byte short int long
-         *   `               1    2     4   8
-         *                   -128 ~ 127
-         *                   计算机最小的计算单元  bit   1字节 = 8bit
-         *  产品类型   5;
-         *  byte  a = 5;
-         *  int b = 5;
-         *
-         *  i++   ++i   区别
-         *  先赋值后运算  先运算后赋值
-         *  i++ 和 ++i 区别
-         *  无接受值: i++ 和 ++i  效果等同  都是进行自增一的操作
-         *  有接收值: i++ 满足 先赋值后运算    ++i 满足 先运算后赋值
-         *
-         *
-         *  &       && 区别   |  ||
-         *  逻辑与  短路与
-         *  true  &  false   -->  false
-         *  true  &&  false   -->  false
-         *
-         *  T  &  T/F  -->T/F  都走
-         *  T  &&  T/F  --> T/F
-         *  F  &&  T/F  --> F
-         */
-
-
-//        int a = 10;
-////       int c = a++;
-//          int c =  ++a;
-//        System.out.println(a);  //11
-//        System.out.println(c);
-        int x = 1;
-        int y = 1;
-        if (x++ == 2 && ++y == 2){
-            x = 7;
-        }
-        System.out.println(x);
-        System.out.println(y);
-    }
-}

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

@@ -0,0 +1,24 @@
+package com.sf.day08;
+
+public class Car {
+
+    public double weight;
+    public double horsepower;
+
+    @Override
+    public String toString() {
+        return "Car{" +
+                "weight=" + weight +
+                ", horsepower=" + horsepower +
+                '}';
+    }
+
+    public double proportion(){
+        return horsepower*10/weight;
+    }
+
+    public String getInfo(){
+        double proportion = proportion();
+        return "weight = "+weight+",horsepower = "+horsepower+ "proportion = "+proportion;
+    }
+}

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

@@ -0,0 +1,31 @@
+package com.sf.day08;
+
+import java.util.Arrays;
+
+public class CarTest {
+    public static void main(String[] args) {
+        Car[] cars = new Car[3];
+        Car car = new Car();
+        car.weight = 1500;
+        car.horsepower = 180;
+        cars[0] =car;
+
+        Car car1 = new Car();
+        car1.weight = 1300;
+        car1.horsepower = 125;
+        cars[1] =car1;
+
+        Car car2 = new Car();
+        car2.weight = 2000;
+        car2.horsepower = 230;
+        cars[2] =car2;
+
+        System.out.println(Arrays.toString(cars));
+
+        for (Car car3 : cars) {
+            System.out.println(car3.getInfo());
+        }
+    }
+
+
+}

+ 32 - 0
src/main/java/com/sf/day08/Game.java

@@ -0,0 +1,32 @@
+package com.sf.day08;
+
+public class Game {
+
+    private int score;
+
+    public Game() {
+    }
+
+    public Game(int score) {
+        if(score >10){
+            System.out.println("error");
+            return;
+        }
+        this.score = score;
+    }
+
+    public int getScore() {
+        return score;
+    }
+
+    public void setScore(int score) {
+        this.score = score;
+    }
+
+    @Override
+    public String toString() {
+        return "Game{" +
+                "score=" + score +
+                '}';
+    }
+}

+ 11 - 0
src/main/java/com/sf/day08/GameTest.java

@@ -0,0 +1,11 @@
+package com.sf.day08;
+
+public class GameTest {
+    public static void main(String[] args) {
+        Game game = new Game();
+        game.setScore(112);
+        //不能大于10
+        int score = game.getScore();
+        System.out.println(score);
+    }
+}

+ 49 - 0
src/main/java/com/sf/day08/Person.java

@@ -0,0 +1,49 @@
+package com.sf.day08;
+
+public class Person {
+    public String name;
+
+    public int age;
+
+    /**
+     * 构造器的作用 :  对象的创建  属性的赋值
+     *创建无参构造器  有参构造器
+     */
+
+    public  double weight;
+
+    public Person(){
+
+    }
+
+    public Person(int age ){
+        this.age = age;
+    }
+
+    public Person(String name,int age ){
+        this.name = name;
+        this.age = age;
+    }
+
+    public Person(String name,int age,double weight ){
+        this(name,age);
+        this.weight = weight;
+        }
+
+    @Override
+    public String toString() {
+        return "Person{" +
+                "name='" + name + '\'' +
+                ", age=" + age +
+                ", weight=" + weight +
+                '}';
+    }
+
+    public static void main(String[] args) {
+//       Person person = new Person(13);
+        Person person1 = new Person("zs", 13, 123.0);
+        System.out.println(person1);
+    }
+
+
+}

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

@@ -0,0 +1,18 @@
+package com.sf.day08;
+
+public class Student {
+    public int number;  //学号
+    public int state;   //年级
+    public int score;   //成绩
+
+
+    // alt  +  insert  +  回车
+    @Override
+    public String toString() {
+        return "Student{" +
+                "number=" + number +
+                ", state=" + state +
+                ", score=" + score +
+                '}';
+    }
+}

+ 41 - 0
src/main/java/com/sf/day08/Test.java

@@ -0,0 +1,41 @@
+package com.sf.day08;
+
+
+import java.util.Arrays;
+
+public class Test {
+
+    @org.junit.Test
+    public void t1(){
+        Student[] students = new Student[5];
+        for (int i = 1;i<=5;i++){
+            Student student = new Student();
+            student.number = i;
+            student.state = (int) ((Math.random()*5)+1);
+            student.score = (int) ((Math.random()*100)+1);
+            students[i-1] =  student;
+        }
+        //遍历所有学生信息
+        System.out.println(Arrays.toString(students));
+
+        //打印出年级为三的学生信息
+        for (Student student : students) {
+            if(student.state == 3){
+                System.out.println(student);
+            }
+        }
+
+        //使用冒泡排序  (分数)
+        for(int i = 1;i<students.length;i++){
+            for (int j  = 0;j<students.length-i;j++){
+                if(students[j].score > students[j+1].score){
+                   int temp = students[j].score;
+                    students[j].score = students[j+1].score;
+                    students[j+1].score = temp;
+                }
+            }
+        }
+
+        System.out.println(Arrays.toString(students));
+    }
+}

+ 4 - 0
src/main/java/com/sf/day08/User.java

@@ -0,0 +1,4 @@
+package com.sf.day08;
+
+public class User {
+}

BIN
target/classes/com/sf/Test1.class


BIN
target/classes/com/sf/Test2.class


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


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


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


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


BIN
target/classes/com/sf/day08/Game.class


BIN
target/classes/com/sf/day08/GameTest.class


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


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


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


BIN
target/classes/com/sf/day08/User.class