1. 程式人生 > >SDUT-3349 答答租車系統(面向物件綜合練習)

SDUT-3349 答答租車系統(面向物件綜合練習)

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(含義同上)

Sample Input

1
2
1 1
2 2

Sample Output

15 0.00 1600
import java.util.Scanner;
class Car{
	int num, price, person;
	double w;
	Car(int numi, int personi, double wi, int pricei)
	{
		this.num = numi;
		this.person = personi;
		this.w = wi;
		this.price = pricei;
	}
}
public class Main {
	public static void main(String args[]) {
		Scanner in = new Scanner(System.in);
		Car c[] = {
				new Car(0, 5, 0, 800),
				new Car(1, 5, 0, 400),
				new Car(2, 5, 0, 800),
				new Car(3, 51, 0, 1300),
				new Car(4, 55, 0, 1500),
				new Car(5, 5, 0.45, 500),
				new Car(6, 5, 2, 450),
				new Car(7, 0, 3, 200),
				new Car(8, 0, 25, 1500),
				new Car(9, 0, 35, 2000),
		};
		int t, n, i, x, y;
		t = in.nextInt();
		if(t == 0)
		{
			System.out.println("0 0.00 0\n");
		}
		else
		{
				n = in.nextInt();
				int s1 = 0, s3 = 0;
				double s2 = 0;
				for(i = 0; i < n; i++)
				{
					x = in.nextInt();
					x = x - 1;
					y = in.nextInt();
					s1 += c[x].person * y;
					s2 += c[x].w * y;
					s3 += c[x].price * y;
				}
				System.out.printf("%d %.2f %d\n", s1, s2, s3);
		}
       in.close();
}
}