'class' Or 'interface' Expected


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: 'class' Or 'interface' Expected

  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, 10:24 AM
  2. Replies: 2
    Last Post: 10-10-2001, 09:45 AM
  3. Replies: 0
    Last Post: 10-10-2001, 09:15 AM
  4. Interface leaks in C#?
    By Kevin Burton in forum .NET
    Replies: 12
    Last Post: 10-09-2000, 11:29 AM
  5. Replies: 0
    Last Post: 07-10-2000, 11:51 AM

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


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center