Advertisement
Guest User

teszt

a guest
Oct 4th, 2015
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.49 KB | None | 0 0
  1.  
  2. import java.text.DecimalFormat;
  3. import java.util.Arrays;
  4. import java.util.Comparator;
  5. import java.util.Scanner;
  6.  
  7. /*
  8.  * To change this license header, choose License Headers in Project Properties.
  9.  * To change this template file, choose Tools | Templates
  10.  * and open the template in the editor.
  11.  */
  12.  
  13. /**
  14.  *
  15.  * @author hallgato
  16.  */
  17. public class teszt {
  18.  
  19.     public static void main(String[] args) {
  20.         /*  Haromszog h1; //Haromszog típusú változó h1 névvel -- referencia/hivatkozás változó
  21.          h1 = new Haromszog(); // először a jobboldali kifejezés hajtódik végre( vmi = EZ ); ()-- konstruktor hívás; a "new" operátor a példányosítás operátora
  22.    
  23.          System.out.println(h1.a); //h1 változó által megnevezett "a" mezőre
  24.          System.out.println(h1.b);
  25.          System.out.println(h1.c);
  26.    
  27.          h1.a = 2.0;
  28.          h1.b = 3.0;
  29.          h1.c = 4.0;
  30.        
  31.          System.out.println(h1.a); //h1 változó által megnevezett "a" mezőre
  32.          System.out.println(h1.b);
  33.          System.out.println(h1.c);
  34.        
  35.          Haromszog h2 = new Haromszog(); //kezdőérték adás egyből
  36.          h2.a = 11.0;
  37.          h2.b = 12.0;
  38.          h2.c = 44.0;
  39.        
  40.          System.out.println(h2.a);
  41.          System.out.println(h2.b);
  42.          System.out.println(h2.c);    */
  43.  
  44.         /*    
  45.          Haromszog h1; //Haromszog típusú változó h1 névvel -- referencia/hivatkozás változó
  46.          h1 = new Haromszog(2.0, 3.0, 4.0); // először a jobboldali kifejezés hajtódik végre( vmi = EZ ); ()-- konstruktor hívás; a "new" operátor a példányosítás operátora
  47.          System.out.println(h1.a); //h1 változó által megnevezett "a" mezőre
  48.          System.out.println(h1.b);
  49.          System.out.println(h1.c);
  50.    
  51.          Haromszog h2 = new Haromszog(11.0, 12.0, 44.0);
  52.          System.out.println(h2.a);
  53.          System.out.println(h2.b);
  54.          System.out.println(h2.c);
  55.          átírjuk privátra */
  56.  
  57.     /* float f = 12.5F;
  58. int i = (int)f;
  59. System.out.println("f is " + f);
  60. System.out.println("i is " + i);
  61.  
  62.  char x = 'a';
  63.         char y = 'c';
  64.  
  65.         System.out.println(++x);
  66.         System.out.println(y++);
  67.         System.out.println(x - y);
  68.        
  69.         System.out.println("\n1" + 1);
  70. System.out.println('1' + 1);
  71. System.out.println("1" + 1 + 1);
  72. System.out.println("1" + (1 + 1));
  73. System.out.println('1' + 1 + 1);
  74.       */ //GYAKORLÁS ÓRÁN
  75. Haromszog h1; //Haromszog típusú változó h1 névvel -- referencia/hivatkozás változó
  76.         h1 = new Haromszog(5.0, 12.0, 13.0); // először a jobboldali kifejezés hajtódik végre( vmi = EZ ); ()-- konstruktor hívás; a "new" operátor a példányosítás operátora
  77.         //System.out.println(h1.getA()); //h1 változó által megnevezett "a" mezőre
  78.         //System.out.println(h1.getB());
  79.         //System.out.println(h1.getC());
  80.         //System.out.println(h1);
  81.        
  82. Haromszog h2 = new Haromszog(14.0, 22.0, 24.0);
  83.        // System.out.println(h2.getA());
  84.         //System.out.println(h2.getB());
  85.         //System.out.println(h2.getC());
  86.  
  87.         //h2.setB(121.0);
  88.         //System.out.println(h2.getA());
  89.        
  90.         //System.out.println(h2); //ez felel meg a h1,h2-es referenciának
  91.      
  92.          System.out.println("A háromszög területe: " +terulet(h1.getA(), h1.getB(), h1.getC()));
  93.      
  94.         System.out.println("A háromszöge területe 2 argumentummal: "+terulet(h1.getA(), h1.getB()));
  95.        
  96. Haromszog h3 = new Haromszog (3.00, 5.60, 6.80);
  97. Haromszog h4 = new Haromszog (11.00, 15.70, 18.89);
  98. Haromszog h5 = new Haromszog (20.30, 22.56, 25.00);
  99. Haromszog h6 = new Haromszog (30.00, 80.00, 91.00);
  100.  
  101.  
  102.  
  103. Haromszog[] htomb = {h1, h2, h3, h4, h5, h6};
  104.         //System.out.println(htomb[0].getA());
  105.        
  106.         for (int i=0; i< htomb.length; i++) {
  107.             System.out.println("A háromszögek területe:" + i + " " + terulet(htomb[i].getA(), htomb[i].getB(), htomb[i].getC()));
  108.         }
  109.        
  110.         //Arrays.sort(htomb, new Sajatcomparator2());
  111.        
  112.        
  113.     }
  114.     public static double terulet(double a, double b, double c){
  115.  
  116.     double s=0;
  117.     double terulet=0;
  118.    
  119.     s = (a+b+c)/2.00;
  120.      
  121.     terulet = Math.sqrt(s*(s-a)*(s-b)*(s-c));
  122.         System.out.println();
  123.     return terulet;
  124.     }
  125.    
  126.     public static double terulet(double a, double m){
  127.  
  128.         double terulet;
  129.         terulet= (a*m)/2.00;
  130.         return terulet;
  131.     }
  132.  
  133.  
  134.        
  135.        
  136. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement