Likes

Java Lab05_Ans2

WRITE A PROGRAM TO CREAT THAT CONTAINS A METHOD THAT ACCEPTS COMPASS DIRECTIONS AND DISPLAYS THE SAME.IN ADDITION,YOU NEED TO ENSURE THAT THE METHOD MUST ACCEPT ANY ONE OF THE DIRECTIONS: NORTH,SOUTH,EAST,WEST,NORTHEAST,SOUTHEAST,SOUTHWEST,OR NORTHWEST

ANSWER

enum CompassDirections
{
  NORTH, SOUTH, EAST, WEST, NORTHEAST, SOUTHEAST, SOUTHWEST, NORTHWEST;
}
     class TestCompassDirections
{


public void displayDirection(CompassDirections cd)
{
System.out.println(cd);
}
  public static void main(String[] args)
   {
TestCompassDirections tcd = new TestCompassDirections();
tcd.displayDirection(CompassDirections.EAST);
}
}

No comments: