Can't compile with Eclipse
I've been doing some Java projects at school using Eclipse and i've got some homework to do during spring break.
I've downloaded Eclipse and all the needed Java plugins.
Now when I open a Java project that I worked on at school, it shows me the code, but when I click on "run as" it gives two options, both are "ants" or whatever. Doesn't matter which one i choose it won't show me the output, the actual program... Why ?
Any help ?
For example, this code worked perfectly fine at school, but won't do anything at home:
import java.util.Scanner;
class Car
{
Scanner scan = new Scanner(System.in);
double milesStart;
double milesEnd;
double gallons;
Car(double start, double end, double gals)
{
System.out.println("Enter starting miles: ");
start = scan.nextDouble();
milesStart = start;
System.out.println("Enter ending miles: ");
end = scan.nextDouble();
milesEnd = end;
System.out.println("Enter gallons used: ");
gals = scan.nextDouble();
gallons = gals;
}
double calculateMPG()
{
return (milesEnd - milesStart)/gallons;
}
boolean gasHog()
{
}
boolean economyCar()
{
}
}
class MPGTester
{
public static void main (String[] args)
{
Car car = new Car(0.0, 0.0, 0.0);
System.out.println( "MPG: " + car.calculateMPG() );
}
}
Re: Can't compile with Eclipse
Post moved to the IDE's thread.
Re: Can't compile with Eclipse
Right click on the java file containing the main() method, then choose RunAs...
This tells Eclipse what class you want to run (a project may contain many classes with a main(), or many different ways of running as well).
This is then added to your list of Run Configurations, which are accessible from the Run buttons (the green ones in the tool bar) should you not wish to always hunt around for the correct class to run.