DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2005
    Posts
    3

    'class' Or 'interface' Expected

    Hi, I am a newbie here to this forum and to java, and was wondering if you guys could help me. I was trying to construct a gregorian calendar for current data and time, and I constantly get this error. Like I said before I'm new at java and just started a few weeks ago, hopefully you can take a look at what I have and help me figure out the prob.


    java.util.Calendar calendar = new java.util.GregorianCalendar();
    System.out.println("Year\tMonth\tDate\tHour\tHour24\tMinute\tSecond");
    System.out.println(calendar.get(Calendar.YEAR) + "\t" +
    calendar.get(Calendar.MONTH) + "\t" + calendar.get(Calendar.DATE)
    + "\t" + calendar.get(Calendar.HOUR) + "\t" +
    calendar.get(Calendar.MINUTE) + "\t" +
    calendar.get(Calendar.SECOND));
    System.out.print("Day of week: " +
    calendar.get(Calendar.DAY_OF_WEEK) + "\t");
    System.out.print("Day of month: " +
    calendar.get(Calendar.DAY_OF_MONTH) + "\t");
    System.out.println("Day of year: " +
    calendar.get(Calendar.DAY_OF_YEAR));
    System.out.print("Week of month: " +
    calendar.get(Calendar.WEEK_OF_MONTH) + "\t");
    System.out.print("Week of year: " +
    calendar.get(Calendar.WEEK_OF_YEAR));

    I'm wondering if I should declare a class before this code, thanks in advance

  2. #2
    Join Date
    Oct 2005
    Posts
    22
    Did you wrote any java programs before? If yes, Please paste the full code along with the errors.

  3. #3
    Join Date
    Nov 2004
    Location
    Norway
    Posts
    1,560
    I wrapped this in a class, and I fail to see any errors:
    Code:
    import java.io.*;
    import java.util.*;
    
    public class GregCal {
      public GregCal() {}
    
      public void writeCalendar(PrintStream out) {
    
        java.util.Calendar calendar = new java.util.GregorianCalendar();
        out.println("Year\tMonth\tDate\tHour\tHour24\tMinute\tSecond");
        out.println(calendar.get(Calendar.YEAR) + "\t" +
                    calendar.get(Calendar.MONTH) + "\t" +
                    calendar.get(Calendar.DATE)
                    + "\t" + calendar.get(Calendar.HOUR) + "\t" +
                    calendar.get(Calendar.MINUTE) + "\t" +
                    calendar.get(Calendar.SECOND));
        out.print("Day of week: " +
                  calendar.get(Calendar.DAY_OF_WEEK) + "\t");
        out.print("Day of month: " +
                  calendar.get(Calendar.DAY_OF_MONTH) + "\t");
        out.println("Day of year: " +
                    calendar.get(Calendar.DAY_OF_YEAR));
        out.print("Week of month: " +
                  calendar.get(Calendar.WEEK_OF_MONTH) + "\t");
        out.print("Week of year: " +
                  calendar.get(Calendar.WEEK_OF_YEAR));
    
      }
    
      public static void main(String[] args) {
        GregCal gc = new GregCal();
        gc.writeCalendar(System.out);
      }
    
    }
    eschew obfuscation

Similar Threads

  1. Replies: 0
    Last Post: 10-12-2001, 09:24 AM
  2. Replies: 2
    Last Post: 10-10-2001, 08:45 AM
  3. Replies: 0
    Last Post: 10-10-2001, 08:15 AM
  4. Interface leaks in C#?
    By Kevin Burton in forum .NET
    Replies: 12
    Last Post: 10-09-2000, 10:29 AM
  5. Replies: 0
    Last Post: 07-10-2000, 10:51 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links