JAVA answering car rental system (object-oriented comprehensive exercise)


Ada car rental system (object-oriented comprehensive exercise)

Time Limit: 1000 ms Memory Limit: 65536 KiB

Problem Description

Dear object-oriented friends, after learning the core concepts of object-oriented - class encapsulation, inheritance, and polymorphism, the car rental system started to operate.

Please make full use of object-oriented thinking to solve the problem of intelligent car rental for the company, and calculate the rental fee, the maximum number of passengers, and the maximum load according to the car model selected by the customer and the number of rental days.

The company currently has three types of models (passenger cars, pickup trucks, and trucks), each of which has a name and rental attributes; among them: passenger cars can only carry people, trucks can only carry goods, and pickup trucks are both passenger and cargo vehicles. It can carry people as well as cargo.

The following are the available models, capacities and price lists of the car rental company:
No. Name Passenger capacity Cargo capacity Rent
                           (person) (ton) (yuan/day)
  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

Requirement: Calculate the total number of people that can be carried, the total number of goods and the total amount of rental fees according to the serial number and days of the rental type entered by the customer.

Input

The first line is an integer: whether to rent a car or not 1 - to rent a car (the program continues), 0 - not to rent a car (the program ends);

The second line is an integer representing the number N to be rented;

Next is N lines of data, each line has 2 integers m and n, where: m represents the number of the car to be rented, and n represents the number of days to rent the model.

Output

If the rental car is successful, a line of data will be output with a space between the data, meaning:

Total number of passengers Carried total weight (2 decimal places) Car rental amount (integer)

If you don't rent a car, output: 

0 0.00 0 (same meaning as above)

Sample Input

1
2
1 1
2 2

Sample Output

15 0.00 1600

import java.util. *;
class Car{
	int people, price;
	double thing;
	public void start(int n) {
		switch(n) {
		case 1:people = 5; thing = 0; price = 800;break;
		case 2:people = 5; thing = 0; price = 400;break;
		case 3:people = 5; thing = 0; price = 800;break;
		case 4:people = 51; thing = 0; price = 1300;break;
		case 5:people = 55; thing = 0; price = 1500;break;
		case 6:people = 5; thing = 0.45; price = 500;break;
		case 7:people = 5; thing = 2.0; price = 450;break;
		case 8:people = 0; thing = 3; price = 200;break;
		case 9:people = 0; thing = 25; price = 1500;break;
		case 10:people = 0; thing = 35; price = 2000;break;
		}
	}
	public void end(int m) {
		people *= m;
		thing *= m;
		price *= m;
	}
	public void put() {
		System.out.printf("%d %.2f %d\n", people, thing, price);
	}
}
public class Main {
	public static void main(String args[]) {
		Scanner cin = new Scanner(System.in);
		int t = cin.nextInt ();
		while(t != 0) {
			Car c = new Car();
			int x = cin.nextInt ();
			while(x != 0) {
				int n = cin.nextInt ();
				int m = cin.nextInt ();
				Car a = new Car();
				a.start(n);
				a.end(m);
				c.people += a.people;
				c.thing += a.thing;
				c.price += a.price;
				x--;
			}
			c.put();
			t = cin.nextInt ();
		}
		System.out.println("0 0.00 0");//If you use System.out.println(0.00), you can only print 0.0, so it should be output in the form of a string when printing
	}
}






Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324574202&siteId=291194637