面向对象例题

      

package com.hanqi.test;

import com.hanqi.model.Circle;
import com.hanqi.model.Point;

public class Test2 {
    public static void main(String[] args) {
        Point p = new Point(3.5, 8);
        Point p2 = new Point(2.5, 6.7);
        Point p3 = new Point(0, 0);
        Point p4 = new Point(3, 4);
        System.out.println("这个点到原点的距离是:" + p4.instance());
    
        // System.out.println(Math.PI);
        
        Circle c = new Circle(p3,4);
        boolean b = c.isIn(p4);
        if (b) {
            System.out.println("这个点在圆中");
        } else {
            System.out.println("这个点不在圆中");
        }
    }
}

//关于求这个点在不在圆内
package com.hanqi.test;

import com.hanqi.model.Animals;
import com.hanqi.model.Cat;
import com.hanqi.model.Dog;

public class Test4 {

    public static void main(String[] args) {
        Dog d1 = new Dog();
        d1.setName("金毛");
        Dog d2 = new Dog();
        d2.setName("哈士奇");
        Dog d3 = new Dog();
        d3.setName("萨摩");
        Dog d4 = new Dog();
        d4.setName("高加索");
        
        Cat c1 = new Cat();
        c1.setName("暹罗");
        Cat c2 = new Cat();
        c2.setName("折耳猫");
        Cat c3 = new Cat();
        c3.setName("短毛猫");
        
        Animals.show();
        
        d3.display();
        c1.display();
    }

}

//领养宠物的品种

package com.hanqi.test;

import java.util.Random;
import java.util.Scanner;

import com.hanqi.model.DigRiddle;

public class Test5 {

    public static void main(String[] args) {
/*        for (int i = 0; i < 10; i++) {
            double d = Math.random(); // 0 - 1   不包括1
            System.out.println(d);
        }*/
        
/*        for (int i = 0; i < 10; i++) {
            Random r = new Random();
            System.out.println(r.nextInt(6) + 5);
        }*/
        boolean flag = true;
        Scanner scanner = new Scanner(System.in);
        DigRiddle d = new DigRiddle();
        System.out.println("请输入一个数字: ");
        
        while(flag) {
            int i = scanner.nextInt();
            boolean result = d.guess(i);
            if (result) {
                flag = false;
            }
        }
        
        scanner.close();
    }

}


//领养宠物界面

 

posted @ 2018-05-08 15:43  峰栯  阅读(123)  评论(0编辑  收藏  举报