-3

So I am using the superclass Vehicle and subclass Van. The Van subclass inherits horsepower, weight, and aerodynamics from the superclass. I have also defined a new instance variable in Van called carryweight. When I try to run TestAcceleration.java I get this error:

java error

Here is the code:

VEHICLE SUPERCLASS

public class Vehicle
{
public double horsepower;
public double aerodynamics;
public double weight;

public Vehicle(double hp, double w, double ad)
{
    horsepower = hp;
weight = w; 
aerodynamics = ad;
}

public double getHorsepower()
{
    return horsepower;
}

public double getAerodynamics()
{
    return aerodynamics;
}

public double getWeight()
{
    return weight;
}

public double acceleration()
{
double calcAccel = (100/horsepower)*aerodynamics*weight/100;
double roundAccel = Math.round(calcAccel * 100.0) / 100.0;
return roundAccel;
}
}

VAN SUBCLASS

public class Van extends Vehicle
{
public double carryweight;

public Van(double hp, double w, double ad, double cw)
{
super(hp, w, ad, cw);
carryweight = cw;
}

public double getCarryweight()
{
    return carryweight;
}

public double acceleration()
{
double calcAccel = (100/horsepower)*(aerodynamics/2)*weight/100;
double roundAccel = Math.round(calcAccel * 100.0) / 100.0;
return roundAccel;
}
}

TESTACCELERATION CLASS

public class TestAcceleration
{
public static void main (String[] args)
{

Vehicle car1 = new Van(100, 3500, 0.9, 160.4);

System.out.println(car1.acceleration());

}
}
  • Hello and welcome to StackOverflow! Your question will most likely be closed or even deleted shortly. To prevent this from happening in the future, please [take the tour](https://stackoverflow.com/tour) and [take a look at the help center](https://stackoverflow.com/help). In particular, [make yourself famlilar as to what is regarded as on-topic around here](https://stackoverflow.com/help/on-topic). You may also want to look at [this question asking how much research is expected](https://meta.stackoverflow.com/questions/261592/how-much-research-effort-is-expected-of-stack-overflow-users). – Turing85 Feb 05 '18 at 13:00
  • Your parameters don't match, you probably meant `super(hp, w, ad);` . – Arnaud Feb 05 '18 at 13:01
  • Your code shouldn't even compile, as no constructor with 4 arguments is to be found in the `Vehicule` class – DamCx Feb 05 '18 at 13:03
  • 1
    Please understand that this community is not programming school where tutors help you with super basic problems. The idea is that do **serious** research prior posting questions. But it seems you didn't do that. You dont even understand that you have a **compiler** error. You are **not** running your classes. The screen shot (which you should not have used - as error messages are **text** and should be coming as **text** in your question) **clearly** tells you that the different parts of your source code simply dont "match up". – GhostCat Feb 05 '18 at 13:05
  • @DamCx Yes, that's what OP is asking here. – Tom Feb 05 '18 at 13:07
  • 1
    @Tom No, actually he claims that he gets this error when *running* stuff. Unfortunately this newbie is still at a level where is not able to even correctly communicate his problem. – GhostCat Feb 05 '18 at 13:08
  • @GhostCat And when people would actually look that the linked picture, they would see that OP is "running" the compiler to compile TestAcceleration.java. – Tom Feb 05 '18 at 13:09
  • @Tom Pretty often, people here think that linking to a screen shot of *text* is a nogo anyway. So they most often will not follow that link, but click that "down arrow" icon instead ;-) – GhostCat Feb 05 '18 at 13:24
  • @GhostCat That's fine, but one shouldn't claim what OP should actually get, then they don't even know that OP is currently asking about. – Tom Feb 05 '18 at 13:46

3 Answers3

2

The super you are calling in the subclass calls the constructor of your parent class, in this case Vehicle so you must use the paremeters of it's constructor which are 3 and not 4 as you typed.

Parent class constructor

public Vehicle(double hp, double w, double ad)

Your code:

public Van(double hp, double w, double ad, double cw)
{
    super(hp, w, ad, cw); // this is wrong, you should call with only 3 parameters, there is no CW in your parent class. The call should be super(hp, w, ad);
    carryweight = cw;
}
Kennedy Oliveira
  • 2,141
  • 2
  • 20
  • 25
0

You have passed four arguments to Vehicle constructor in Van subclass.

super(hp, w, ad, cw);

Just remove cw from constructor and it will be ok.

Hani
  • 21
  • 4
0

In the constructor of your subclass you call:

super(hp, w, ad, cw);

But the constructor of your superclass has only three arguments. Remove the last argument and your code will compile.

erdeanmich
  • 33
  • 3