Hello,
i am new at Java and i am trying to create a class called Vehicle but everytime i try to call it the error "could not find or load main class Vehicle" is shown. even though i try to find mistakes in my code i can not. The code is:
public class Vehicle
{
String make;
String color;
boolean engineState;
void startEngine()
{
if (engineState == true)
System.out.println("The engine is already on!");
else
{
engineState = true;
System.out.println("The engine is now on.");
}
}
void showAttributes()
{
System.out.println("This vehicle is a " + color + "
" + make);
if (engineState == true)
System.out.println("The engine is on.");
else
System.out.println("The engine is off.");
}
public static void main(String args[])
{
// Create a new vehicle and set its attributes.
Vehicle car = new Vehicle();
car.make = "Rolls Royce";
car.color = "Midnight blue";
System.out.println("Calling showAttributes ...");
car.showAttributes();
System.out.println("--------");
System.out.println("Starting the engine ...");
car.startEngine();
System.out.println("--------");
System.out.println("Calling showAttributes ...");
car.showAttributes();
// Let’s try to start the engine again.
System.out.println("--------");
System.out.println("Starting the engine ...");
car.startEngine();
}
}
i am new at Java and i am trying to create a class called Vehicle but everytime i try to call it the error "could not find or load main class Vehicle" is shown. even though i try to find mistakes in my code i can not. The code is:
public class Vehicle
{
String make;
String color;
boolean engineState;
void startEngine()
{
if (engineState == true)
System.out.println("The engine is already on!");
else
{
engineState = true;
System.out.println("The engine is now on.");
}
}
void showAttributes()
{
System.out.println("This vehicle is a " + color + "
" + make);
if (engineState == true)
System.out.println("The engine is on.");
else
System.out.println("The engine is off.");
}
public static void main(String args[])
{
// Create a new vehicle and set its attributes.
Vehicle car = new Vehicle();
car.make = "Rolls Royce";
car.color = "Midnight blue";
System.out.println("Calling showAttributes ...");
car.showAttributes();
System.out.println("--------");
System.out.println("Starting the engine ...");
car.startEngine();
System.out.println("--------");
System.out.println("Calling showAttributes ...");
car.showAttributes();
// Let’s try to start the engine again.
System.out.println("--------");
System.out.println("Starting the engine ...");
car.startEngine();
}
}