Hello guys,

In the code below, I decided to clear the value 1 in the array to '0' and
if it is 1, it should print" the day is not a hoilday" but even when I
entered the number 1 in the command line, I still get the opposite of what
i expected : "the day is a holiday!" what am i doing wrong?

[CODE]

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package holidaysked;
import java.util.*;

/**
 *
 * @author henryjoseph
 */
public class HolidaySked {

   BitSet sked;

   public HolidaySked() //constructor
    {
       sked = new BitSet();
       int[] holiday = {1,15,50,148,185,246,281,316,326,359};
       for(int i= 0; i<holiday.length;i++)
           addHoliday(holiday[i]);
   }

    public void  addHoliday(int dayToAdd)
           {
        if(dayToAdd==1)
            sked.clear(dayToAdd);//set to zero
             sked.set(dayToAdd);
           }

    public boolean isholiday(int dayToCheck)
    {
      boolean result = sked.get(dayToCheck);
      return result;
    }
    public static void main(String[] args)
    {

        HolidaySked cal = new HolidaySked();
        if(args.length>0)
        {
          try{
              int whichDay = Integer.parseInt(args[0]);
              if(cal.isholiday(whichDay))
                  System.out.println("Day number" +whichDay + "is a
holiday");


                else  if(!cal.isholiday(whichDay))
                    System.out.println("Day number" +whichDay + "is not a
holiday");

              else
                 System.out.println("Day number" +whichDay + "is not a
holiday");

          } catch(NumberFormatException nfe){
              //System.out.println("oops!" +nfe.printStackTrace());
               System.out.println("oops!" +nfe.getMessage());

          }
        }
    }

}


[/CODE]

-- 
You received this message because you are subscribed to the Google Groups 
"JPassion.com: Java Programming" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/jpassion_java?hl=en.

Reply via email to