被抛出一个愚蠢的括号错误。也不确定如何继续
Being thrown a stupid bracket error. Also unsure on how to continue
所以我有以下 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);
}
}
我收到一个错误,看起来 '('
预计在 SportCar class 的第五行。我不知道为什么会出现此错误,所以我超级卡住了。
此外,我正在尝试在公式中使用马力、重量、最高速度和空气动力学特性来提供消耗值。我不确定我目前所做的工作该往哪里推进 - 任何提示都将不胜感激。
要回答为什么缺少括号,您需要在 public void Aero
之后添加 ()
,如下所示:
public void Aero()
但是,由于它扩展了 Vehicle,您还需要与 Vehicle 的主构造函数中相同的参数 class。
public void Aero(double HP, double Heavy, double TSpeed){
//to-do logic
}
至于创建消耗值,您需要确定三个变量(或 Aero 的 4 个)如何影响它的结果。例如:HP * TSpeed * Heavy
。现在,我不是工程师,我不知道要使用的正确公式。
所以我有以下 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);
}
}
我收到一个错误,看起来 '('
预计在 SportCar class 的第五行。我不知道为什么会出现此错误,所以我超级卡住了。
此外,我正在尝试在公式中使用马力、重量、最高速度和空气动力学特性来提供消耗值。我不确定我目前所做的工作该往哪里推进 - 任何提示都将不胜感激。
要回答为什么缺少括号,您需要在 public void Aero
之后添加 ()
,如下所示:
public void Aero()
但是,由于它扩展了 Vehicle,您还需要与 Vehicle 的主构造函数中相同的参数 class。
public void Aero(double HP, double Heavy, double TSpeed){
//to-do logic
}
至于创建消耗值,您需要确定三个变量(或 Aero 的 4 个)如何影响它的结果。例如:HP * TSpeed * Heavy
。现在,我不是工程师,我不知道要使用的正确公式。