Advertisement
daniv1

Untitled

Apr 5th, 2018
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.74 KB | None | 0 0
  1. public class Master extends Triangle{
  2.     Master(){}
  3. public void master(Triangle t1 , Triangle t2) {
  4.         for(int i = 0 ; i < 3 ; i++) {
  5.            if(t1.xPoly[i] == t2.xPoly[i] && t1.yPoly[i] == t2.yPoly[i]) {
  6.                int n = ++i;
  7.                System.out.println("точка "+ n +  " є спільною для 2 трикутників");
  8.            }
  9.            
  10.     }
  11.  
  12.     }}
  13.  
  14.  
  15.  
  16.  
  17.  
  18.  
  19.  
  20.  
  21.  
  22.  
  23.  
  24.  
  25.  
  26.  
  27.  
  28.  
  29.  
  30.  
  31. import java.awt.*;
  32. import java.lang.*;
  33. public class Triangle {
  34.    
  35.     protected int xPoly[] = new int [3];
  36.     protected int yPoly[] = new int [3];
  37.     public int length = 3;
  38.     public Triangle() {
  39.        
  40.             xPoly[0] = 70;
  41.             yPoly[0] = 100;
  42.             xPoly[1] = 150;
  43.             yPoly[1] = 200;
  44.             xPoly[2] = 200;
  45.             yPoly[2] = 100;
  46.          }
  47.      
  48.    public Triangle(int xPoly[], int yPoly[]){
  49.        this.xPoly = xPoly;
  50.        this.yPoly = yPoly;
  51.    }
  52.    
  53.    public void getRadius() {
  54.        double   a = Math.sqrt(Math.pow(xPoly[1] - xPoly[0],2) + Math.pow(yPoly[1] - yPoly[0], 2));
  55.        
  56.            double  b = Math.sqrt(Math.pow(xPoly[2] - xPoly[1],2) + Math.pow(yPoly[2] - yPoly[1], 2));
  57.            
  58.            double c = Math.sqrt(Math.pow(xPoly[0] - xPoly[2],2) + Math.pow(yPoly[0] - yPoly[2], 2));
  59.            
  60.            double p = (a + b + c) / 2;
  61.      
  62.        double S = Math.sqrt(p* (p-a) * (p-b) * (p - c));
  63.        
  64.        double R = (a* b* c) / (4 *S);
  65.        
  66.        System.out.println(R);
  67.    }
  68.    
  69.  
  70.    public void Visible () {
  71.      Boolean per = true ;
  72.      
  73.        for(int i = 0 ; i < 3 ; i++) {
  74.            if(xPoly[i] < 0 || xPoly[i] > 250 || yPoly[i] < 0 || yPoly[i] > 250  )
  75.                per = false;
  76.        }
  77.        if(per == true)
  78.        { System.out.println("All points is inside the frame");}
  79.        else
  80.        {  System.out.println("At least one point is outside the frame");}
  81.    }  
  82.     public void drawTriangle(Graphics g) {
  83.         g.drawPolygon(new Polygon(xPoly, yPoly, xPoly.length));
  84.     }
  85.    
  86.    
  87. }
  88.  
  89.  
  90.  
  91.  
  92.  
  93.  
  94.  
  95. import java.awt.*;
  96. import java.awt.event.*;
  97.  
  98. public class DvaClass extends Frame{
  99.  
  100.  
  101.     private int Nabi[] = { 70, 100 , 140};
  102.     private int Genuk[] = { 100, 130 , 130};
  103.      Triangle ob1 = new Triangle();
  104.      Triangle ob2 = new Triangle(Nabi , Genuk);  
  105.      Master m1 = new Master();
  106.    
  107.   Stroke drawingStroke = new BasicStroke(2);
  108.   public  void paint(Graphics g) {
  109.         Graphics2D graph = (Graphics2D)g;
  110.    
  111.         ob1.drawTriangle(graph);
  112.         ob2.drawTriangle(graph);
  113.         ob1.getRadius();
  114.         ob2.getRadius();
  115.         ob1.Visible();
  116.         ob2.Visible();
  117.         m1.master(ob1, ob2);
  118.         }
  119.  
  120.  
  121.   public static void main(String args[]) {
  122.  
  123.   Frame frame = new DvaClass();
  124.  
  125.  
  126.   frame.addWindowListener(
  127.           new WindowAdapter(){
  128.               public void windowClosing(WindowEvent we){
  129.               System.exit(0);
  130.              }
  131.             }
  132.           );
  133.   frame.setSize(250, 250);
  134.   frame.setVisible(true);
  135.  }}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement