D:\Hany\HalalFarms\HalalCentersHaulersJavaProject\HalalCentersHauler\src\java\constants\EnumerationExample.java
 1 /*
 2  * To change this template, choose Tools | Templates
 3  * and open the template in the editor.
 4  */
 5 
 6 package constants;
 7 
 8 /**
 9  *
10  * @author sameldin
11  */
12 
13 public class EnumerationExample
14 {
15 
16     public enum Cars
17     {
18         MERCEDES(1),
19         MITSUBISHI(2),
20         MAZDA(3),
21         TOYOTA(4),
22         FERRARI(5);
23 
24         private final int id;
25 
26         Cars(int id)
27         {
28             this.id = id;
29         }
30         public int getValue()
31         {
32             return id;
33         }
34     }
35 
36     /**
37      * prints all Car items and its values
38 
39      */
40     public void printCarsValues()
41     {
42         Cars[] carsArray = Cars.values();
43 
44         for (int i=0; i < carsArray.length; i++)
45         {
46             Cars item = carsArray[i];
47             System.out.print(" CAR: " + item.name());
48             System.out.println(" VALUE: " + item.getValue());
49         }
50     }
51 
52     /**
53      * shows how to access any item in the enumeration
54 
55      */
56 
57     public void printOneCar()
58     {
59         System.out.println(" ------- \n print just one item \n ");
60         System.out.println("Car: " + Cars.MAZDA + " Value: " + Cars.MAZDA.getValue());
61 
62     }
63 
64     public static void main(String[] args){
65         // enum test values
66         EnumerationExample example = new EnumerationExample();
67         // print all the items
68         example.printCarsValues();
69         // print just one item
70         System.out.println("Car: " + Cars.MAZDA + " Value: " + Cars.MAZDA.getValue());
71         example.printOneCar();
72     }
73 }
74 
75