汽车租赁系统
需求说明:某汽车租赁公司出租多种轿车和客车,出租费⽤以⽇为单位计算。出租车型及信息如下表所⽰。
编写程序实现汽车租赁业务,效果如下图所⽰。
新增“卡车”车型。新购置了卡车,根据吨位,租⾦每吨每天50元,在作
业1的基础上对系统进⾏扩展,计算汽车租赁的总租⾦,实现效果如下图所⽰。
packageDayOptional;
/**
*@authoryzh
*2021-01-1213:59
*@汽车类
*/
publicclassChe{
privateStringbrand;//品牌
privateStringcarNum;//车牌
privatedoublemoney;//⽇租⾦
privateintday;//租赁天数
privatefloatdiscount;//折扣
publicChe(Stringbrand,StringcarNum,doublemoney){
=brand;
=carNum;
=money;
}
publicStringgetBrand(){
returnbrand;
returnbrand;
}
publicvoidtBrand(Stringbrand){
=brand;
}
publicStringgetCarNum(){
returncarNum;
}
publicvoidtCarNum(StringcarNum){
=carNum;
}
publicdoublegetMoney(){
returnmoney;
}
publicvoidtMoney(doublemoney){
=money;
}
publicintgetDay(){
returnday;
}
publicvoidtDay(intday){
=day;
}
//把返回值设置为1不打折,⼦类中如不满⾜折扣条件,执⾏count()
publicfloatgetDiscount(){
return1;
}
//让折扣变成只读属性
/*publicvoidtDiscount(floatdiscount){
nt=discount;
}*/
@Override
publicStringtoString(){
return"Che{"+
"brand='"+brand+'''+
",carNum='"+carNum+'''+
",money="+money+
",day="+day+
",discount="+discount+
'}';
}
//计算租⾦的⽅法:
publicdoublecalRent(){
//租⾦:租赁天数*⽇租⾦*折扣
returngetDay()*getMoney()*getDiscount();
}
publicdoublenoDiscount(){
returngetDay()*getMoney();
}
}
packageDayOptional;
/**
*@authoryzh
*2021-01-1214:03
*轿车类
*/
*/
publicclassJiaoCheextendsChe{
privateStringtype;//车型
publicJiaoChe(Stringbrand,StringcarNum,doublemoney,Stringtype){
super(brand,carNum,money);
=type;
}
publicStringgetType(){
returntype;
}
publicvoidtType(Stringtype){
=type;
}
//重写⽗类getDiscount⽅法,提供轿车特有的折扣算法,天数判定顺序从⼤到⼩
@Override
publicfloatgetDiscount(){
if(getDay()>150){
return0.7f;
}elif(getDay()>30){
return0.8f;
}elif(getDay()>7){
return0.9f;
}
count();
}
@Override
publicStringtoString(){
ng();
}
@Override
publicdoublecalRent(){
t();
}
}
packageDayOptional;
/**
*@authoryzh
*2021-01-1214:04
*客车类
*/
publicclassKeCheextendsChe{
privateintatNum;//车座位数
publicKeChe(Stringbrand,StringcarNum,doublemoney,intatNum){
super(brand,carNum,money);
m=atNum;
}
publicintgetSeatNum(){
returnatNum;
}
publicvoidtSeatNum(intatNum){
m=atNum;
}
//提供客车特有折扣算法
@Override
publicfloatgetDiscount(){
if(getDay()>=150){
return0.6f;
return0.6f;
}elif(getDay()>=30){
return0.7f;
}elif(getDay()>=7){
return0.8f;
}elif(getDay()>=3){
return0.9f;
}
count();
}
@Override
publicStringtoString(){
ng();
}
@Override
publicdoublecalRent(){
t();
}
}
packageDayOptional;
/**
*@authoryzh
*2021-01-1317:45
*卡车类
*/
publicclassTruckextendsChe{
privateinttonnage;
publicTruck(Stringbrand,StringcarNum,doublemoney,inttonnage){
super(brand,carNum,money);
e=tonnage;
}
publicintgetTonnage(){
returntonnage;
}
publicvoidtTonnage(inttonnage){
e=tonnage;
}
@Override
publicfloatgetDiscount(){
count();
}
@Override
publicdoublecalRent(){
returngetDay()*getMoney()*getDiscount()*getTonnage();
}
@Override
publicdoublenoDiscount(){
ount()*getTonnage();
}
}
packageDayOptional;
/**
*@authoryzh
*2021-01-1320:13
*汽车管理类
*/
publicclassCheService{
publicclassCheService{
publicChefindChe(Che[]ches,StringfindBrand,StringfindType,intfindSeatNum,intfindTonnage){
for(Cheche:ches){
if(cheinstanceofJiaoChe){
if((nd())&&(((JiaoChe)che).getType())){
returnche;
}
}elif(cheinstanceofKeChe){
if((nd())&&findSeatNum==((KeChe)che).getSeatNum()){
returnche;
}
}elif(cheinstanceofTruck){
if((nd())&&findTonnage==((Truck)che).getTonnage()){
returnche;
}
}
}
returnnull;
}
}
packageDayOptional;
r;
/**
*@authoryzh
*2021-01-1215:05
*测试类
*/
publicclassTestOne{
publicstaticvoidmain(String[]args){
CheServicervice=newCheService();
Scannerinput=newScanner();
Che[]ches={
newJiaoChe("宝马","京NY28588",800,"X6"),
newJiaoChe("宝马","京CNY3284",600,"550i"),
newJiaoChe("别克","京NT37465",300,"林荫⼤道"),
newJiaoChe("别克","京NT96968",600,"GL8"),
newKeChe("⾦杯","京6566754",800,16),
newKeChe("⾦龙","京8696997",800,16),
newKeChe("⾦杯","京9696996",1500,34),
newKeChe("⾦龙","京8696998",1500,34),
newTruck("⼀汽解放","京P225797",50,1),
newTruck("⼀汽解放","京P116808",50,2),
newTruck("重庆红岩","京P007919",50,1),
newTruck("重庆红岩","京P118020",50,2),
};
//储存租赁的车辆数组
Che[]rentChes=newChe[10];
//所有车辆总租赁费⽤
doublesumCost=0;
//折扣总⾦额
doublesumDiscount=0;
do{
n("**********欢迎光临腾飞汽车租赁公司**********");
n("1、轿车2、客车3、卡车");
n("请选择您要租赁的汽车类型:");
intlect=t();
StringfindType=null;//假设客户选择的汽车型号不存在
StringfindBrand=null;//假设客户选择的汽车品牌不存在
intatNum=0;//假设客户选择的客车座位数
inttonnage=0;//假设客户选择的卡车吨位
intbrandId;
switch(lect){
ca1:
n("请您选择要租赁的轿车品牌:1、宝马2、别克");
brandId=t();
brandId=t();
if(brandId==1){
findBrand="宝马";
n("型号:1、X62、550i");
}elif(brandId==2){
findBrand="别克";
n("型号:1、林荫⼤道2、GL8");
}el{
n("您选择的轿车品牌暂时没有");
}
n("请您选择型号:");
inttypeId=t();
if(typeId==1){
findType=brandId==1?"X6":"林荫⼤道";
}elif(typeId==2){
findType=brandId==1?"550i":"GL8";
}el{
n("您选择的轿车型号暂时没有");
}
break;
ca2:
n("请您选择要租赁的客车品牌:1、⾦杯2、⾦龙");
brandId=t();
if(brandId==1){
findBrand="⾦杯";
}elif(brandId==2){
findBrand="⾦龙";
}el{
n("您选择的客车品牌暂时没有");
}
n("座位数量:1、16座2、34座");
n("请您选择座位数量:");
intatNumId=t();
if(atNumId==1){
atNum=16;
}elif(atNumId==2){
atNum=34;
}el{
n("您选择的客车座位数暂时没有");
}
break;
ca3:
n("请您选择要租赁的卡车品牌:1、⼀汽解放2、重庆红岩");
brandId=t();
if(brandId==1){
findBrand="⼀汽解放";
}elif(brandId==2){
findBrand="重庆红岩";
}el{
n("您选择的卡车品牌暂时没有");
}
n("吨位:1、1吨2、2吨");
n("请您选择吨位:");
inttonnageId=t();
if(tonnageId==1){
tonnage=1;
}elif(tonnageId==2){
tonnage=2;
}el{
n("您选择的卡车吨位暂时没有");
}
break;
default:
n("本公司暂⽆该类型汽车");
break;
}
}
CheresultChe=e(ches,findBrand,findType,atNum,tonnage);
if(resultChe!=null){
("请输⼊您要租赁的天数:");
intdays=t();
n("分配给您得汽车号牌是:"+Num());
(days);
doubletotalCost=t();
sumCost+=totalCost;//总费⽤
n("您需要⽀付的租赁费⽤为:"+totalCost+"元");
n("本次租赁折扣:"+count()+
",原价:"+ount()+"元"+
",帮您节省"+(ount()-t()));
sumDiscount+=(ount()-t());//总节省⾦额
}
//录⼊租赁车辆信息:
for(inti=0;i<;i++){
if(rentChes[i]==null){
rentChes[i]=resultChe;
break;
}
}
for(CherentCh:rentChes){
if(rentCh!=null){
("您租赁的车辆信息如下:"+"品牌:"+nd()+
",车牌:"+Num()+",租期:"+()+"天"+
",租⾦:"+t()+"元");
if(rentChinstanceofJiaoChe){
n(",型号:"+((JiaoChe)rentCh).getType());
}elif(rentChinstanceofKeChe){
n(",座位:"+((KeChe)rentCh).getSeatNum());
}el{
n(",吨位:"+((Truck)rentCh).getTonnage());
}
}
}
n("所有车辆实付费⽤:"+sumCost+"元"+",总计优惠:"+sumDiscount+"元!");
n("是否继续租车,按0继续,按任意其它数字退出");
intbutton=t();
if(button!=0){
n("系统退出,欢迎下次使⽤");
return;
}
}while(true);
}
}
本文发布于:2022-11-26 07:20:46,感谢您对本站的认可!
本文链接:http://www.wtabcd.cn/fanwen/fan/90/23645.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |