我觉得大概可以这样设计吧?
程序代码:
class vehicle {
//共性,长宽高重,轮数,载员数,类型,主人
float height;
float width;
float length;
float weight;//车重
float load;//载重
int person;//载员数
int wheel;//轮数
int type;//类型
String owner;//主人
//行为
move(){}
moveBack(){}
turn(direct){}
}
enum taxi_status{//未可用,空闲,运营,占用,报废
taxi_unused,
taxi_free,
taxi_running,
taxi_ocupied,
taxi_scrapped
}
class taxi extends vehicle{
//性质
String company;//所属公司
String curLocation;//目前地址
String startLocat;//始发地
String dest;//目的地
taxi_status status;//状态,
Integer distance;//计价路程 ,米
Integer time_span;//计价时长,分钟
Integer start_distance;//起始计费距离
Integer start_time_span;//起始计费时长
double price1;//每公里价格
double price2;//每分钟价格
double payment;
//getters and setters
taxi(){
start_distance = 5;
start_time_span = 60;
price1 = 1.1;
price2 = 0.1;
}
//行为
void loadingPassenger() {//载客,或载客途中
status = taxi_status.taxi_ocupied;
}
void load() {//开始运客
status = taxi_status.taxi_running;
distance = 0; time_span = 0;
//setstartlocation, setDest()
}
void unload() {//下客
status = taxi_status.taxi_free;
//setstartlocation, setDest()
}
void tick() {
//totaltime++; 统计工作时长
if(status == taxi_status.taxi_running) time_span++;//分钟 计算运客时长
}
void moveOn() {//每前进一米执行一次
distance++;
}
double getPayment() {//计算当前费用
return price1 * ((distance - start_distance) > 0 ? (distance - start_distance) : 0) / 1000
+ price2 * ((time_span - start_time_span) > 0 ? (time_span - start_time_span) : 0)
+ price1 * start_distance ;
}
void moveAround(String curLocate) {//时刻记录当前位置, 参数可以是经纬度,或是街道及距离等复杂对象
this.curLocation = curLocate;
}
}