答答租车

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

Time Limit: 1000MS Memory Limit: 65536KB

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
 
 
//数组的赋值可以在定义的时候赋值,代码量可减少
import java.util.*;


public class Main {

	public static void main(String[] args) {
       Scanner reader=new Scanner(System.in);
       int n=reader.nextInt();
        if(n==1){
        	int num=reader.nextInt();
        	int a [] = new int [10];
        	int b[] = new int [10];
        	 double c[] = new double [10];
        	 int[] d = new int [10];
        	 for(int i=0;i<10;i++){
     		    a[i]=i+1;
     		    b[i]=0;
     		   c[i]=0;
     		   d[i]=0;
     		}
     		b[1]=b[0]=b[2]=b[5]=b[6]=5;
     		b[3]=51;
     		b[4]=55;
     	
     		c[5]=0.45;
     		c[6]=2.0;c[7]=3;
     		c[8]=25;c[9]=35;
     		d[0]=800;
     		d[1]=400;d[2]=800;d[3]=1300;
     		d[4]=1500;d[5]=500;
     		d[6]=450;d[7]=200;d[8]=1500;d[9]=2000;
           Da z=new Da(a,b,c,d);
           int p[]=new int[10];
           int k[]=new int [10];
           for(int i=0;i<num;i++)
           {
        	   p[i]=reader.nextInt();
        	   k[i]=reader.nextInt();
           }
           
           z.add(num, p, k);
        }
        else {
        	System.out.println("0 0.00 0");
        }

}
}
class Da   {
	public int[] a;
	public int b[];
	public double c[];
	public int d[];
	
	public Da(int[] a2, int[] b2, double[] c2, int[] d2) {
		// TODO Auto-generated constructor stub
		this.a=a2;
		this.b=b2;
		this.c=c2;
		this.d=d2;
	}
	public void add(int n,int p[],int k[]){
		int sum1=0;
		double sum2=0;
		int sum3=0;
		
		int j=0;
		for(j=0;j<n;j++){
		for(int i=0;i<10;i++){
			if(p[j]==a[i]){
				sum1+=b[i]*k[j];
				sum2+=c[i]*k[j];
				sum3+=d[i]*k[j];
				break;
			}
		}
	  }
		System.out.println(sum1+" "+String.format("%.2f", sum2)+" "+sum3);
	}
	
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值