答答租车系统(面向对象综合练习)

Problem Description

各位面向对象的小伙伴们,在学习了面向对象的核心概念——类的封装、继承、多态之后,答答租车系统开始营运了。

请你充分利用面向对象思想,为公司解决智能租车问题,根据客户选定的车型和租车天数,来计算租车费用,最大载客人数,最大载载重量。

公司现有三种车型(客车、皮卡车、货车),每种车都有名称和租金的属性;其中:客车只能载人,货车只能载货,皮卡车是客货两用车,即可以载人,也可以载货。

下面是答答租车公司的可用车型、容量及价目表:
序号     名称     载客量      载货量        租金
                           (人)     (吨)    (元/天)
  1          A            5                                 800
  2          B            5                                 400
  3          C            5                                 800
  4          D            51                             1300
  5          E            55                             1500
  6          F             5            0.45             500
  7         G             5             2.0               450
  8         H                            3                  200
  9          I                             25              1500
 10        J                             35              2000

要求:根据客户输入的所租车型的序号及天数,计算所能乘载的总人数、货物总数量及租车费用总金额。

Input
首行是一个整数:代表要不要租车 1——要租车(程序继续),0——不租车(程序结束);

第二行是一个整数,代表要租车的数量N;

接下来是N行数据,每行2个整数m和n,其中:m表示要租车的编号,n表示租用该车型的天数。

Output
若成功租车,则输出一行数据,数据间有一个空格,含义为:

载客总人数 载货总重量(保留2位小数) 租车金额(整数)

若不租车,则输出: 

0 0.00 0(含义同上)

Example Input
1
2
1 1
2 2
Example Output
15 0.00 1600
Hint
 
Author
import java.text.DecimalFormat;
import java.util.Scanner;
public class Main {
	
	public static void main(String args[ ]) {
		Scanner in =new Scanner(System.in);
		int a = in.nextInt();
		if(a == 0){
			 System.out.printf("0 0.00 0");
			 System.exit(0);
		}
		else{
			Car[] c ={   
                    new KeCar("A",800,5),  
                    new KeCar("B",400,5),  
                    new KeCar("C",800,5),  
                    new KeCar("D",1300,51),  
                    new KeCar("E",1500,55),  
                    new PiCar("F",500,5,0.45),  
                    new PiCar("G",450,5,2.0),  
                    new HuoCar("H",200,3),  
                    new HuoCar("I",1500,25),  
                    new HuoCar("J",2000,35),  
            };  
			int N = in.nextInt();
			int count = 0;
			 int mannedNum = 0;  
             double cargoedNum = 0.00;
             for(int i = 0; i < N; i++){
            	 int j = in.nextInt() - 1;//编号
            	 double day = in.nextDouble();//天数
            	 count += c[j].money*day;
            	 if(j <= 4)
            		 mannedNum += c[j].passenger*day;
            	 else if(j == 5 || j == 6){  
                     mannedNum += c[j].passenger*day;  
                     cargoedNum += c[j].cargo*day;  
                 }  
            	 else
            		 cargoedNum += c[j].cargo*day;
             }
		DecimalFormat two = new DecimalFormat("#0.00");
		System.out.printf(mannedNum+" "+two.format(cargoedNum) +" "+count);
		}
		in.close();
	}
}
class Car{
	public String name;
	public int money;
	public int passenger;
	public double cargo;
}
class KeCar extends Car{
	public KeCar(String newName, int newMoney,int newPassenger ){
		 this.name = newName;  
	        this.money = newMoney;  
	        this.passenger = newPassenger; 
	}
}
class HuoCar extends Car{
	public HuoCar(String newName,int newMoney,double newCargo){
		this.name = newName;  
        this.money = newMoney;  
        this.cargo = newCargo;
	}
}
class PiCar extends Car{
	 public PiCar(String newName,int newMoney,int newPassenger,double newCargo){  
	        this.name = newName;  
	        this.money = newMoney;  
	        this.passenger = newPassenger;  
	        this.cargo = newCargo;            
	    }  
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值