Enum example

Enum example
 package com.ram;

enum Continents{
 AUSTRALIA, ASIA, EUROPE, AFRICA, NORTH_AMERICA, SOUTH_AMERICA, ANTARCTICA 
}

public class EnumExample {
 
 Continents continents;
 
 public EnumExample(Continents continents){
  this.continents = continents;
 }
 
 public void tellAboutContinents(){
  switch(continents){
   case AUSTRALIA:
    System.out.println("Australia is the largest island. Australia's Great Barrier Reef is the world's largest coral reef.");
    break;
    
   case ASIA:
    System.out.println("It is the largest continent. It is the home of the 10 highest mountain peaks in the world.");
    break;
   
   case EUROPE:
    System.out.println("In Europe, there are no deserts.It is the only continent without any deserts.");
    break;
   
   case AFRICA:
    System.out.println("Africa is very rich in minerals.Ninety five percent of the worlds’s diamonds and more than 50% of the world’s gold comes from Africa.");
    break;
    
   case NORTH_AMERICA:
    System.out.println("North America was named after the explorer Americo Vespucci. North America is the only continent that has every kind of climate.");
    break;
    
   case SOUTH_AMERICA:
    System.out.println("The Angel Falls of South America ,is the Highest Waterfall in the World.");
    break;
    
   case ANTARCTICA:
    System.out.println("Antarctica is a frozen land area around the South Pole.It is also called Frozen Continent.");
    break;
   
   default:
    System.out.println("Rest is ocean ...");
  }
 }
 
 public static void main(String[] args) {
  EnumExample australia = new EnumExample(Continents.AUSTRALIA);
  australia.tellAboutContinents();
  EnumExample asia = new EnumExample(Continents.ASIA);
  asia.tellAboutContinents();
  EnumExample europe = new EnumExample(Continents.EUROPE);
  europe.tellAboutContinents();
  EnumExample africa = new EnumExample(Continents.AFRICA);
  africa.tellAboutContinents();
  EnumExample northAmerica = new EnumExample(Continents.NORTH_AMERICA);
  northAmerica.tellAboutContinents();
  EnumExample southAmerica = new EnumExample(Continents.SOUTH_AMERICA);
  southAmerica.tellAboutContinents();
  EnumExample antarctica = new EnumExample(Continents.ANTARCTICA);
  antarctica.tellAboutContinents();
  
 }
}
 
 
 
Execute EnumExample class and you get the below output:

Australia is the largest island. Australia's Great Barrier Reef is the world's largest coral reef.
It is the largest continent. It is the home of the 10 highest mountain peaks in the world.
In Europe, there are no deserts.It is the only continent without any deserts.
Africa is very rich in minerals.Ninety five percent of the worlds’s diamonds and more than 50% of the world’s gold comes from Africa.
North America was named after the explorer Americo Vespucci. North America is the only continent that has every kind of climate.
The Angel Falls of South America ,is the Highest Waterfall in the World.
Antarctica is a frozen land area around the South Pole.It is also called Frozen Continent.

No comments:

Post a Comment