Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: helo

  1. #1
    Junior Member
    Join Date
    Oct 2010
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default helo

    Hi Guys, how are you all. I seem to be having a problem getting my program to highlight the date which is typed as the third command line argument. There are three command line arguments; 1st one is the starting date, second is the month, and the third is the date to highlight.

    Here is the code:

     
    // Program to print a calendar for a given month.
    // First argument is the number of the start day, 1 to 7
    // Second argument is the last date in the month e.g. 28.
    public class CalendarHighlight
    {
      public static void main(String [] args)
      {
        printMonth(Integer.parseInt(args[0]), Integer.parseInt(args[1]));
     
      } // main
     
      // Print the calendar for the month.
      private static void printMonth(int monthStartDay, 
                                     int lastDateInMonth)
      {
        // Keep track of which day 1 to 7 is the next day to be printed
        // out.
        int nextDayColumnToUse = monthStartDay;
     
        // Keep track of next date to be printed out.
        int nextDateToPrint = 1;
     
        // Print top line of calendar.
        printMonthLineOfHyphens();
     
        // Print headings i.e. su, mo, tu etc.
        printDayNames();
     
        // Print out minimum 6 rows to ensure consistent format.
        int noOfRows = 0;
        while (nextDateToPrint <= lastDateInMonth || noOfRows < 6)
        {
          // Print one row.
          System.out.print(" | ");
          for (int dayColumnNo = 1; dayColumnNo <= 7; dayColumnNo++)
          {
    	// Print a space separator between day columns.
            if (dayColumnNo > 1)
    	  System.out.print("    ");
     
    	// We either print spaces or date.
    	if (dayColumnNo != nextDayColumnToUse
    	    || nextDateToPrint > lastDateInMonth)
    	  printDateSpace();
    	else
    	{
    	  printDate(nextDateToPrint);
    	  nextDayColumnToUse++;
    	  nextDateToPrint++;
    	} // else
          } // for
     
          // Print separator and end the row.
          System.out.println(" | ");
          noOfRows++;
     
          // The next row.
          nextDayColumnToUse = 1;
        } // while
     
        // Print bottom line of calendar.
        printMonthLineOfHyphens();
      } // printMonth
     
      // Print line of hyphens as wide as table starting with
      // spaces and ending with spaces so it looks right.
      private static void printMonthLineOfHyphens()
      {
        System.out.print("  ");
        for (int dayColumnNo = 1; dayColumnNo <= 7; dayColumnNo++)
        {
          if (dayColumnNo > 1)
            System.out.print("---");
          printDateHyphens();
        } // for
        System.out.println("    ");
      } // printMonthLineOfHyphens
     
      // Print headings of days in the week.
      private static void printDayNames()
      {
        System.out.print(" | ");
        for (int dayColumnNo = 1; dayColumnNo <= 7; dayColumnNo++)
        {
          if (dayColumnNo > 1)
            System.out.print("    ");
          printDayName(dayColumnNo);
        } // for
        System.out.println(" | ");
      } // printDayNames
     
      // Print Day names as two characters.
      private static void printDayName(int dayNo)
      {
        // Days in the week are numbered 1 - 7 from sunday so:
        switch (dayNo)
        {
          case 1: System.out.print("Su"); break;
          case 2: System.out.print("Mo"); break;
          case 3: System.out.print("Tu"); break;
          case 4: System.out.print("We"); break;
          case 5: System.out.print("Th"); break;
          case 6: System.out.print("Fr"); break;
          case 7: System.out.print("Sa"); break;
        } // switch
      } // printDayName
     
      // Print spaces as wide as date between the dates.
      private static void printDateSpace()
      {
        System.out.print("  ");
      } // printDateSpace
     
      // Print hyphens as wide as the date.
      private static void printDateHyphens()
      {
        System.out.print("---");
      } // printDateHyphens
     
      // Print date using two characters, with leading zero if required.
      private static void printDate(int date)
      {
        System.out.printf("%02d", date);
      } // printDate
     
     
    } // class CalendarHighlight

    Any suggestions guys?

    Kind regards

    Shyam
    Last edited by Shyamz1; November 23rd, 2010 at 12:58 PM. Reason: Wrong code


  2. #2
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default Re: helo

    What do you mean by highlight?

Similar Threads

  1. helo
    By FaintSmile in forum Member Introductions
    Replies: 1
    Last Post: July 14th, 2010, 02:33 AM