I'm currently learning how to code and on my first module final. Before I can move on I must complete the assignment. When I input my code it returns with 1 error. The code is listed below. Can someone tell me what I'm doing wrong and how to fix it? Thank you!
public class Driver extends User {
private Driveable vehicle = new Vehicle();
public Driver() {}//mine
public Driver(Vehicle vehicle, String name, String email){
this();
setVehicle(vehicle);
setName(name);
setEmail(email);
}
public Driveable getVehicle(){
return vehicle;
}
public Drivable setVehicle(){
this.vehicle;
}
public void setVehicle(Vehicle vehicle){
this.vehicle = vehicle;
}
public void drive(){
vehicle.drive();
}
}
Error methods are listed below as well,
^
1 error
class Driver does contain the required methods.
Check class Vehicle getter/setter methods.
Exception in thread "main" java.lang.NoClassDefFoundError: TaxiService
at Test.taxiService(Test.java:56)
at Test.main(Test.java:16)
Caused by: java.lang.ClassNotFoundException: TaxiService
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:352)
at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
... 2 more
CodePudding user response:
I'm also new, so pls forgive any error I make.
emm.. first things first on the third line of code
private Driveable vehicle = new Vehicle();
you should not be giving assignments here, and the Class types also doesn't match
private Driveable vehicle;
is enough.
if you still want to initialize the attribute, do it in the constructor method.
your getter looks fine, but in the first setter, I'm not sure what you want to do by taking no input but to return an object reference.
Note that the vehicle is of type Driveable and it seems you want to use it as Vehicle type in your code after definition, so consider fixing that.