测试类: package com.ft; import java.util.Scanner; public class Kongzhi { public static void main(String[] args) { // TODO Auto-generated method stub //name carNum perNum/loadNum price Car car1 = new Huoche("货车1号(1)", 4, 100,300); Car car2 = new Huoche("货车2号(2)", 3, 150,500); Car car3 = new Jiaoche("客车1号(3)", 5, 5,400); Car car4 = new Jiaoche("客车2号(4)", 20, 30,600); Car car5 = new Pika("皮卡车1号(5)", 10,10,100,1000); Car car6 = new Pika("皮卡车2号(6)",5,15,500, 1500); Car[] cars=new Car[6]; cars[0]=car1; cars[1]=car2; cars[2]=car3; cars[3]=car4; cars[4]=car5; cars[5]=car6; while(true){ System.out.println("*************欢迎使用答答租车系统!*****************"); Scanner sc = new Scanner(System.in); System.out.println("租车请按1,退出请按2"); int num= sc.nextInt(); if(num==1) { System.out.println("我们拥有的所有车辆信息为:"); for(int i=0;i<cars.length;i++) { cars[i].show(); } System.out.println("请输入您想要租车的类型"); Scanner scan=new Scanner(System.in); int a=scan.nextInt(); System.out.println("您选择租赁第"+a+"种类型的车"); if(cars[a-1].carNum>0) { System.out.println( " 当前此类型车可租赁,剩余"+cars[a-1].carNum+"辆~具体信息为"); cars[a-1].show(); } else if(cars[a-1].carNum<1) { System.out.println("当前此车暂时没有剩余车辆"); break; } else { System.out.println("输入错误,程序结束"); break; } System.out.println("请输入租车天数,租车数量"); int[] b=new int[2]; int m=0; for(;m<2;m++) { b[m]=scan.nextInt(); } System.out.println("您总共需要支付:"+cars[a-1].price*b[0]*b[1]+"元~"); System.out.println("感谢您的使用,期待您的下次光临!"); break; } else if(num==2){ System.out.println("感谢您的使用,再见!"); break ; } else { System.out.println("请按提示进行输入!"); } } } }
Car主类 package com.ft; public class Car { //品牌 public String name; //可租数量 public int carNum; //载客量 public int perNum; //载货量 public int loadNum; //租金 public int price; public void show() { } }
轿车子类: package com.ft; public class Jiaoche extends Car { public Jiaoche(String name,int carNum,int perNum,int rent) { this.name=name; this.carNum =carNum; this.perNum=perNum; this.price=rent; } public void show() { System.out.println(name+" "+price+"元/天"+"载客量/人:"+perNum); } }
货车子类: package com.ft; public class Huoche extends Car { public Huoche(String name,int carNum,int loadNum,int rent) { this.name=name; this.loadNum =loadNum; this.carNum=carNum; this.price=rent; } public void show(){ System.out.println ( name + " " + price + "元/天 " +"载货/吨:" + loadNum );} }
皮卡子类: package com.ft; public class Pika extends Car { public Pika(String name,int carNum,int perNum,int loadNum,int rent) { this.name=name; this.carNum =carNum; this.perNum=perNum; this.price=rent; this.loadNum=loadNum; } public void show() { System.out.println(name+" "+price+"元/天"+"载客量/人:"+perNum+"载货量/吨:"+loadNum); } }
点击查看更多内容
1人点赞
评论
共同学习,写下你的评论
评论加载中...
作者其他优质文章
正在加载中
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦