-2

I can't seem to instantiate an object from a class that I've written into the main method. I don't know if its a problem with my code or netBeans. Here's is the program with comments solely for the question:

package app;
import java.util.Scanner;
public class SetUpSite {
public static void main(String[] args) {
    final int FOUNDED_YEAR = 1977;
    int currentYear;
    int age;
    statementOfPhilosophy();
    Scanner reader = new Scanner(System.in);
    //the very next line is the only line unrecognized
    EventSite oneSite = new EventSite();
    int siteNum;
    System.out.print("Enter the event site number: ");
    siteNum = reader.nextInt();
    oneSite.setSiteNumber(siteNum);
    System.out.print("Enter the Current year of the company: ");
    currentYear = reader.nextInt();
    System.out.println("The age of the Company is "+ calculateAge(FOUNDED_YEAR,        currentYear) + " years");

}

public static void statementOfPhilosophy() {
System.out.println("Event Handlers INC");
}
public static int calculateAge(final int ORIGINAL_YEAR, int currentDate) {
    int years = currentDate - ORIGINAL_YEAR;
    return years;

}

public class EventSite {
private int siteNumber;

public void oneSite() {

}
public int getSiteNumber() {
return siteNumber;
}

public void setSiteNumber(int n) {
    siteNumber = n;
}

}
}
RobertB
  • 4,592
  • 1
  • 30
  • 29
Sudo
  • 1
  • 1

1 Answers1

1

EventSite is a public inner class of SetUpSite, and this is messing you up. Get your EventSite class code out of the SetUpSite class and instead put it in its own file where it belongs. A Java file cannot have more than one top-level public class.

You could make it a private inner class, and make it static internal class, but with no good reason for doing so, or could make it private and create it on top of a SetUpSite instance, but this is an ugly and unnecessary kludge.

Hovercraft Full Of Eels
  • 283,665
  • 25
  • 256
  • 373