收藏 分销(赏)

汽车租赁系统-java.doc

上传人:天**** 文档编号:4311584 上传时间:2024-09-05 格式:DOC 页数:4 大小:19.92KB 下载积分:5 金币
下载 相关 举报
汽车租赁系统-java.doc_第1页
第1页 / 共4页
汽车租赁系统-java.doc_第2页
第2页 / 共4页


点击查看更多>>
资源描述
实现租车汽车租赁系统,不同车型日租金情况如表7-1所示; 车型及日期 轿车 客车 车型 别克Gl8 宝马750 别克凯越 <=19座 >19座 日租金(元/天) 750 600 500 800 1200 编程实现计算不同车型不同天数的租赁费用。 package zuche; public abstract class MotoVehicle { private String no; private String brand; int []fee= { 750,600,500,800,1200}; public MotoVehicle() {} public MotoVehicle(String no,String brand) { this.no=no; this.brand=brand; } public String getNo() { return no; } public String getBrand() { return brand; } public void setBrand(String brand) { this.brand=brand; } public void setNo(String no) { this.no=no; } public void printInfo() { System.out.println("***汽车的信息***"+"\n汽车品牌"+this.brand+"\n车牌号"+this.no); } public abstract void calRent(int days) ; } package zuche; public class Car extends MotoVehicle { private String type; //String [] type1= {"别克凯越","宝马730","别克凯越","中小客车(19座以内)","大型客车(19座以上)"}; public Car() {} public Car(String no,String brand,String type) { super(no,brand); this.type=type; } public String getType() { return type; } public void setType(String type) { this.type=type; } public void printInfo() { //super.printInfo();//调用父类的构造方法,子类不能直接继承父类的构造方法; System.out.println("***汽车的信息***"+"\n汽车品牌"+getBrand()+"\n型号"+this.type+"\n车牌号"+getNo()); } public void calRent(int days) { int rent=0; if("宝马".equals(getBrand())) { rent=days*600; } else if("别克".equals(getBrand())&&"gl8".equals(this.type)) {rent=days*750;} else {rent=days*500;} System.out.println(" 你的租车费用为"+rent+"元"); } } package zuche; public class Bus extends MotoVehicle{ private int seatCount; public Bus() {} public int getSeatCount() { return seatCount; } public void setSeatCount(int seatCount) { this.seatCount=seatCount; } public void printInfo() { System.out.println("***汽车的信息***"+"\n车牌号"+getNo()+"\n客车座位数"+this.seatCount+"座"); } public void calRent(int days) { int rent=0; if(seatCount<=19) {rent=days*800; }else { rent=days*1200; } System.out.println("你的租车费用为"+rent+"元"); } } package zuche; import java.util.Scanner; public class TestRent { public static void main(String[]args) { Scanner input=new Scanner(System.in); //int carType; String answer; int day=0; Car c=new Car(); Bus b=new Bus(); System.out.println("**欢迎光临西树东花租车**"); System.out.println("***********************"); int random=(int)(Math.random()*89999+10000);//random()的取值范围为[0,1); do {System.out.println("轿车请选:1"+"\n货车请选:2"); c.setNo("黑A\t"+random); if(input.nextInt()==1) { System.out.println("请输入汽车的品牌(1.宝马、2.别克)"); switch(input.nextInt()) { case 1: c.setBrand("宝马"); c.setType("730"); c. printInfo(); System.out.println("请输入租车天数"); c.calRent(input.nextInt()); break; case 2: System.out.println("请选择别克车的类型:gl8、凯越"); if(input.nextInt()==1){ c.setBrand("别克"); c.setType("gl8"); c. printInfo(); System.out.println("请输入租车天数"); c.calRent(input.nextInt()); }else { c.setBrand("别克"); c.setType("凯越"); c. printInfo(); System.out.println("请输入租车天数"); c.calRent(input.nextInt()); } }} else {System.out.println("请选择客车的座位数:19座下/19座以上"); b.setNo("黑A"+random); switch(input.nextInt()) { case 1:b.setSeatCount(17); b.printInfo(); System.out.println("请输入租车天数"); b.calRent(input.nextInt()); break; case 2: b.setSeatCount(21); b.printInfo(); System.out.println("请输入租车天数"); b.calRent(input.nextInt()); break; }} System.out.println("是否继续租车 y/n"); answer=input.next(); } while( answer.equals("y")); if(answer.equals("n")) { System.out.println("欢迎下次光临");}}}
展开阅读全文

开通  VIP会员、SVIP会员  优惠大
下载10份以上建议开通VIP会员
下载20份以上建议开通SVIP会员


开通VIP      成为共赢上传

当前位置:首页 > 包罗万象 > 大杂烩

移动网页_全站_页脚广告1

关于我们      便捷服务       自信AI       AI导航        抽奖活动

©2010-2026 宁波自信网络信息技术有限公司  版权所有

客服电话:0574-28810668  投诉电话:18658249818

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :微信公众号    抖音    微博    LOFTER 

客服