QwerkyGeek
QwerkyGeek

Reputation: 1

How to avoid an 'Interface Abstract class error'?

Here is my main class for this and I keep getting an error saying that

The abstract class has not been overridden

I have tried making the car class abstract and not overridding, I have tried to override and using an abstract class, without success. I just don't know what I'm doing wrong.

public abstract class Car implements CarbonFootprint {


    private double Car;
    private double MilesDrivenPerYear;
    private double MilesPerGallon;


    //Constructor
    public Car(double MilesDrivenPerYear, double MilesPerGallon) {
        this.MilesDrivenPerYear = MilesDrivenPerYear;
        this.MilesPerGallon = MilesPerGallon;
    }

    //Return miles driven per year
    public double getMilesDrivenPerYear() { return MilesDrivenPerYear; }

    //Return Miles per Gallon
    public double getMilesPerGallon() { return MilesPerGallon; }

    public void setMilesDrivenPerYear(double MilesDrivenPerYear) {
        this.MilesDrivenPerYear = MilesDrivenPerYear;
    }

    public void  setMilesPerGallon(double MilesPerGallon) {
        this.MilesPerGallon = MilesPerGallon;
    }

    @Override
    public String toString() {
        return String.format("%s: %n%s: %s", "Car", "Miles 
    Driven: ",getMilesDrivenPerYear(), "Miles per 
    Gallon; ",getMilesPerGallon());
    }
    public abstract double  Car();

    public double getCarbonFootprint() {
        return Car = getMilesDrivenPerYear() / getMilesPerGallon() * 19.82;

    }
}
//end car class'

public class CarbonFootprintTest {




    public static void main(String[] args) {

        ArrayList FootprintList = new ArrayList();

        Car Footprint1 = new Car(25, 36);

        FootprintList.add(Footprint1);

        Building Footprint2 = new Building(78, 78);
        FootprintList.add(Footprint2);


        Bicycle Footprint3 = new Bicycle(90);
        FootprintList.add(Footprint3);


        System.out.println("Shaina Carbon Footprint Calculator");

        for (Object Footprint: FootprintList) {
            System.out.printf("Miles Driven:");
            System.out.printf("Car Carbon Footprint",
                Footprint2.getCarbonFootprint());
        } 

}

Upvotes: 0

Views: 169

Answers (1)

KingMathCS
KingMathCS

Reputation: 19

Car is an Abstract class, so you cannot create an instance of it. You should probably make another class that extends the Car class. See this answer for information:

https://stackoverflow.com/a/30317092/7260643

Upvotes: 1

Related Questions