Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- enum weekdays
- {
- HETFO, KEDD, SZERDA, CSUTORTOK, PENTEK, SZOMBAT, VASARNAP;
- }
- enum honapok
- {
- JANUAR(31), FEBRUAR(28), MARCIUS(30);
- private int value;
- private honapok(int value)
- {
- this.value = value;
- }
- public int getValue()
- {
- return value;
- }
- }
- enum orszagok
- {
- HUNGARY("Budapest", 93036, 9893899),
- GERMANY("Berlin", 357168, 80716000),
- SPAIN("Madrid", 505990, 46464053);
- private String capitalTown;
- private int area;
- private int population;
- private orszagok(String ct, int area, int population)
- {
- this.capitalTown = ct;
- this.area = area;
- this.population = population;
- }
- public String getCapitalTown()
- {
- return this.capitalTown;
- }
- public int getArea()
- {
- return this.area;
- }
- public int getPopulation()
- {
- return this.population;
- }
- public int getDensity()
- {
- return this.population / this.area;
- }
- }
- class enumclassTest
- {
- public static void main(String[] args)
- {
- weekdays w1 = weekdays.HETFO;
- System.out.println(w1);
- for (weekdays w2 : weekdays.values())
- System.out.printf("ENUM: %s\n", w2);
- for (honapok h1 : honapok.values())
- System.out.printf("ENUM: %s, értéke: %d\n", h1, h1.getValue());
- honapok h2 = honapok.JANUAR;
- System.out.printf("ENUM: %s, értéke: %d\n", h2, h2.getValue());
- orszagok o1 = orszagok.HUNGARY;
- System.out.printf("ENUM: %s, főváros: %s, terület (km2): %d\n", o1, o1.getCapitalTown(), o1.getArea());
- for (orszagok o2 : orszagok.values())
- {
- 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());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement