Advertisement
zsoltizbekk

ora2

Sep 21st, 2015
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.33 KB | None | 0 0
  1. HAROMSZOG.JAVA
  2.  
  3.  
  4. import javax.swing.JOptionPane;
  5.  
  6. /*
  7.  * To change this license header, choose License Headers in Project Properties.
  8.  * To change this template file, choose Tools | Templates
  9.  * and open the template in the editor.
  10.  */
  11.  
  12. /**
  13.  *
  14.  * @author hallgato
  15.  */
  16. public class haromszog {
  17.  
  18.     private double a, b, c; //adattag
  19.     //private jobb gomb, insert getter, setter
  20.     public void setA(double a) {
  21.         if (0.0 < a && a < this.b + this.c){
  22.         this.a = a;
  23.         }
  24.         else {
  25.             JOptionPane.showMessageDialog(null, "Nem jรณ oldalhossz!", "Hiba", JOptionPane.ERROR_MESSAGE); //grafikus hibauzenet
  26.             //throw new IllegalArgumentException("Hibas oldalhossz!");
  27.         }
  28.     }
  29.  
  30.     public void setB(double b) {
  31.         this.b = b;
  32.     }
  33.  
  34.     public void setC(double c) {
  35.         this.c = c;
  36.     }
  37.  
  38.     public double getA() {
  39.         return a;
  40.     }
  41.  
  42.     public double getB() {
  43.         return b;
  44.     }
  45.  
  46.     public double getC() {
  47.         return c;
  48.     }
  49. public String tostring(){
  50.             return "a=" + a + ", b=" + b + ", c" + c;
  51.    
  52. }
  53.     public haromszog(double a, double b, double c) {
  54.         this.a = a;
  55.         this.b = b;
  56.         this.c = c;
  57.  
  58.     }
  59. }
  60.  
  61.  
  62.  
  63.  
  64. TESZT.JAVA
  65.  
  66.  
  67.  
  68. import java.time.Clock;
  69.  
  70. /*
  71.  * To change this license header, choose License Headers in Project Properties.
  72.  * To change this template file, choose Tools | Templates
  73.  * and open the template in the editor.
  74.  */
  75.  
  76. /**
  77.  *
  78.  * @author hallgato
  79.  */
  80. public class Teszt {
  81.  
  82.     public static void main(String[] args) {
  83.         haromszog h1;
  84.         h1 = new haromszog(3.0, 4.0, 5.0);
  85.         System.out.println(h1.getA());
  86.         System.out.println(h1.getB());
  87.         System.out.println(h1.getC());
  88.        
  89.         h1.setA(2.0);
  90.         h1.setB(3.0);
  91.         h1.setC(4.0);
  92.        
  93.         System.out.println(h1.getA());
  94.         System.out.println(h1.getB());
  95.         System.out.println(h1.getC());
  96.        
  97.         System.out.println(h1); //objektumok string reprezentacioja
  98.        
  99.         haromszog h2=new haromszog(11.0, 12.0, 13.0);
  100.        
  101.         h2.setA(22.0);
  102.         h2.setB(23.0);
  103.         h2.setC(24.0);
  104.        
  105.         System.out.println(h2.getA());
  106.         System.out.println(h2.getB());
  107.         System.out.println(h2.getC());
  108.        
  109.  
  110.     }
  111.  
  112. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement