在主函数中调用Scanner函数出错?求各位给看一下
代码如下:public class JavaApplication5 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
Scanner input = new Scanner(System.in);
Tank tank1 = new Tank();
Tank tank2 = new Tank();
tank1.setBulletAmount(10);
tank2.setBulletAmount(1);
double tank1.speedUp =input.nextDouble();
double tank2.speedUp =input.nextDouble(); 这里ide提示我需要‘;’我的分号是英文的而且写了啊,下面的一句一样是这个错误,不明白为什么错了,求各位指点一下。
tank1.fire();
tank2.fire();
System.out.println("tank1目前的速度:"+tank1.getSpeed());
System.out.println("tank2目前的速度:"+tank2.getSpeed());
System.out.println("tank1现有炮弹数量:"+tank1.getBulletAmount());
System.out.println("tank2现有炮弹数量:"+tank2.getBulletAmount());
double tank1.speedUp =input.nextDouble();
double tank2.speedUp =input.nextDouble();
tank1.fire();
tank2.fire();
System.out.println("tank1目前的速度:"+tank1.getSpeed());
System.out.println("tank2目前的速度:"+tank2.getSpeed());
System.out.println("tank1的炮弹数量:"+tank1.getBulletAmount());
System.out.println("tank2的炮弹数量:"+tank2.getBulletAmount());
}
}
class Tank{
double speed;
int bulletAmount;
void speedUp(int s){
speed = speed + s; }
void speedDown(int d){
if(speed-d >= 0)
speed = speed -d;
else
speed = 0; }
void setBulletAmount(int m){
bulletAmount = m; }
int getBulletAmount(){
return bulletAmount; }
double getSpeed(){
return speed; }
void fire(){
if(bulletAmount >= 1){
bulletAmount = bulletAmount -1;
System.out.println("打出一发炮弹"); }
else {
System.out.println("没有炮弹了"); }
}