Advertisement
zsoltizbekk

2016.03.01_java

Mar 1st, 2016
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.63 KB | None | 0 0
  1. //Teszt.java
  2.  
  3. package geom;
  4.  
  5. import geom.Pont;
  6.  
  7. public class Teszt {
  8.    
  9.     public static void main(String[] args) {        
  10.         System.out.println("Hello vilag!");
  11.         Pont p1 = new Pont(3,5, "fekete");
  12.         //System.out.println("(" + p1.x + "," + p1.y + ")");
  13.         System.out.println("(" + p1.getX() + "," + p1.getY() + ")" + p1.getSzin());
  14.        
  15.         p1.setX(-3);
  16.         System.out.println("p1:(" + p1.getX() + "," + p1.getY() + ")" + p1.getSzin());
  17.        
  18.         Pont p2 = new Pont();
  19.         System.out.println("p2:(" + p2.getX() + "," + p2.getY() + ")" + p2.getSzin());
  20.        
  21.         System.out.println(p1.toString());
  22.        
  23.         Pont p3 = new Pont();
  24.        
  25.         System.out.println("p3:(" + p3.getX() + "," + p3.getY() + ")" + p3.getSzin());
  26.        
  27.         if (p2.equals(p3))
  28.             System.out.println("egyenlล‘");
  29.         else
  30.             System.out.println("nem egyenlล‘");
  31.        
  32.         System.out.printf("%5s, %-6.1f%c\n", "alma", 4.56, 'x');
  33.     }
  34. }
  35.  
  36.  
  37. //Pont.java
  38.  
  39. package geom;
  40.  
  41. import java.util.Objects;
  42.  
  43. public class Pont{
  44.    private int x;
  45.    private int y;
  46.    private String szin;
  47.    
  48.    //public Pont(){}
  49.  
  50.     public Pont(int x, int y) {
  51.         this.x = x;
  52.         this.y = y;
  53.         szin = "feher";
  54.     }
  55.  
  56.     public Pont(int x, int y, String szin) {
  57.         this (x, y);
  58. //        this.x = x;
  59. //        this.y = y;
  60. //        this.szin = szin;
  61.     }
  62.  
  63.     public Pont() {
  64.         this (0, 0);
  65. //        x = 0;
  66. //        y = 0;
  67.         szin = "feher";
  68.     }
  69.  
  70.     public int getX() {
  71.         return x;
  72.     }
  73.  
  74.     public int getY() {
  75.         return y;
  76.     }
  77.    
  78.     public String getSzin() {
  79.         return szin;
  80.     }
  81.    
  82.     public void setX(int x) {
  83.         this.x = x;
  84.     }
  85.  
  86.     public void setY(int y) {
  87.         this.y = y;
  88.     }
  89.  
  90.     public void setSzin(String szin) {
  91.         this.szin = szin;
  92.     }
  93.  
  94.     @Override
  95.     public String toString() {
  96.         return "(" + x + "," + y + ")" + szin;
  97.     }
  98.  
  99.     @Override
  100.     public int hashCode() {
  101.         int hash = 3;
  102.         return hash;
  103.     }
  104.  
  105.     @Override
  106.     public boolean equals(Object obj) {
  107.         if (obj == null) {
  108.             return false;
  109.         }
  110.         if (getClass() != obj.getClass()) {
  111.             return false;
  112.         }
  113.         final Pont other = (Pont) obj;
  114.         if (this.x != other.x) {
  115.             return false;
  116.         }
  117.         if (this.y != other.y) {
  118.             return false;
  119.         }
  120.         if (!Objects.equals(this.szin, other.szin)) {
  121.             return false;
  122.         }
  123.         return true;
  124.     }
  125.    
  126. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement