当谈到我缺乏 Java 技能时,我仍然在 HelloWorld。我无法理解这一点来挽救我的生命。我正在编写一个覆盖方法?在我开始尝试完成其余部分之前,我刚刚开始使用我学校提供的代码,并且我已经遇到了我什至无法开始考虑如何纠正的错误。任何帮助都将不胜感激。我只是想让这个错误消失,这样我就可以创建一些新的:) 下面是代码:
public class Vehicle
public static void main (String [] args)}
{
private boolean moving; // whether or not the vehicle
private double speed;
private char bearing;
('N','E','S', or 'W')
public Vehicle(){ // Vehicle class no-arg constructor
moving = false; // assume not moving
speed = 0.0; // not moving
bearing = 'N'; // assume 'N'orth
System.out.println("Created a vehicle (no-arg)");
}
public Vehicle (double initialSpeed) // Vehicle 1-arg constructor
bearing = 'W';
speed = initialSpeed;
if (speed > 0.0)
{
moving = true;
}
System.out.println("Created a vehicle (1-arg)");
public Vehicle (double initialSpeed, char initialBearing) // Vehicle 2-arg constructor
bearing = initialBearing;
speed = initialSpeed;
if (speed > 0.0){
moving = true;
}
System.out.println("Created a vehicle (2-arg)");
public void start(double initialSpeed, char initialBearing){
moving = true;
if (initialSpeed >= 5.0 && initialSpeed <= 20.0){
speed = initialSpeed; // valid expected range
} else if (initialSpeed >= 0.0 && initialSpeed < 5.0){
speed = 5.0; // minimum
} else if (initialSpeed < 0.0){
speed = 0.0; // assume no movement
moving = false;
} else if (initialSpeed > 20.0){
speed = 20.0; // maximum allowed
}
switch(initialBearing){
case 'N':
bearing = initialBearing;
break;
case 'E':
bearing = initialBearing;
break;
case 'S':
bearing = initialBearing;
break;
case 'W':
bearing = initialBearing;
default:
System.out.println("invalid bearing " +
initialBearing +
" set to N"); // additional user notification
bearing = 'N';
}
public double getSpeed() { // get and return current speed in mph
return speed;
}
public void setSpeed(double newSpeed){ // set new speed in mph
speed = newSpeed;
}
/**
*
* @return
*/
public char getBearing(){
return bearing;
}
public void speedUp(double mphSteps, int numSteps){
int counter = 0;
while (counter < numSteps)
speed += mphSteps;
System.out.println("counter= " + counter + ", " +
this.toString());
counter++;
}
public String toString(){
return "From toString(): speed= " + getSpeed() +
" mph and bearing= " + getBearing();
}
}
public class Car extends Vehicle{
private String color;
private int doors;
private double hp;
public Car(String carColor, int numDoors,
double horsePower, double
startingSpeed)
{
super(startingSpeed);
color = carColor;
doors = numDoors;
hp = horsePower;
System.out.println("Created a car");
}
public String getColor()
{
return color;
}
public int getDoors()
{
return doors;
}
public double getHp()
{
return hp;
}
public String toString()
{
return "From Car toString(): color= " + getColor() +
" doors= " + getDoors() +
" hp= " + getHp() +
" speed= " + getSpeed() +
" mph and bearing= " + getBearing();}
}
public class TestCar2
{
public static void main(String[] args)
{
Car myCar2 = new Car("blue", 4, 300., 10.0);
System.out.println(myCar2.toString());
myCar2.speedUp(5.0, 2);
}
}
请拜托,谢谢你的帮助!