中易网

怎么用java做汽车出租管理程序

答案:3  悬赏:0  
解决时间 2021-04-17 18:01
设计一程序,可以管理各种出租汽车并计算其租金, 类之间的关系图如下:
最佳答案

车辆出租管理系统



一、项目功能:设计程序,可以管理各种出租汽车并计算其租金。


说明:程序主要管理货车类Truck 、客车类 Bus、小车类Car三中车辆



二、UML图:







main( )






TestCar









三、源码:


abstract class Vehicle


{


protected String number;//车牌号


protected String type;//车类型


protected double value;//购车价格


protected double rentPrice;//租车单价


protected double rentKilometers;//租车里程数


protected double rent;//租金



public Vehicle(String number,String type,double value,double rentPrice)//设置车牌号、类型、价格、租车单价


{


this.number=number;


this.type=type;


this.value=value;


this.rentPrice=rentPrice;


}



public void setRentKilometers(double rentKilometers)//设置租车里程数


{ this.rentKilometers=rentKilometers;}



public double getRentKilometers()//返回租车里程数


{return rentKilometers;}



public abstract void calcuRent();//计算租金



public double getRent()//返回租金


{return rent;}



public void printBasicInfo()//返回车的基本信息


{


System.out.println("车牌:"+number+"\t车类型:"+type+"\t车价:"+value+"万元"+"\t租车单价:"+rentPrice);



}



public void printOtherInfo()//返回租车的信息


{ System.out.print("租车里程数:"+rentKilometers);


System.out.print("\t租车单价:"+rentPrice);


System.out.println("\t租金:"+rent);


System.out.println();


}



}



class Truck extends Vehicle


{


private double tonnage;//货车的吨位数


public Truck(String number,String type,double value,double rentPrice,double tonnage)


{


super(number,type,value,rentPrice);//调用父类的构造器方法


this.tonnage=tonnage;//对自己的成员变量进行初始化


}


public double getTonnage()


{


return tonnage;


}


public void calcuRent()//计算租金


{ if(tonnage<10) rent=rentPrice*rentKilometers;


else rent=rentPrice*rentKilometers*1.5;


}


public void printOtherInfo()//返回租车的信息


{


System.out.print("货车租吨位:"+tonnage);


System.out.print("\t租车单价:"+rentPrice);


System.out.println("\t租金:"+rent);


System.out.println();


}


}



class Bus extends Vehicle


{


int seats;//客车坐位数


int rentHours;//租车小时


public Bus(String number,String type,double value,double rentPrice,int seats)


{ super(number,type,value,rentPrice);//调用父类的构造器方法


this.seats=seats;


}



public void setRentHours(int rentHours)


{ this.rentHours=rentHours;


}


public int getRentHours()


{ return rentHours;


}


public int getSeats()


{ return seats;


}


public void calcuRent()


{ rentPrice=rentPrice*rentHours;


}


public void printOtherInfo()//返回租车的信息


{


System.out.print("客车租车时间:"+rentHours);


System.out.print("\t租车单价:"+rentPrice);


System.out.println("\t租金:"+rent);


System.out.println();


}


}



class Car extends Vehicle


{


private int rentDays;


public Car(String number,String type,double value,double rentPrice)


{ super(number,type,value,rentPrice); //调用父类的构造器方法


}



public void setRentDays(int rentDays)


{ this.rentDays=rentDays;


}



public int getRentDays()


{ return rentDays;


}


public void calcuRent()


{ rentPrice=rentPrice* rentDays;


}


public void printOtherInfo()//返回租车的信息


{


System.out.print("小车租车天数:"+rentDays);


System.out.print("\t租车单价:"+rentPrice);


System.out.println("\t租金:"+rent);


System.out.println();


}


}




public class TestCar


{


public static void main(String args[])


{


Truck truck1=new Truck("粤B 30234","小车",16,200,15.0);


Bus bus1=new Bus("粤B 30234","小车",16,200,50);


Car car1=new Car("粤B 30234","小车",16,200);


truck1.printBasicInfo();


bus1.printBasicInfo();


car1.printBasicInfo();


}


}


四、运行结果


全部回答

main( )

TestCar

、运行结果

我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
桌面上的迅雷看看的图标不小心被删除了,怎么
找几首好听的歌,要温柔一点的!栋子看好你
求PSP3000金手指软件下载以及使用方法 请了解
长沙汽车南站到永州道县最新时刻表
冬天和女朋友约会 去哪里玩 吃什么啊?
温州市小学生2014"生活中的数学擂台赛"获奖名
在大学里学医的文科人有多少
腰部经络不同会造成赘肉吗 腰部两旁有赘肉怎
没满月的宝宝喂奶粉是按时间喂还是不用按时间
物流信息。重庆市涪陵区任氏物流提货点在哪里
睡觉时磨牙齿怎么办?
有关千古风流人物诗句
有哪些污的话题,越多越好
石家庄54所待遇怎么样?好近吗
以合肥寄圆通快递到安徽利辛县城关镇要几天
推荐资讯
小S老公的详细资料,他有什么背景没?
有没有一种可以美化别人声音的软件,比如很难
丝路英雄冒险需要玩家控制么?
摘抄西游记1-9
杰士派的发蜡和发胶(气雾剂)推荐哈
梦幻西游地府一点体质加多少血上限?
英雄传说IV空之轨迹FC打完最终BOSS的完美存档
我钱汇错银行,那个人如果去那家银行 能取到
中国所有的公司厂家货源阿里巴巴上是不是都有
若短周期的两种元素可以形成化合物A2B3,那+3
n73的导航键怎么换壳?那个壳是怎么弄下来的
焕我生活 面膜怎么样?
手机登qq时,显示手机磁盘不足,清理后重新登
刺客的套装怎么选啊?