Saturday, September 17, 2016

8. Write a JAVA Program a. Create an enumeration Day of Week with seven values SUNDAY through SATURDAY. Add a method is Workday( ) to the DayofWeek class that returns true if the value on which it is called is MONDAY through FRIDAY. For example, the call DayOfWeek.SUNDAY.isWorkDay ( ) returns false.

import java.io.*;
class Enumaration
  {
     public enum DayOfWeek
         {
                     MONDAY(1),TUESDAY(2),WEDNESDAY(3),THURSDAY(4),FRIDAY(5),
SATURDAY(6),SUNDAY(7);
                     public int val;
                     DayOfWeek(int val)
                         {
                                 this.val=val;
                         }
                     boolean isWorkDay()
                         {
                                 if(val<6)
                                             return true;
                                 else
                                             return false;
                         }
         }
    public static void main(String[] args)
         {
                     DayOfWeek Day;
                     System.out.println(" verfication of sunday(isWorkDay())");  
                     System.out.println(DayOfWeek.SUNDAY.isWorkDay());
                     System.out.println(" verfication of Wednesday(isWorkDay())");  
                     System.out.println(DayOfWeek.WEDNESDAY.isWorkDay());
         }

  }

2 comments: