package apple;
import java.util.Scanner;
public class Dog {
public static void main(String[] args) {
// TODO Auto-generated method stub
public static double m,n;
// 输入四组坐标值
public void getNum();
public void count();
public void isSquare();
}
// 三个成员方法
// 成员方法一,输入坐标值,并进行基本判断
public void getNum() {
int x1, x2, x3, x4;
int y1, y2, y3, y4;
Scanner in = new Scanner(System.in);
System.out.println("请输入左上角坐标值:");
x1 = in.nextInt();
y1 = in.nextInt();
System.out.println("请输入左下角坐标值:");
x2 = in.nextInt();
y2 = in.nextInt();
System.out.println("请输入右下坐标值:");
x3 = in.nextInt();
y3 = in.nextInt();
System.out.println("请输入右上角坐标值:");
x4 = in.nextInt();
y4 = in.nextInt();
in.close();
// 判断是否在第一象限
if (x1 > 0 & x2 > 0 & x3 > 0 & x4 > 0 & y1 > 0 & y2 > 0 & y3 > 0 & y4 > 0) {
System.out.println("所有输入的坐标均在第一象限区域内!");
} else {
System.out.println("检查到有输入的坐标不属于第一象限!");
}
// 判断x或y值是否不大于20.0
if (x1 > 20 | x2 > 20 | x3 > 20 | x4 > 20 | y1 > 20 | y2 > 20 | y3 > 20 | y4 > 20) {
System.out.println("检查到有大于20的x或y值!");
} else {
System.out.println("输入坐标值当中所有的x和y值均不大于20!");
}
// 检测是否构成一个矩形
double p, q;
m = Math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
n = Math.sqrt((x2 - x3) * (x2 - x3) + (y2 - y3) * (y2 - y3));
p = Math.sqrt((x3 - x4) * (x3 - x4) + (y3 - y4) * (y3 - y4));
q = Math.sqrt((x4 - x1) * (x4 - x1) + (y4 - y1) * (y4 - y1));
double diagonalSquare; // 定义矩形对角线变量的平方
diagonalSquare = (x1 - x3) * (x1 - x3) + (y1 - y3) * (y1 - y3);
if (m == p & n == q & diagonalSquare == m * m + n * n) {
System.out.println("构成矩形!");
} else {
System.out.println("不构成矩形");
}
}
// 成员方法二,计算矩形的长宽面积和周长
public void count() {
double length, wide, area, circumference;
if (m >= n) {
length = m;
wide = n;
} else {
length = n;
wide = m;
}
area = length * wide;
circumference = (length + wide) * 2;
System.out.println("此矩形的长为 " + length + "宽为 " + wide + "面积为 " + area + "周长为 " + circumference);
}
// 成员方法三, 检测此矩形是否为一个特殊的正方形
public void isSquare() {
if (length == wide) {
System.out.println("此矩形是一个正方形");
} else {
System.out.println("此矩形不是一个正方形");
}
}
}