Ejemplo n.º 1
0
  /** getDayNode() - return the DayNode object for the given day. */
  public DayNode getDayNode(String day) {
    int count = 0;
    boolean found = false;
    DayNode currDay = this.sun;

    while (!found && count < DAYS_IN_MONTH) {
      if (currDay.getDay().equals(day)) found = true;
      else {
        currDay = currDay.getNext();
        ++count;
      }
    }

    return currDay;
  }
Ejemplo n.º 2
0
  public Calendar() {
    // initialize days of the week
    this.sun = new DayNode("Sunday", 'N');
    DayNode currDayNode = sun;
    currDayNode.setNext(new DayNode("Monday", 'Y'));
    currDayNode = currDayNode.getNext();
    currDayNode.setNext(new DayNode("Tuesday", 'Y'));
    currDayNode = currDayNode.getNext();
    currDayNode.setNext(new DayNode("Wednesday", 'Y'));
    currDayNode = currDayNode.getNext();
    currDayNode.setNext(new DayNode("Thursday", 'Y'));
    currDayNode = currDayNode.getNext();
    currDayNode.setNext(new DayNode("Friday", 'Y'));
    currDayNode = currDayNode.getNext();
    currDayNode.setNext(new DayNode("Saturday", 'N'));
    currDayNode = currDayNode.getNext();
    currDayNode.setNext(sun);

    // initialize the months
    this.jan = new Month("JAN", "January", 31, 1);
    Month currMonth = jan;
    currMonth.setNext(new Month("FEB", "February", 28, 2));
    currMonth = currMonth.getNext();
    currMonth.setNext(new Month("MAR", "March", 31, 3));
    currMonth = currMonth.getNext();
    currMonth.setNext(new Month("APR", "April", 30, 4));
    currMonth = currMonth.getNext();
    currMonth.setNext(new Month("MAY", "May", 31, 5));
    currMonth = currMonth.getNext();
    currMonth.setNext(new Month("JUN", "June", 30, 6));
    currMonth = currMonth.getNext();
    currMonth.setNext(new Month("JUL", "July", 31, 7));
    currMonth = currMonth.getNext();
    currMonth.setNext(new Month("AUG", "August", 31, 8));
    currMonth = currMonth.getNext();
    currMonth.setNext(new Month("SEP", "September", 30, 9));
    currMonth = currMonth.getNext();
    currMonth.setNext(new Month("OCT", "October", 31, 10));
    currMonth = currMonth.getNext();
    currMonth.setNext(new Month("NOV", "November", 30, 11));
    currMonth = currMonth.getNext();
    currMonth.setNext(new Month("DEC", "December", 31, 12));
    currMonth = currMonth.getNext();
    currMonth.setNext(jan);
  }