what am I doing wrong?


Joined
Apr 12, 2012
Messages
1
Reaction score
0
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:
Ad

Advertisements


Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top