Errors

What does it say and can you help me debug it ?
No description
6 Replies
JavaBot
JavaBot6mo ago
This post has been reserved for your question.
Hey @OMIDD! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically marked as dormant after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
reiwa
reiwa6mo ago
You need to make sure you have created a Java file named IAuto.java and defined the IAuto interface (public interface IAuto { ... }). Same problems with IElectricCar and IFuelCar. Similarly, the tesla and ford variables are being used as if they have already been declared and initialized, but no such declarations exist. Make sure you instantiate them: IAuto tesla = new Car("Tesla Model S");, for example.
OMIDD
OMIDDOP6mo ago
import Model.ElectricModel;
import Model.FuelModel;

import Entities.ElectricCar;
import Entities.FuelCar;

public class Main {
public static void main(String[] args) {
// Create models
ElectricModel teslaModel = new ElectricModel("Model 3", "Tesla", 2023, 75);
FuelModel fordModel = new FuelModel("Focus", "Ford", 2022, 50, "Gasoline");

// Create cars
ElectricCar tesla = new ElectricCar(teslaModel);
FuelCar ford = new FuelCar(fordModel);

// Display car info
System.out.println("=== ELECTRIC CAR ===");
System.out.println(tesla);
tesla.startEngine();
tesla.charge();
System.out.println("\nAfter charging:\n" + tesla);

System.out.println("\n=== FUEL CAR ===");
System.out.println(ford);
ford.startEngine();
ford.refuel();
System.out.println("\nAfter refueling:\n" + ford);

// Demonstrate LSP
System.out.println("\n=== LSP DEMONSTRATION ===");
IAuto[] vehicles = {tesla, ford};
for (IAuto vehicle : vehicles) {
System.out.println("\nVehicle: " + vehicle.getModel().getFullName());
vehicle.startEngine();

if (vehicle instanceof IElectricCar) {
((IElectricCar) vehicle).charge();
}
if (vehicle instanceof IFuelCar) {
((IFuelCar) vehicle).refuel();
}
}
}
}
import Model.ElectricModel;
import Model.FuelModel;

import Entities.ElectricCar;
import Entities.FuelCar;

public class Main {
public static void main(String[] args) {
// Create models
ElectricModel teslaModel = new ElectricModel("Model 3", "Tesla", 2023, 75);
FuelModel fordModel = new FuelModel("Focus", "Ford", 2022, 50, "Gasoline");

// Create cars
ElectricCar tesla = new ElectricCar(teslaModel);
FuelCar ford = new FuelCar(fordModel);

// Display car info
System.out.println("=== ELECTRIC CAR ===");
System.out.println(tesla);
tesla.startEngine();
tesla.charge();
System.out.println("\nAfter charging:\n" + tesla);

System.out.println("\n=== FUEL CAR ===");
System.out.println(ford);
ford.startEngine();
ford.refuel();
System.out.println("\nAfter refueling:\n" + ford);

// Demonstrate LSP
System.out.println("\n=== LSP DEMONSTRATION ===");
IAuto[] vehicles = {tesla, ford};
for (IAuto vehicle : vehicles) {
System.out.println("\nVehicle: " + vehicle.getModel().getFullName());
vehicle.startEngine();

if (vehicle instanceof IElectricCar) {
((IElectricCar) vehicle).charge();
}
if (vehicle instanceof IFuelCar) {
((IFuelCar) vehicle).refuel();
}
}
}
}
this is it take a look if it is good! @reiwa
reiwa
reiwa6mo ago
are your Interfaces in a separate package? You may need to import the package, likepackage Interfaces; if the package is called 'Interfaces'.
OMIDD
OMIDDOP6mo ago
i fixed it thnx i imported tthnx thnx
JavaBot
JavaBot6mo ago
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.

Did you find this page helpful?