⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ex2.java

📁 讲述各种各样的java初始编程 了解编程
💻 JAVA
字号:
/* * To change this template, choose Tools | Templates * and open the template in the editor. */package chenchao;import java.util.Random;/** * * @author qjxy */public class Ex2 {    public static void main(String[] args) {        Ex2 test = new Ex2();        test.doTest();    }    private void doTest() {        Random r = new Random();        Point a = new Point(r.nextInt(10), r.nextInt(20));        Point b = new Point(r.nextInt(10), r.nextInt(20));        Point c = new Point(r.nextInt(10), r.nextInt(20));        TriAngle t = new TriAngle(a, b, c);        System.out.println(t);    }}class TriAngle{    private Point a;    private Point b;    private Point c;    private double area;    private double longth;    private double ab;    private double bc;    private double ac;    private double angle;    public Point getA() {        return a;    }    public void setA(Point a) {                this.a = a;    }    public double getArea() {        area = (ac * bc * angle) /2;        return area;    }    public Point getB() {        return b;    }    public void setB(Point b) {        this.b = b;    }    public Point getC() {        return c;    }    public void setC(Point c) {        this.c = c;    }    public double getLongth() {        longth = ab + ac + bc;        return longth;    }    public TriAngle(Point a, Point b, Point c) {        this.a = a;        this.b = b;        this.c = c;                this.ab = this.getAb();        this.ac = this.getAc();        this.bc = this.getBc();        this.angle = this.getAngle();                this.area = this.getArea();        this.longth = this.getLongth();    }        private double getDistance(Point s, Point d){        double distance = 0;        distance = Math.sqrt(Math.pow(s.getX() - d.getX(), 2) + Math.pow(s.getY() - d.getY(), 2));        return distance;    }    public double getAb() {        ab = getDistance(a, b);        return ab;    }    public double getAc() {        ac = getDistance(a, c);        return ac;    }    public double getBc() {        bc = getDistance(b, c);        return bc;    }    public double getAngle() {        double cos = (ac * ac + bc * bc - ab * ab ) / (2 * bc * ac);         double sin = Math.sqrt(1- cos * cos);        angle = sin;        return angle;    }    @Override    public String toString() {        String stra = a.toString();        String strb = b.toString();        String strc = c.toString();                String str = stra + '\n' + strb + '\n' + strc + '\n';        str = str + "The Area is :\t " + this.getArea()+ '\n';        str = str + "The Longth is :\t " + this.getLongth() + '\n';        return str;    }        }class Point{    private int x;    private int y;    public int getX() {        return x;    }    public void setX(int x) {        this.x = x;    }    public int getY() {        return y;    }    public void setY(int y) {        this.y = y;    }    public Point(int x, int y) {        this.x = x;        this.y = y;    }    @Override    public String toString() {        String str = "[the x is :\t" + this.x + '\t' + "the y is :\t" + this.y + ']';        return str;    }        }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -