You are on page 1of 3

ADVANCE OBJECT ORIENTED PROGRAMMING 2020-CE-127

Task 3: Create enum for departments in an university – FINANCE, NETWORKS,


EXAMINATION, are all departments of a university. Use the department enum in employee
class.Traversed the department enum and prints the oridinal values.Enhanced enum with a new
private instance variable deptCode holding the department code, a getter method for deptCode
named getDeptCode(), and a constructor which accepts the department code at the time of enum
creation.

Source Code:
enum Department {

FINANCE("GB-01"), NETWORK("AB-01"), EXAMINATION("BT-01");

private final String deptCode;

Department(String deptCode){

this.deptCode=deptCode;

public String getDeptCode(){

return deptCode;

}}

public class Employee {

public static void main(String args[]) {

for(Department dept:Department.values()){

System.out.println(dept+" Department Code: "+dept.getDeptCode());

} }}

Output:

4|Page
ADVANCE OBJECT ORIENTED PROGRAMMING 2020-CE-127

Task 4: Create enum for spade, heart, diamond, and club belonging to an enumerated type called
cards stored each of the enumerators in the reference variables a1,a2,a3,a4 respectively.

Source Code:
enum Cards

spade, heart, diamond, club;

public class TASK2 {

public static void main(String[] args) {

Cards a1 = Cards.spade;

Cards a2 = Cards.heart;

Cards a3 = Cards.diamond;

Cards a4 = Cards.club;

System.out.println("Enumerators are: "+ a1 + "," + a2 + "," +

a3 + "," + a4);

Output:

5|Page
ADVANCE OBJECT ORIENTED PROGRAMMING 2020-CE-127

Task 5: created an enumeration called games with four enumerators(ludo, Chess, Badminton,
Cricket) initialize a for each loop (inside a class) and fetch the value of the enumerators.

Source Code:
enum Games

Ludo, Chess, Badminton, Cricket;

public class Task3 {

public static void main(String[] args) {

System.out.println("Games:");

for (Games g:Games.values()) {

System.out.println(g);

Output:

6|Page

You might also like