what am I doing wrong?

Discussion in 'Java' started by S0All, Apr 12, 2012.

  1. S0All

    S0All

    Joined:
    Apr 12, 2012
    Messages:
    1
    When I run this program on JCreator I get the error "non-static method returnJulianDate(int,int,int) cannot be referenced from a static context"!
    What am I doing wrong? please help !



    import java.util.Scanner;

    public class ProjectTwo {
    final static int JANUARY = 1 ;
    final static int FEBRUARY = 2 ;
    final static int MARCH = 3 ;
    final static int APRIL = 4 ;
    final static int MAY = 5 ;
    final static int JUNE = 6 ;
    final static int JULY = 7 ;
    final static int AUGUST = 8 ;
    final static int SEPTEMBER = 9 ;
    final static int OCTOBER = 10 ;
    final static int NOVEMBER = 11 ;
    final static int DECEMBER = 12 ;

    public static boolean isALeapYear(int year) {
    boolean isALeapYear = false ;

    if ( ((year % 400) == 0) || (((year % 4) == 0) && ((year % 100) != 0 )) )
    isALeapYear = true ;

    return isALeapYear ;
    }

    public static int returnDaysInMonth(int year, int month) {
    int daysInMonth = 0 ;

    if ((month == JANUARY) || (month == MARCH) || (month == MAY) || (month == JULY) || (month == AUGUST) || (month == OCTOBER) || (month == DECEMBER))
    daysInMonth = 31 ;
    else
    if ((month == APRIL) || (month == JUNE) || (month == SEPTEMBER) || (month == NOVEMBER))
    daysInMonth = 30 ;
    else
    if ( month == FEBRUARY )
    if ( isALeapYear(year) )
    daysInMonth = 29 ;
    else
    daysInMonth = 28 ;

    return daysInMonth ;
    }

    public static String returnMonthName(int month) {
    String monthName = null ;

    if(month==JANUARY)
    monthName = "JANUARY" ;
    else
    if(month==FEBRUARY)
    monthName = "FEBRUARY";
    else
    if(month==MARCH)
    monthName = "MARCH";
    else
    if(month==APRIL)
    monthName = "APRIL" ;
    else
    if(month==MAY)
    monthName = "MAY";
    else
    if(month==JUNE)
    monthName = "JUNE";
    else
    if(month==JULY)
    monthName = "JULY";
    else
    if(month==AUGUST)
    monthName = "AUGUST";
    else
    if(month==SEPTEMBER)
    monthName = "SEPTEMBER";
    else
    if(month==OCTOBER)
    monthName = "OCTOBER";
    else
    if(month==NOVEMBER)
    monthName = "NOVEMBER";
    else
    //if(month==DECEMBER)
    monthName = "DECEMBER" ;

    return monthName ;
    }

    long returnJulianDate (int yearEntered, int monthEntered, int dayEntered){

    int year = 0 ;
    int month = 0 ;
    long counter = 0 ;

    year = 1600;
    while(year < yearEntered) {
    if(isALeapYear (year))
    counter += 366;
    else
    counter += 365;
    }
    month = 1;
    while(month < monthEntered ){
    counter += returnDaysInMonth(yearEntered, month);
    month += 1;
    }
    counter += dayEntered;

    return counter;
    }



    public static void main(String [] args) {
    Scanner keyboard = null ;
    int yearEntered = 0 ;
    int dayEntered = 0 ;
    int monthEntered = 0 ;
    int daysInMonth = 0 ;
    keyboard = new Scanner(System.in) ;


    System.out.print("Enter a month: ") ;
    monthEntered = keyboard.nextInt() ;


    System.out.print("Enter a day: ") ;
    dayEntered = keyboard.nextInt() ;


    System.out.print("Enter a year: ") ;
    yearEntered = keyboard.nextInt() ;


    daysInMonth = returnDaysInMonth(yearEntered, monthEntered) ;

    System.out.println("The date you entered is: "+ monthEntered + "/" + dayEntered + "/" + yearEntered + ", " + returnMonthName(monthEntered) + " has " + daysInMonth
    + " days" + "," + " Julian is " + returnJulianDate(yearEntered , monthEntered , dayEntered)) ;


    }
    }
    Last edited: Apr 12, 2012
    S0All, Apr 12, 2012
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Salisha Khan
    Replies:
    1
    Views:
    11,632
    JohnFol
    Aug 1, 2003
  2. Keith R. Williams

    What am I doing wrong?

    Keith R. Williams, Jul 14, 2003, in forum: VHDL
    Replies:
    4
    Views:
    1,020
    Ed Diego
    Jul 15, 2003
  3. ed
    Replies:
    1
    Views:
    648
    nobull@mail.com
    Jan 5, 2004
  4. Aaron Ackerman
    Replies:
    2
    Views:
    361
    Lewis Wang [MSFT]
    Jul 29, 2003
  5. J

    What am I doing wrong

    J, Aug 14, 2003, in forum: ASP .Net
    Replies:
    3
    Views:
    374
    John Saunders
    Aug 14, 2003
Loading...

Share This Page