Advertisement
Guest User

Untitled

a guest
Jul 1st, 2015
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.65 KB | None | 0 0
  1. enum weekdays
  2. {
  3.     HETFO, KEDD, SZERDA, CSUTORTOK, PENTEK, SZOMBAT, VASARNAP;
  4. }
  5.  
  6. enum honapok
  7. {
  8.     JANUAR(31), FEBRUAR(28), MARCIUS(30);
  9.  
  10.     private int value;
  11.  
  12.     private honapok(int value)
  13.     {
  14.         this.value = value;
  15.     }
  16.     public int getValue()
  17.     {
  18.         return value;
  19.     }
  20. }
  21.  
  22. enum orszagok
  23. {
  24.     HUNGARY("Budapest", 93036, 9893899),
  25.     GERMANY("Berlin", 357168, 80716000),
  26.     SPAIN("Madrid", 505990, 46464053);
  27.  
  28.     private String capitalTown;
  29.     private int area;
  30.     private int population;
  31.  
  32.     private orszagok(String ct, int area, int population)
  33.     {
  34.         this.capitalTown = ct;
  35.         this.area = area;
  36.         this.population = population;
  37.     }
  38.  
  39.     public String getCapitalTown()
  40.     {
  41.         return this.capitalTown;
  42.     }
  43.  
  44.     public int getArea()
  45.     {
  46.         return this.area;
  47.     }
  48.  
  49.     public int getPopulation()
  50.     {
  51.         return this.population;
  52.     }  
  53.  
  54.     public int getDensity()
  55.     {
  56.         return this.population / this.area;
  57.     }
  58. }
  59.  
  60. class enumclassTest
  61. {
  62.     public static void main(String[] args)
  63.     {
  64.         weekdays w1 = weekdays.HETFO;
  65.         System.out.println(w1);
  66.  
  67.         for (weekdays w2 : weekdays.values())
  68.             System.out.printf("ENUM: %s\n", w2);       
  69.  
  70.         for (honapok h1 : honapok.values())
  71.             System.out.printf("ENUM: %s, értéke: %d\n", h1, h1.getValue());
  72.  
  73.         honapok h2 = honapok.JANUAR;
  74.         System.out.printf("ENUM: %s, értéke: %d\n", h2, h2.getValue());
  75.  
  76.         orszagok o1 = orszagok.HUNGARY;
  77.         System.out.printf("ENUM: %s, főváros: %s, terület (km2): %d\n", o1, o1.getCapitalTown(), o1.getArea());
  78.  
  79.         for (orszagok o2 : orszagok.values())
  80.         {
  81.             System.out.printf("ENUM: %s, főváros: %s, terület (km2): %d, Népsűrűség: %d\n", o2, o2.getCapitalTown(), o2.getArea(), o2.getDensity());
  82.         }
  83.     }  
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement