package com.imooc.dada;
//父类
public abstract class Aotu {
public String name;
public float price;
public int manned;
public float cargo;
//public int number;
public abstract void run();
}
package com.imooc.dada;
//其中一子类
public class Aodi extends Aotu {
@Override
public void run() {
// TODO Auto-generated method stub
}
Aodi(){
name = "奥迪A4 ";
price = 500;
manned = 4;
cargo = 0;
}
}
package com.imooc.dada;
import java.util.Scanner;
//主程序入口
public class Dada {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner input = new Scanner(System.in);
int inputbuf = 0; //输入缓存
int[] inputData; //用户输入数据
float allMoney = 0; //总金额
int day = 0; //天数
String[] takePerson; //载人车名
String[] takeGoods; //载货车名
int loadNumber = 0; //总载人数
float ladenNumber = 0; //总载货数
//创建各个对象
Aotu aodi = new Aodi();
Aotu mazida = new Mazida();
Aotu pikaxue = new Pikaxue();
Aotu jinlon = new Jinlon();
Aotu songhuajiang = new Songhuajiang();
Aotu yiweike = new Yiweike();
//租车流程开始
System.out.println("欢迎使用答答租车系统:");
System.out.println("您是否要搭车:1是 0否");
inputbuf = input.nextInt();
if(inputbuf == 1){
//打印车辆信息
System.out.println("您可租车的类型和价格表:");
System.out.println("序号 汽车名称 租金 容量");
System.out.println("1、 "+aodi.name+aodi.price+"元/天"+" "+"载人:"+aodi.manned+"人"+" "+"载货:"+aodi.cargo+"吨");
System.out.println("2、 "+mazida.name+mazida.price+"元/天"+" "+"载人:"+mazida.manned+"人"+" "+"载货:"+mazida.cargo+"吨");
System.out.println("3、 "+pikaxue.name+pikaxue.price+"元/天"+" "+"载人:"+pikaxue.manned+"人"+" "+"载货:"+pikaxue.cargo+"吨");
System.out.println("4、 "+jinlon.name+jinlon.price+"元/天"+" "+"载人:"+jinlon.manned+"人"+" "+"载货:"+jinlon.cargo+"吨");
System.out.println("5、 "+songhuajiang.name+songhuajiang.price+"元/天"+" "+"载人:"+songhuajiang.manned+"人"+" "+"载货:"+songhuajiang.cargo+"吨");
System.out.println("6、 "+yiweike.name+yiweike.price+"元/天"+" "+"载人:"+yiweike.manned+"人"+" "+"载货:"+yiweike.cargo+"吨");
System.out.println("");
//用户输入
System.out.println("请输入您要租车的数量:");
inputbuf = input.nextInt();
inputData = new int[inputbuf];
takeGoods = new String[inputbuf];
takePerson = new String[inputbuf];
//用户输入车序号
for(int i = 0;i < inputbuf;i++){
System.out.println("请输入第"+(i+1)+"辆车的序号:");
inputData[i] = input.nextInt();
}
System.out.println("请输入租车天数:");
day = input.nextInt();
input.close();
//清空数据
allMoney = 0;
ladenNumber = 0;
loadNumber = 0;
for(int i = 0,j = 0,z = 0;i < inputData.length;i++){
//计算总载人数和总载货数,获取载人车名和载货车名
switch(inputData[i]){
case 1: allMoney = allMoney + aodi.price*day;
loadNumber = loadNumber + aodi.manned;
takePerson[j] = aodi.name;
j++;
break;
case 2: allMoney = allMoney + mazida.price*day;
loadNumber = loadNumber + mazida.manned;
takePerson[j] = mazida.name;
j++;
break;
case 3: allMoney = allMoney + pikaxue.price*day;
loadNumber = loadNumber + pikaxue.manned;
ladenNumber = ladenNumber + pikaxue.cargo;
takePerson[j] = pikaxue.name;
takeGoods[z] = pikaxue.name;
z++;
j++;
break;
case 4: allMoney = allMoney + jinlon.price*day;
loadNumber = loadNumber + jinlon.manned;
takePerson[j] = jinlon.name;
j++;
break;
case 5: allMoney = allMoney + songhuajiang.price*day;
ladenNumber = ladenNumber + songhuajiang.cargo;
takeGoods[z] = pikaxue.name;
z++;
break;
case 6: allMoney = allMoney + yiweike.price*day;
ladenNumber = ladenNumber + pikaxue.cargo;
takeGoods[z] = pikaxue.name;
z++;
break;
default:
}
}
//打印账单
System.out.println("您的帐单:");
System.out.println("***可载人的车有:");
for(String s:takePerson){
if(s != null){
System.out.print(s + " ");
}
}
System.out.println("共载人:" + loadNumber + "人");
System.out.println("***载货的车有:");
for(String s:takeGoods){
if(s != null){
System.out.print(s + " ");
}
}
System.out.println("共载货:" + ladenNumber + "吨");
System.out.println("租车总价钱:" + allMoney);
}else{
System.out.println("再见!");
}
}
}