So I have the following classes:
public class Vehicle
{
private double horsepower;
private double weight;
private double topspeed;
public Vehicle (double HP, double Heavy, double TSpeed)
{
horsepower = HP;
weight = Heavy;
topspeed = TSpeed;
}
//public double Consumption
}
.
public class SportCar extends Vehicle
{
public double aerodynamic;
public void Aero
{
aerodynamic = 0.5;
}
}
.
public class TestConsumption
{
public static void main(String[] args)
{
Vehicle first = new Vehicle(200, 1500, 220);
Vehicle second = new Vehicle(100, 1000, 170);
Vehicle third = new Vehicle(135, 1100.2, 173);
}
}
And I'm being given an error that looks says '('
expected in the fifth line of the SportCar class. I have no idea why its giving this error so I'm super stuck.
Additionally, I'm trying to use the horsepower, weight, topspeed and aerodynamic properties in a formula to provide a consumption value. I'm not sure where to go forward with what I've done so far - any tips would be appreciated.
To answer why you are getting the missing bracket, you need to add ()
after your public void Aero
like so:
public void Aero()
However, since it extends Vehicle, you would also require the same parameters as in your main constructor for your Vehicle class.
public void Aero(double HP, double Heavy, double TSpeed){
//to-do logic
}
As for creating a consumption value, you would need to identify how the three variables (or 4 for Aero), affect the outcome of it. For example: HP * TSpeed * Heavy
. Now, I'm no engineer and I would not know the correct formula to use.