Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <----MAIN PROGRAMM---->
- package vrnkv6;
- import java.util.ArrayList;
- import java.util.Random;
- import java.util.Scanner;
- public class VRNKV6 {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int N = scanner.nextInt();
- ArrayList<Triangle> list = new ArrayList<>();
- Random rand = new Random();
- for(int i=0;i<N;i++){
- Triangle trngl = new Triangle(
- rand.nextInt(10),
- rand.nextInt(10),
- rand.nextInt(10),
- rand.nextInt(10),
- rand.nextInt(10),
- rand.nextInt(10));
- list.add(trngl);
- }
- for(Triangle item:list){
- System.out.println("--------------------------\n");
- System.out.println("Сторона AB = " + item.getSideAB() + " ; " +
- "Cторона BC = " + item.getSideBC() + " ; " +
- "Cторона AC = " + item.getSideAC()
- );
- if (item.getTrnglVerif()== true){
- System.out.println("Это треугольник!");
- System.out.println(item.getAngles());
- System.out.println("Периметр = " + item.getPerimeter());
- System.out.println("Площадь = " + item.getArea());
- }
- else{
- System.out.println("Это не треугольник!");
- }
- }
- }
- }
- <----CLASS TRIANGLE---->
- package vrnkv6;
- public class Triangle {
- private Point A;
- private Point B;
- private Point C;
- public Triangle(Point A, Point B, Point C ) {
- this.A = A;
- this.B = B;
- this.C = C;
- }
- public Triangle(double x1, double y1, double x2,double y2,double x3,double y3)
- {
- this.A = new Point(x1,y1);
- this.B = new Point(x2,y2);
- this.C = new Point(x3,y3);
- }
- public double getSideAB()
- {
- double AB = Math.sqrt(Math.pow((B.getX()- A.getX()),2.0) +
- Math.pow((B.getY()-A.getY()),2.0));
- return AB;
- }
- public double getSideBC()
- {
- double BC = Math.sqrt(Math.pow((C.getX()- B.getX()),2.0) +
- Math.pow((C.getY()-B.getY()),2.0));
- return BC;
- }
- public double getSideAC(){
- double AC = Math.sqrt(Math.pow((C.getX()- A.getX()),2.0) +
- Math.pow((C.getY()-A.getY()),2.0));
- return AC;
- }
- public boolean getTrnglVerif(){
- if(getSideAB() + getSideBC() > getSideAC() && getSideAB() + getSideAC()>
- getSideBC() && getSideBC() + getSideAC() > getSideAB()){
- return true;
- }
- else
- return false;
- }
- public String getAngles(){
- double angA = Math.acos((Math.pow(getSideAB(),2.0) + Math.pow(getSideAC(),2.0) -
- Math.pow(getSideBC(),2.0)) / (2.0 * getSideAB() * getSideAC()));
- double angB = Math.acos((Math.pow(getSideAB(),2.0) + Math.pow(getSideAC(),2.0) -
- Math.pow(getSideBC(),2.0)) / (2.0 * getSideAB() * getSideAC()));
- double angC = Math.acos((Math.pow(getSideAB(),2.0) + Math.pow(getSideAC(),2.0) -
- Math.pow(getSideBC(),2.0)) / (2.0 * getSideAB() * getSideAC()));
- return "Угол А =" + angA + "; Угол B =" + angB + "; Угол C =" + angC + " ";
- }
- public double getPerimeter(){
- double P = getSideAB() + getSideBC() + getSideAC();
- return P;
- }
- public double getArea(){
- double p=getPerimeter()/2;//полупериметр
- double S = Math.sqrt(p *(p - getSideAB()) * (p - getSideBC()) *
- (p - getSideAC()) ); //Формула Герона
- return S;
- }
- /*@Override
- public String toString(){
- return "Point A("+A.getX()+" ; "+ A.getY()+")\nPoint B("+B.getX()+" ; "+ B.getY()+")\nPoint C("+C.getX()+" ; "+ C.getY()+")";
- }*/
- }
- <----CLASS POINT---->
- package vrnkv6;
- public class Point {
- private double x;
- private double y;
- public Point(double x, double y) {
- this.x = x;
- this.y = y;
- }
- public Point() {
- this.x = 0;
- this.y = 0;
- }
- public double getX() {
- return x;
- }
- public double getY() {
- return y;
- }
- public void setX(double x) {
- this.x = x;
- }
- public void setY(double y) {
- this.y = y;
- }
- }
Add Comment
Please, Sign In to add comment