Как избежать «ошибки абстрактного класса интерфейса»? - PullRequest
0 голосов
/ 20 января 2019

Вот мой основной класс для этого, и я получаю сообщение об ошибке, говорящее, что

Абстрактный класс не был переопределен

Я попытался сделать класс автомобилей абстрактным и не переопределяющим, я попытался переопределить и использовать абстрактный класс, но безуспешно. Я просто не знаю, что я делаю не так.

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

}

1 Ответ

0 голосов
/ 20 января 2019

Car - это абстрактный класс, поэтому вы не можете создать его экземпляр. Вы, вероятно, должны сделать еще один класс, который расширяет класс автомобилей. Смотрите этот ответ для информации:

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

...