Java这题怎么做
看看这个满足吗?
Vehicle类代码:
public class Vehiclo {
private double speed;
private int power;
public double getSpeed() {
return speed;
}
public int getPower() {
return power;
}
public void setPower(int power) {
this.power = power;
}
}
User类:
import java.util.Scanner;
public class User {
public static void main(String args[]){
int powerSet=0;
int flag=0;
do{
Scanner in = new Scanner(System.in);
System.out.println("请设置车的功率(int):");
int powerSet1=in.nextInt();
Vehiclo car=new Vehiclo();
car.setPower(powerSet1);
if(powerSet1>powerSet){
speedUp(powerSet,powerSet1);
}else if (powerSet==powerSet1) {
System.out.println("系统功率和当前车速匹配!");
}else {
speedDown(powerSet,powerSet1);
}
powerSet=powerSet1;
System.out.println("退出请输入数字0,重新设置功率请输入数字1");
flag=in.nextInt();
}while(flag==1);
}
public static void speedUp(int powerNow,int powerGoal){
System.out.println("当前车速为:"+powerNow);
System.out.println("目标功率为:"+powerGoal);
System.out.println("汽车正在加速");
}
public static void speedDown(int powerNow,int powerGoal){
System.out.println("当前车速为:"+powerNow);
System.out.println("目标功率为:"+powerGoal);
System.out.println("汽车正在减速");
}
}
结果: