0

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());
        } 

}
Vega
  • 27,856
  • 27
  • 95
  • 103
  • 3
    You need to learn to format your code, i.e. indent the code to show the code structure, greatly improving the readability of the code by us mere humans. – Andreas Jan 20 '19 at 01:13
  • 2
    There are quite a few issues with this code, to the point where it's difficult to know how to help without just rewriting all of your code. Maybe you could reduce the example by removing all the lines that aren't relevant to the error you're getting, so you can focus on one thing at a time? And then be very specific with the error you're getting and where it occurs. – Mark Peters Jan 20 '19 at 05:43
  • Along with @Andreas suggestion to format your code, a very important convention that helps readability is to use `UpperCase` for type names (classes, interfaces, etc) and `lowerCase` for variable and field names. – Mark Peters Jan 20 '19 at 05:46
  • It looks like some of the compilation errors are due to something messing up the line breaks when you copied your code from somewhere to somewhere. There are line breaks in the middle of string literals! Please go through your code (in the Question) and correct these and other formatting problems before you ask us to help you. – Stephen C Jan 20 '19 at 05:48

1 Answers1

1

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

KingMathCS
  • 19
  • 4