public class User {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Vehicle car1,car2;
car1 = new Vehicle();
car2 = new Vehicle();
car1.setPower(128);
car2.setPower(76);
System.out.println("car1的功率是:"+car1.getpower());
System.out.println("car2的功率是:"+car2.getpower());
car1.speedUp(80);
car2.speedUp(80);
System.out.println("car1目前的速度是:"+car1.getspeed());
System.out.println("car2目前的速度是:"+car2.getspeed());
car1.speedDown(10);
car2.speedDown(20);
System.out.println("car1目前的速度是:"+car1.getspeed());
System.out.println("car2目前的速度是:"+car2.getspeed());
}
}
public class Vehicle {
double speed;
int power;
Vehicle(){
speed=0.0;
power=0;
}
void speedUp(int s){
speed=speed+s;
}
void speedDown(int d){
speed=speed-d;
}
double getspeed(){
return speed;
}
void setPower(int p){
power=p;
}
int getpower(){
return power;
}
}
chapter3
最新推荐文章于 2024-01-20 10:45:38 发布