'Eclipse says "cannot be resolved to a type" [duplicate]

So I'm doing an assignment for school and its my first CS class. We have to create a Mars Landing Simulator. On the line,

MarsLander lander = new MarsLander(850, engineIgnitionTime, engineThrust);

The code on that line says "MarsLander cannot be resolved to a type". Why is it saying that? I've been stuck on this for three days. I have no clue what I'm doing.

import java.util.Scanner;


public class MarsLandingSimulator {

    private static final double ALTITUDE_START = 10000.0;
    

    public static void main(String[] args) {
        
        System.out.println("-----------------------------------------");
        System.out.println("|                                       |");
        System.out.println("| Welcome to the Mars Landing Simulator |");
        System.out.println("|                                       |");
        System.out.println("-----------------------------------------");
        System.out.println();
        System.out.println(""
                + "This program will simulate the final phase\n"
                + "of a rocket landing on Mars! \n\n"
                + "The rocket will free-fall from a height of\n"
                + "10,000 meters until the engines are ignited\n"
                + "at a certain time after the fall starts.\n\n"
                + "Your job is to choose the engine ignition\n"
                + "time and engine thrust to make a safe landing.\n\n"
                + "The lander's engines have enough fuel for\n"
                + "a 300 second burn.");
        System.out.println();
        
        Scanner keyboard = new Scanner(System.in);
        String input = "";

        // outer loop to give the user multiple chances
        do {
            
            printLine(40);
            System.out.printf("%-45s","Enter the engine ignition time (seconds): ");
            input = keyboard.nextLine();
            double engineIgnitionTime = Double.parseDouble(input);

            System.out.printf("%-45s","Enter the engine thrust (Newtons): ");
            input = keyboard.nextLine();
            double engineThrust = Double.parseDouble(input);

            // Create an instance of the MarsLander
            // During the final phase of landing, the mars lander
            // will have a mass of 850kg
            MarsLander lander = new MarsLander(850, engineIgnitionTime, engineThrust);
            
            // Set the initial altitude
            lander.setAltitude(ALTITUDE_START);
            
            // run the simulation.
            runSimulation(lander);
            
            // try again prompt
            System.out.println("\n");
            System.out.printf("Would you like to run another simulation? ");
            input = keyboard.nextLine();
        } while(input.toLowerCase().startsWith("y"));
                
        
        System.out.println("\n");
        System.out.println("Thank you for trying the Mars Landing Simulator.");
        
        keyboard.close();
    }
    
    /**
     * Helper method to print out a line with a given length.
     * @param length
     */
    private static void printLine(int length) {
        for (int i=0; i<length; i++) {
            System.out.print("-");
        }
        System.out.print("\n");
    }
    
    /**
     * Performs a simulation given a MarsLander object
     * with initial conditions pre-set.
     * @param lander
     */
    private static void runSimulation(MarsLander lander) {
        
        // Set the time increment
        double dt = 0.01;
        
        // Set the maximum simulation time in seconds
        double simulationTimeMax = 20 * 60; 
        
        // index for displaying the result
        int displayIndex = 0;
        int displayPeriod = (int)(1.0 / dt);
        
        System.out.println("\n");       
        System.out.println("LANDING TELEMETRY:");
        // print the column headers
        System.out.printf("%10s%10s%10s%10s\n", "ET(s)", "A(m)", "v(m/s)","a(m/s^2)");
        printLine(40);
        
        // Simulate the fall of the Rocket.
        for (double simulationTime = 0.0; simulationTime<simulationTimeMax && lander.getAltitude()>0; simulationTime+=dt) {
            
            // Update the lander status at each point in the simulation
            lander.update(simulationTime);
            
            // Update the report output every display period to limit the amount of data
            // displayed to the user.
            if ((displayIndex++ % displayPeriod) == 0) {
                lander.display();
            }
        }
        // display the final state of the lander
        lander.display();
        
        // Create the landing report
        printLine(40);
        System.out.println();

        // Create the final report
        System.out.println("LANDING REPORT:");
        printLine(40);
        System.out.printf("%-20s %,10.1f (s)\n", "Elapsed Time:", lander.getTime());
        System.out.printf("%-20s %,10.1f (s)\n", "Engine Burn Time:", Math.abs(lander.getEngineBurnDuration()));
        System.out.printf("%-20s %,10.3f (m/s)\n", "Terminal Velocity:", Math.abs(lander.getVelocity()));
        System.out.printf("%-20s %,10.1f (%%)\n", "Fuel Remaining:", 100.0 * (MarsLander.ENGINE_MAX_BURN_DURATION - lander.getEngineBurnDuration()) / MarsLander.ENGINE_MAX_BURN_DURATION);
        
        
        // Evaluate the landing         
        // Did we make it to the ground in time?
        String missionStatus = "";
        if (lander.getAltitude() > ALTITUDE_START) {
            missionStatus = "Landing failed.\n"
                    + "The lander has returned to orbit\n"
                    + "and is out of fuel for a second attempt.";
        }
        else if (lander.getAltitude()>1.0) {
            missionStatus = "Landing failed.\n"
                    + "Landing engine fuel has been exhausted.\n"
                    + "The lander has sustained major damage\n"
                    + "and is no longer functioning.";
        } 
        // we made it to the ground but how fast were we going?
        // A landing speed greater than 1.0 m/s is considered a crash. 
        // Major damage to the lander will have occurred
        else if (Math.abs(lander.getVelocity()) > 1.0) {
            missionStatus = "Landing failed.\n"
                    + "Terminal Velocity exceeded maximum safety limits.\n"
                    + "The lander has sustained major damage\n"
                    + "and is no longer functioning.";
        } 
        // A landing speed between 1.0 and 0.1 m/s is considered a hard landing.
        // Minor damage may have occurred.
        else if (Math.abs(lander.getVelocity()) > 0.1) {
            missionStatus = "Hard landing.\n"
                    + "Terminal Velocity exceeded optimal safety limits.\n"
                    + "The lander has sustanined minor damage\n"
                    + "but is still mostly operational.";
        } 
        // A landing speed between 0.1 and 0.01 meters per second is a good landing.
        else if (Math.abs(lander.getVelocity()) > 0.01) {
            missionStatus = "Good landing.\n"
                    + "The lander has not sustained any damage.\n"
                    + "There is a slight probability that\n"
                    + "some sensitive experiments were disturbed.";
        } 
        
        // A landing speed below 0.01 meters per second is a perfect landing
        else {
            missionStatus = "Perfect landing.\n"
                    + "No damage to the lander or experiments on board.\n"
                    + "Congratulations!";
        }
        System.out.printf("\n%s\n%s\n","Mission Status:", missionStatus);
        printLine(40);
        
    }

}


Solution 1:[1]

It seems like Eclipse cannot find the MarsLander class and thus it cannot instantiate a MarsLander variable.

You either forgot to define the MarsLander class within your project or you did not import the whole project's files if this was an example from your teacher.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Dan