idzik

Matura2017

Mar 7th, 2017
450
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.20 KB | None | 0 0
  1. /**
  2.  * Created by operator on 07.03.2017.
  3.  */
  4. public class Punkty {
  5.     double x;
  6.     double y;
  7.  
  8.     public Punkty(double x, double y) {
  9.         this.x = x;
  10.         this.y = y;
  11.     }
  12.  
  13.     public double getX() {
  14.         return x;
  15.     }
  16.  
  17.     public void setX(double x) {
  18.         this.x = x;
  19.     }
  20.  
  21.     public double getY() {
  22.         return y;
  23.     }
  24.  
  25.     public void setY(double y) {
  26.         this.y = y;
  27.     }
  28. }
  29.  
  30.  
  31.  
  32. ///////////////////////////////////////////////////////////////
  33.  
  34. /**
  35.  * Created by operator on 07.03.2017.
  36.  */
  37. public class Okrag implements Comparable<Okrag>{
  38.     double x;
  39.     double y;
  40.     double z;
  41.  
  42.     public Okrag(double x, double y, double z) {
  43.         this.x = x;
  44.         this.y = y;
  45.         this.z = z;
  46.     }
  47.  
  48.     public double getX() {
  49.         return x;
  50.     }
  51.  
  52.     public void setX(double x) {
  53.         this.x = x;
  54.     }
  55.  
  56.     public double getY() {
  57.         return y;
  58.     }
  59.  
  60.     public void setY(double y) {
  61.         this.y = y;
  62.     }
  63.  
  64.     public double getZ() {
  65.         return z;
  66.     }
  67.  
  68.     public void setZ(double z) {
  69.         this.z = z;
  70.     }
  71.  
  72.  
  73.     @Override
  74.     public int compareTo(Okrag o) {
  75.         if (this.getX()<o.getX()) return -1;
  76.         else if (this.getX()>o.getX()) return 1;
  77.         else  if (this.getY()<o.getY()) return -1;
  78.             else if (this.getY()>o.getY()) return 1;
  79.             else return 0;
  80.  
  81.     }
  82.  
  83.     @Override
  84.     public String toString() {
  85.         return x + " " + y + " " + z;
  86.     }
  87. }
  88.  
  89.  
  90. ////////////////////////////////////////////////////////////////////////////////////
  91.  
  92. import java.io.File;
  93. import java.io.FileNotFoundException;
  94. import java.io.PrintWriter;
  95. import java.util.ArrayList;
  96. import java.util.Collections;
  97. import java.util.Scanner;
  98.  
  99. /**
  100.  * Created by operator on 07.03.2017.
  101.  */
  102.  
  103. public class Matura2017 {
  104.     public static double distanceSqrt(double ax,double ay,double bx,double by){
  105.         return Math.sqrt((ax-bx)*(ax-bx)+(ay-by)*(ay-by));
  106.     }
  107.  
  108.     public static double distanceNoSqrt(double ax,double ay,double bx,double by){
  109.         return (ax-bx)*(ax-bx)+(ay-by)*(ay-by);
  110.     }
  111.  
  112.     public static double obliczPole(double ax,double ay,double bx,double by,double cx,double cy){
  113.         double s_ab=distanceSqrt(ax,ay,bx,by);
  114.         double s_ac=distanceSqrt(ax,ay,cx,cy);
  115.         double s_bc=distanceSqrt(bx,by,cx,cy);
  116.         double p=(s_ab+s_bc+s_ac)/2;
  117.         //System.out.println("P ="+p);
  118.         //System.out.println("Pole ="+pole);
  119.         //System.out.println("M ="+Math.sqrt(p*(p-s_ab)*(p-s_ac)*(p-s_bc)));
  120.         return Math.sqrt(p*(p-s_ab)*(p-s_ac)*(p-s_bc));
  121.     }
  122.  
  123.     public static void main(String[] args) throws FileNotFoundException {
  124.         File file1=new File("punkty.txt");
  125.         File file2=new File("okregi.txt");
  126.         PrintWriter wyniki1=new PrintWriter("wyniki1.txt");
  127.         PrintWriter wyniki2=new PrintWriter("wyniki2.txt");
  128.         PrintWriter wyniki3=new PrintWriter("wyniki3.txt");
  129.         Scanner scanner=new Scanner(file1);
  130.         int liczba=0;
  131.         int [] cwiartki={0,0,0,0,0};
  132.         String wiersz;
  133.         String [] punkty;
  134.         ArrayList<Punkty> lista=new ArrayList<Punkty>();
  135.         while (scanner.hasNextLine()){
  136.             wiersz=scanner.nextLine();
  137.             punkty=wiersz.split(" ");
  138.             lista.add(new Punkty(Double.parseDouble(punkty[0]),Double.parseDouble(punkty[1])));
  139.             if (Double.parseDouble(punkty[0])>0 && Double.parseDouble(punkty[1])>0)
  140.                 cwiartki[1]++;
  141.             else if (Double.parseDouble(punkty[0])<0 && Double.parseDouble(punkty[1])>0)
  142.                 cwiartki[2]++;
  143.             else if (Double.parseDouble(punkty[0])<0 && Double.parseDouble(punkty[1])<0)
  144.                 cwiartki[3]++;
  145.             else cwiartki[4]++;
  146.         }
  147.         wyniki1.println(cwiartki[1]+" "+cwiartki[2]+" "+cwiartki[3]+" "+cwiartki[4]);
  148.         wyniki1.close();
  149.         //######
  150.         ArrayList<Okrag> tablica=new ArrayList<Okrag>();
  151.         scanner=new Scanner(file2);
  152.         String [] okregi;
  153.         while (scanner.hasNextLine()){
  154.             wiersz=scanner.nextLine();
  155.             okregi=wiersz.split(" ");
  156.             tablica.add(new Okrag(Double.parseDouble(okregi[0]),Double.parseDouble(okregi[1]),Double.parseDouble(okregi[2])));
  157.         }
  158.         //System.out.print(tablica);
  159.         Collections.sort(tablica);
  160.         int licznik=0;
  161.         for (Okrag i:tablica
  162.              ) {
  163.             if ((distanceSqrt(i.getX(), i.getY(), i.getX(),0) == i.getZ())) {
  164.                 wyniki2.println(i);
  165.                 licznik++;
  166.                 }
  167.             }
  168.         wyniki2.println(licznik);
  169.         wyniki2.close();
  170.         //##################
  171.         double pole=0;
  172.         double p;
  173.        // System.out.println(distanceSqrt(51,284,0,5184));
  174.         for (int i=0;i<lista.size()-1;i=i+1){
  175.             pole=pole+obliczPole(lista.get(i).getX(),lista.get(i).getY(),lista.get(i+1).getX(),lista.get(i+1).getY(),0,0);
  176.         }
  177. pole=pole+obliczPole(lista.get(lista.size()-1).getX(),lista.get(lista.size()-1).getY(),lista.get(0).getX(),lista.get(0).getY(),0,0);
  178.          wyniki3.println((int)pole);
  179.          wyniki3.close();
  180.         System.out.println("POLE "+(int)pole);
  181.       }
  182. }
Advertisement
Add Comment
Please, Sign In to add comment