guyanqing 1 éve
szülő
commit
ce2187d0a2

+ 6 - 0
pom.xml

@@ -13,6 +13,12 @@
             <artifactId>gson</artifactId>
             <version>2.9.1</version>
         </dependency>
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <version>4.13.2</version>
+            <scope>compile</scope>
+        </dependency>
     </dependencies>
 
     <properties>

+ 11 - 0
src/main/java/com/sf/day10/homework/CompareBig.java

@@ -1,5 +1,16 @@
 package com.sf.day10.homework;
 
+import com.sf.day10.homework.homework1.Apple;
+
 public class CompareBig implements CompareAble{
 
+    @Override
+    public void compare(Apple a1, Apple a2) {
+        System.out.println("默认挑大的:");
+        if(a1.getSize() > a2.getSize()){
+            System.out.println(a1.getSize()+"=="+a1.getColor());
+        }else{
+            System.out.println(a2.getSize()+"=="+a2.getColor());
+        }
+    }
 }

+ 7 - 0
src/main/java/com/sf/day11/Father.java

@@ -0,0 +1,7 @@
+package com.sf.day11;
+
+public class Father   {
+    public  void  eat() throws RuntimeException{
+        System.out.println("chi");
+    }
+}

+ 39 - 0
src/main/java/com/sf/day11/MyException.java

@@ -0,0 +1,39 @@
+package com.sf.day11;
+
+public class MyException extends Exception{
+    public static final long serialVersionUID = 123456L;
+    private String message;
+
+    private Integer id;
+
+    public MyException() {
+    }
+
+    public MyException(String message) {
+        this.message = message;
+    }
+
+    public String getMessage() {
+        return message;
+    }
+
+    public void setMessage(String message) {
+        this.message = message;
+    }
+
+    public Integer getId() {
+        return id;
+    }
+
+    public void setId(Integer id) {
+        this.id = id;
+    }
+
+    @Override
+    public String toString() {
+        return "MyException{" +
+                "message='" + message + '\'' +
+                ", id=" + id +
+                '}';
+    }
+}

+ 15 - 0
src/main/java/com/sf/day11/MyExpTest.java

@@ -0,0 +1,15 @@
+package com.sf.day11;
+
+public class MyExpTest {
+    public static void regist(int num) throws MyException{
+        if(num < 0){
+            throw  new MyException("人数为负");
+        }else {
+            throw new MyException("登记人数"+num);
+        }
+    }
+
+    public static void main(String[] args) throws MyException {
+        regist(12);
+    }
+}

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

@@ -0,0 +1,8 @@
+package com.sf.day11;
+
+public class Son extends Father{
+    @Override
+    public void eat() throws RuntimeException{
+//        super.eat();
+    }
+}

+ 127 - 0
src/main/java/com/sf/day11/Test01.java

@@ -0,0 +1,127 @@
+package com.sf.day11;
+
+import org.junit.Test;
+
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.security.PublicKey;
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.SQLException;
+import java.util.Scanner;
+
+public class Test01 {
+
+    /**
+     * 错误  Error
+     */
+    @Test
+    public void test1(){
+        recursion();
+    }
+    public void recursion(){
+        recursion();
+    }
+
+    @Test
+    public void test2(){
+        int[] arr = new int[Integer.MAX_VALUE];
+    }
+
+    @Test
+    public void test3(){
+        // OutOfMemoryError
+        StringBuilder stringBuilder = new StringBuilder();
+        while (true){
+            stringBuilder.append("sf");
+        }
+    }
+
+
+    /**
+     * 运行时异常   RunTimeException
+     */
+    @Test
+    public void t1(){
+        int[][] arr = new int[3][];
+        System.out.println(arr[0].length);
+    }
+
+    @Test
+    public void t2(){
+        Object obj = 3;
+        String str = (String) obj;
+    }
+
+    @Test
+    public void t3(){
+        int[] arr = new int[5];
+        for (int i= 0;i <=5 ;i++){
+            System.out.println(arr[i]);
+        }
+    }
+
+    @Test
+    public void t4(){
+        //InputMismatchException
+        Scanner input = new Scanner(System.in);
+        System.out.print("请输入一个整数:");//输入非整数
+        int num = input.nextInt();
+        input.close();
+    }
+
+    @Test
+    public void t5(){
+        int a = 1;
+        int b = 0;
+        //ArithmeticException
+        System.out.println(a/ b);
+    }
+
+
+    /**
+     * 编译时异常(受检查异常)
+     * 声明异常     在方法后+ throws  异常类名 , 异常类型2.。。。。
+     */
+
+    @Test
+    public void t6() throws InterruptedException {  //声明
+        Thread.sleep(1000);   //多线程这块    //休眠1000毫秒
+    }
+
+    @Test
+    public void t7() throws ClassNotFoundException {
+        Class<?> aClass = Class.forName("java.lang.String");
+    }
+
+    @Test
+    public void t8() throws SQLException {
+        Connection connection = DriverManager.getConnection(".....");
+    }
+
+    @Test
+    public void t9() throws FileNotFoundException {
+        FileInputStream fileInputStream = new FileInputStream("java.txt");
+    }
+
+
+    @Test
+    public void t10() throws RuntimeException{
+        int a = 0; int b = 1;
+        if(a  == b){
+            throw new RuntimeException("a和b不能相等");
+        }
+        System.out.println("==============");
+    }
+
+
+
+
+
+
+
+
+
+
+}

+ 49 - 0
src/main/java/com/sf/day11/Test02.java

@@ -0,0 +1,49 @@
+package com.sf.day11;
+
+import java.io.FileNotFoundException;
+
+public class Test02 {
+    public static void main(String[] args){
+//        String[] person = {"lisa","rose","jenny"};
+//        try {
+//            for (int i= 0;i<person.length;i++){
+//                System.out.println(person[i]);
+//            }
+//            return;
+////            System.exit(0);
+//        }catch (Exception e){
+//            System.out.println("走catch");
+//            e.printStackTrace();
+//        }finally {
+//            System.out.println("程序执行结束。。。");
+//        }
+
+//        int test = test("123");
+//        System.out.println(test);
+
+        int test = test();
+        System.out.println(test);
+    }
+
+    public static int test(){
+        int i = 200;
+        try {
+            return i;
+        }finally {
+           return ++i;
+        }
+    }
+
+//    public static int test(String str){
+//        try {
+//            Integer.valueOf(str);
+//            return 1;
+//        }catch (NumberFormatException e){
+//            e.printStackTrace();
+//            return -1;
+//        }finally {
+//            System.out.println("test结束");
+//            return 0;
+//        }
+//    }
+}

BIN
target/classes/com/sf/day10/homework/CompareBig.class


BIN
target/classes/com/sf/day11/Father.class


BIN
target/classes/com/sf/day11/MyException.class


BIN
target/classes/com/sf/day11/MyExpTest.class


BIN
target/classes/com/sf/day11/Son.class


BIN
target/classes/com/sf/day11/Test01.class


BIN
target/classes/com/sf/day11/Test02.class