Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.text.DecimalFormat;
- import java.util.Arrays;
- import java.util.Comparator;
- import java.util.Scanner;
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- /**
- *
- * @author hallgato
- */
- public class teszt {
- public static void main(String[] args) {
- /* Haromszog h1; //Haromszog típusú változó h1 névvel -- referencia/hivatkozás változó
- 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
- System.out.println(h1.a); //h1 változó által megnevezett "a" mezőre
- System.out.println(h1.b);
- System.out.println(h1.c);
- h1.a = 2.0;
- h1.b = 3.0;
- h1.c = 4.0;
- System.out.println(h1.a); //h1 változó által megnevezett "a" mezőre
- System.out.println(h1.b);
- System.out.println(h1.c);
- Haromszog h2 = new Haromszog(); //kezdőérték adás egyből
- h2.a = 11.0;
- h2.b = 12.0;
- h2.c = 44.0;
- System.out.println(h2.a);
- System.out.println(h2.b);
- System.out.println(h2.c); */
- /*
- Haromszog h1; //Haromszog típusú változó h1 névvel -- referencia/hivatkozás változó
- 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
- System.out.println(h1.a); //h1 változó által megnevezett "a" mezőre
- System.out.println(h1.b);
- System.out.println(h1.c);
- Haromszog h2 = new Haromszog(11.0, 12.0, 44.0);
- System.out.println(h2.a);
- System.out.println(h2.b);
- System.out.println(h2.c);
- átírjuk privátra */
- /* float f = 12.5F;
- int i = (int)f;
- System.out.println("f is " + f);
- System.out.println("i is " + i);
- char x = 'a';
- char y = 'c';
- System.out.println(++x);
- System.out.println(y++);
- System.out.println(x - y);
- System.out.println("\n1" + 1);
- System.out.println('1' + 1);
- System.out.println("1" + 1 + 1);
- System.out.println("1" + (1 + 1));
- System.out.println('1' + 1 + 1);
- */ //GYAKORLÁS ÓRÁN
- Haromszog h1; //Haromszog típusú változó h1 névvel -- referencia/hivatkozás változó
- 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
- //System.out.println(h1.getA()); //h1 változó által megnevezett "a" mezőre
- //System.out.println(h1.getB());
- //System.out.println(h1.getC());
- //System.out.println(h1);
- Haromszog h2 = new Haromszog(14.0, 22.0, 24.0);
- // System.out.println(h2.getA());
- //System.out.println(h2.getB());
- //System.out.println(h2.getC());
- //h2.setB(121.0);
- //System.out.println(h2.getA());
- //System.out.println(h2); //ez felel meg a h1,h2-es referenciának
- System.out.println("A háromszög területe: " +terulet(h1.getA(), h1.getB(), h1.getC()));
- System.out.println("A háromszöge területe 2 argumentummal: "+terulet(h1.getA(), h1.getB()));
- Haromszog h3 = new Haromszog (3.00, 5.60, 6.80);
- Haromszog h4 = new Haromszog (11.00, 15.70, 18.89);
- Haromszog h5 = new Haromszog (20.30, 22.56, 25.00);
- Haromszog h6 = new Haromszog (30.00, 80.00, 91.00);
- Haromszog[] htomb = {h1, h2, h3, h4, h5, h6};
- //System.out.println(htomb[0].getA());
- for (int i=0; i< htomb.length; i++) {
- System.out.println("A háromszögek területe:" + i + " " + terulet(htomb[i].getA(), htomb[i].getB(), htomb[i].getC()));
- }
- //Arrays.sort(htomb, new Sajatcomparator2());
- }
- public static double terulet(double a, double b, double c){
- double s=0;
- double terulet=0;
- s = (a+b+c)/2.00;
- terulet = Math.sqrt(s*(s-a)*(s-b)*(s-c));
- System.out.println();
- return terulet;
- }
- public static double terulet(double a, double m){
- double terulet;
- terulet= (a*m)/2.00;
- return terulet;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement