ERROR: non-static variable this cannot be referenced from static context
import java.util.*;
import java.io.*;
public class FinalCalculator{
static Scanner console = new Scanner(System.in);
public static void main(String[] args){
int days = 21;
int month = 3;
int year = 2002;
char era = 'a';
String name;
System.out.println("Please enter the name of the date:");
name = console.nextLine();
System.out.println("Please enter the day of the date:");
days = console.nextInt();
System.out.println("Please enter the month of the date:");
month = console.nextInt();
System.out.println("Please enter the year of the date:");
year = console.nextInt();
System.out.println("Please enter the era of the date. If the date is in the era before Christ enter B. If the date is in the era after Christ enter A.:");
era = console.next().charAt(0);
My_Date day = new My_Date (days, month, year, era);
}
public class My_Date {
public My_Date ()
{
myYear = 2007;
myMonth = 1;
myDay = 1;
myEra = 'A';
}
public My_Date (int d, int m, int y, char e)
{
if (isValid (d, m, y, e))
{
myDay = d;
myMonth = m;
myYear = y;
if (e == 'a')
e = 'A';
if (e == 'b')
e = 'B';
myEra = e;
}
else
{
myYear = 2007;
myMonth = 1;
myDay = 1;
myEra = 'A';
}
}
private boolean isValid (int d, int m, int y, char e)
{
if (y < 1)
return false;
if (m < 1 || m > 12)
return false;
if (e != 'a' && e != 'A' && e != 'b' && e != 'B')
return false;
if (d < 1 || d > daysInMonth (m, y, e))
return false;
if ((e == 'a' || e == 'A') && m == 9 && y == 1752
&& d > 2 && d < 14)
return false;
return true;
}
private int daysInMonth (int m, int y, char e)
{
switch (m)
{
case 4: case 6: case 9: case 11: return 30;
case 2: return 29;
default: return 31;
}
}
public void print ()
{
}
private int myYear, myMonth, myDay;
private char myEra;
}
}
I don't know why I'am getting this error...I guess it has to do with the constructor My_Date day = new My_Date(days, month, year, era). I don't know if this constructor is right. I need to execute the methods in class My_Date with the parameters that were input from user.
Any Help!
Thank You!!!
JAVI

