Results 1 to 6 of 6
  1. #1
    andrew_smiley is offline Member
    Join Date
    Feb 2012
    Posts
    2
    Rep Power
    0

    Default What am I missing here..?

    Hello everyone,

    I'm pretty new to Java, so this is some pretty simple stuff.. However, I'm curious as to what I'm doing wrong. This code was initially taken from a book,
    which I copied, line for line, or so I believe.. The only change I made is changing the name of the main class.. Compiling using a cmd shell window..

    here it is..



    import java.text.DateFormatSymbols;
    import java.util.*;


    public class GreCal
    {
    public static void main(String[] args)
    {

    GregorianCalendar d = new GregorianCalendar();


    int today = d get(Calendar.DAY_OF_MONTH);
    int month = d get(Calendar.MONTH);

    d.set(Calendar.DAY_OF_MONTH, 1);

    int weekday = d.get(Calendar.DAY_OF_WEEK);

    // get first day of week (Sunday in the U.S.)
    int firstDayOfWeek = d.getFirstDayOfWeek();

    // determine the required indentation for the first line
    int indent = 0;
    while (weekday != firstDayOfWeek)
    {
    indent++;
    d.add(Calendar.DAY_OF_MONTH, -1);
    weekday = d.get(Calendar.DAY_OF_WEEK);
    }

    // print weekday names
    String[] weekdayNames = new DateFormatSymbols().getShortWeekdays();
    do
    {
    System.out.printf("%4s", weekdayNames[weekday]);
    d.add(Calendar.DAY_OF_MONTH, 1);
    weekday = d.get(Calendar.DAY_OF_WEEK);
    }
    while (weekday != firstDayOfWeek);
    System.out.println();

    for (int i = 1; i <= indent; i++)
    System.out.print(" ");

    d.set(Calendar.DAY_OF_MONTH, 1);
    do
    {
    // print day
    int day = d.get(Calendar.DAY_OF_MONTH);
    System.out.printf("%3d", day);

    // mark current day with *
    if (day == today) System.out.print("*");
    else System.out.print(" ");

    // advance d to the next day
    d.add(Calendar.DAY_OF_MONTH, 1);
    weekday = d.get(Calendar.DAY_OF_WEEK);

    // start a new line at the start of the week
    if (weekday == firstDayOfWeek) System.out.println();
    }
    while (d.get(Calendar.MONTH) == month);
    // the loop exits when d is day 1 of the next month

    // print final end of line if necessary
    if (weekday != firstDayOfWeek) System.out.println();
    }
    }


    d.add(Calendar.DAY_OF_MONTH,1);
    weekday = d.get(Calendar.DAY_OF_WEEK);

    if(weekday == firstDayOfWeek) System.out.println();
    }
    while (d.get(Calendar.MONTH)==month);

    if(weekday != firstDayOfWeek) System.out.println();
    }
    }

    Any suggestion helps.. Thanks!
    Last edited by andrew_smiley; 02-22-2012 at 01:30 AM.

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,449
    Rep Power
    25

    Default Re: What am I missing here..?

    what I'm doing wrong
    Can you explain what the problem is?

    Copy the full text of any error messages and paste them here.

  3. #3
    andrew_smiley is offline Member
    Join Date
    Feb 2012
    Posts
    2
    Rep Power
    0

    Default Re: What am I missing here..?

    Quote Originally Posted by Norm View Post
    Can you explain what the problem is?

    Copy the full text of any error messages and paste them here.

    GreCal.java:13: error: ';' expected
    int today = d get(Calendar.DAY_OF_MONTH);
    ^
    GreCal.java:14: error: ';' expected
    int month = d get(Calendar.MONTH);
    ^
    GreCal.java:73: error: class, interface, or enum expected
    d.add(Calendar.DAY_OF_MONTH,1);
    ^
    GreCal.java:74: error: class, interface, or enum expected
    weekday = d.get(Calendar.DAY_OF_WEEK);
    ^
    GreCal.java:76: error: class, interface, or enum expected
    if(weekday == firstDayOfWeek) System.out.println();
    ^
    GreCal.java:77: error: class, interface, or enum expected
    }
    ^
    GreCal.java:80: error: class, interface, or enum expected
    if(weekday != firstDayOfWeek) System.out.println();
    ^
    GreCal.java:81: error: class, interface, or enum expected
    }
    ^
    8 errors



    Like I said, I can't figure it out.

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,449
    Rep Power
    25

    Default Re: What am I missing here..?

    GreCal.java:13: error: ';' expected
    Where is the ^ pointer in the error messages? Look at the code in the source line in the error messages just above the ^.
    The compiler is confused at that point and thinks there should be a ; there that ends the statement.

    Your unformatted code makes it hard to read and understand your code. You need to enclose the code in code tags to preserve the formatting and to make the code readable. BB Code List - Java Programming Forum

    Make sure the statements are inside of a method.

    Some of the code looks like you were copying and pasting it without being careful where you put it.
    Last edited by Norm; 02-22-2012 at 01:42 PM.

  5. #5
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,532
    Blog Entries
    7
    Rep Power
    20

    Default Re: What am I missing here..?

    Your curly brackets don't match and they have severly confused the compiler.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,014
    Rep Power
    20

    Default Re: What am I missing here..?

    Look at how you called the get() method on 'd' on this line that the compiler hasn't complained about:
    Java Code:
    int weekday = d.get(Calendar.DAY_OF_WEEK);
    Now compare that with this line that does cause the compiler to complain:
    Java Code:
    int today = d get(Calendar.DAY_OF_MONTH);
    ...and also do as Norm suggests and see where the error pointer is pointing...always a good thing to be able to read the errors.

Similar Threads

  1. org.j3d is missing...
    By LinuxDev@Flanders in forum Java Gaming
    Replies: 3
    Last Post: 07-23-2012, 12:31 PM
  2. Avatar missing?
    By DarrylBurke in forum Forum Lobby
    Replies: 5
    Last Post: 05-05-2011, 03:47 PM
  3. unclear what i missing
    By silverspoon34 in forum New To Java
    Replies: 2
    Last Post: 04-13-2011, 08:11 PM
  4. Help; Missing JButtons
    By Cyprusice in forum New To Java
    Replies: 3
    Last Post: 01-10-2010, 11:50 PM
  5. is it bug? or am i missing a point?
    By blowguy in forum Threads and Synchronization
    Replies: 1
    Last Post: 11-20-2007, 06:19 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •