Java——sdut-oop-7 答答租车系统(类的继承与多态 面向对象综合练习)
import java.util.*;
public class Main
{
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
int flag=sc.nextInt();
if(flag==0)
{
System.out.println("0 0.00 0");
}
else
{
int N=sc.nextInt();
int peoples=0,prices=0;double kgs=0.0;//定义总人数、总重量、总金额的变量;
for(int i=0;i<N;i++)
{
int m=sc.nextInt();
Car car=new Car(sc.nextInt());//实例化租车对象;
switch(m)
{
case 1:peoples+=car.getApeople();prices+=car.getAprice();break;
case 2:peoples+=car.getBpeople();prices+=car.getBprice();break;
case 3:peoples+=car.getCpeople();prices+=car.getCprice();break;
case 4:peoples+=car.getDpeople();prices+=car.getDprice();break;
case 5:peoples+=car.getEpeople();prices+=car.getEprice();break;
case 6:peoples+=car.getFpeople();kgs+=car.getFkg();prices+=car.getFprice();break;
case 7:peoples+=car.getGpeople();kgs+=car.getGkg();prices+=car.getGprice();break;
case 8:kgs+=car.getHkg();prices+=car.getHprice();break;
case 9:kgs+=car.getIkg();prices+=car.getIprice();break;
case 10:kgs+=car.getJkg();prices+=car.getJprice();break;
//default:System.out.println("未找到相关车型");break;
}
}
System.out.print(peoples);
System.out.printf(" %.2f",kgs);
System.out.print(" "+prices);
}
}
}
class Car
{
private int day;
public Car(int day)
{
this.day=day;
}
public int getAprice()
{
return day*800;
}
public int getApeople()
{
return day*5;
}
public int getBprice()
{
return day*400;
}
public int getBpeople()
{
return day*5;
}
public int getCprice()
{
return day*800;
}
public int getCpeople()
{
return day*5;
}
public int getDprice()
{
return day*1300;
}
public int getDpeople()
{
return day*51;
}
public int getEprice()
{
return day*1500;
}
public int getEpeople()
{
return day*55;
}
public int getFprice()
{
return day*500;
}
public int getFpeople()
{
return day*5;
}
public double getFkg()
{
return day*0.45;
}
public int getGprice()
{
return day*450;
}
public int getGpeople()
{
return day*5;
}
public double getGkg()
{
return day*2.0;
}
public int getHprice()
{
return day*200;
}
public int getHkg()
{
return day*3;
}
public int getIprice()
{
return day*1500;
}
public int getIkg()
{
return day*25;
}
public int getJprice()
{
return day*2000;
}
public int getJkg()
{
return day*35;
}
}