I'm writing a program for an assignment that is supposed to output information about vehicles, where Vehicle is the Superclass and Car, Truck and Van are the Subclasses. Our instructor gave us the main method, so I know that issue has to be in the code I wrote for the Subclasses.
I have updated my code given the suggested feedback and have encountered a new error on line 3: No enclosing instance of type AssignmentEX2 is accessible. Must qualify the allocation with an enclosing instance of type AssignmentEX2 (e.g. x.new A() where x is an instance of AssignmentEX2).
public class AssignmentEX2 {
public static void main(String[] args) {
Vehicle vehicle = new Vehicle("5554EAWV3898");
System.out.println(vehicle.toString());
vehicle.rentVehicle();
System.out.println(vehicle.toString());
vehicle.returnVehicle();
System.out.println(vehicle.toString());
System.out.println();
Car car = new Car("6903NMME5853", 4);
System.out.println(car.toString());
car.rentVehicle();
System.out.println(car.toString());
System.out.println();
Truck truck = new Truck("7242OAHT0021", 26, 3);
System.out.println(truck.toString());
truck.rentVehicle();
System.out.println(truck.toString());
System.out.println();
Van van = new Van("5397NQRO4899", 11);
System.out.println(van.toString());
van.rentVehicle();
System.out.println(van.toString());
}
class Vehicle {
String vin;
Boolean rented = false;
public Vehicle(String vin) {
}
public String getVin() {
return vin;
}
public Boolean isRented() {
return rented;
}
public void rentVehicle() {
rented = true;
}
public void returnVehicle() {
rented = false;
}
public String toString() {
return("VIN: " + vin + "\nRented: " + rented );
}
}
class Car extends Vehicle {
int doors;
public Car (String vin, int doors) {
super( vin );
}
public int getDoors() {
return doors;
}
public String toString() {
return("VIN: " + vin + "\nRented: " + rented + "\nDoors: " + doors);
}
}
class Truck extends Vehicle {
int boxSize;
int axles;
public Truck(String vin, int boxSize, int axles) {
super( vin );
}
public int getBoxSize() {
return boxSize;
}
public int getAxles() {
return axles;
}
public String toString() {
return("VIN: " + vin + "\nRented: " + rented + "\nBox Size: " + boxSize + "\nAxles: "
+ axles);
}
}
class Van extends Vehicle {
int seats;
public Van (String vin, int seats) {
super( vin );
}
public int getSeats() {
return seats;
}
public String toString() {
return("VIN: " + vin + "\nRented: " + rented + "\nSeats: " + seats);
}
}
}