问答详情
源自:12-1 综合练习

麻烦看看接下来应该咋做

System.out.println("欢迎使用达达租车系统");

    System.out.println("您是否要租车:是1   否0");

    Scanner input = new Scanner (System.in);

    int i=input.nextInt();

    if (i==1){

    System.out.println("您可租车的类型及其价目表:");

    System.out.println("序号"+"\t"+"汽车名称"+"\t"+"租金"+"\t"+"容量");

    }else{

    System.out.println("欢迎您再次光临达达租车系统");

    }

    int j;

    for (j=0;j<6;j++){

    if (automobileMessenge[j] instanceof Car){

    System.out.println(automobileMessenge[j].num+"\t"+automobileMessenge[j].name+"\t"

    +automobileMessenge[j].rent+"元/天"+"\t"+"载人:"+((project7.Car) automobileMessenge[j]).getPeopleCount()+"人");

    }

    if (automobileMessenge[j] instanceof Trunk){

    System.out.println(automobileMessenge[j].num+"\t"+automobileMessenge[j].name+"\t"

        +automobileMessenge[j].rent+"元/天"+"\t"+"载货:"+((project7.Trunk) automobileMessenge[j]).getThingCount()+"吨");

    }

    if (automobileMessenge[j] instanceof PickUp){

    System.out.println(automobileMessenge[j].num+"\t"+automobileMessenge[j].name+"\t"+

    automobileMessenge[j].rent+"元/天"+"\t"+"载人:"+((project7.PickUp) automobileMessenge[j]).getPeopleCount()

        +"载货:"+((project7.PickUp) automobileMessenge[j]).getThingCount()+"吨");

    }

    }

    System.out.println("请输入您要租车的数量");

    int carTotal=input.nextInt();

    int choice []=new int[carTotal];

    for(j=0;j<carTotal;j++){

    System.out.println("请输入第"+""+(j+1)+"辆车的序号");

    choice [j]=input.nextInt();

      }

现在想把数组里的序号循环并判断是能载人的还是能载货的车并输出出来  实在没有思路

提问者:慕粉1471134825 2017-04-15 13:28

个回答

  • minjun123
    2017-04-15 14:26:15

    package 租车系统;

    import java.util.Scanner;


    public class Test {


    public static void main(String[] args) {

    // TODO 自动生成的方法存根

    Carriage c1=new Carriage("奥迪A4",500,4);

    Carriage c2=new Carriage("马自达6",400,4);

    Carriage c3=new Carriage("金龙",800,20);

    PK p1=new PK("皮卡雪6",450,4,2);

    Truck t1=new Truck("松花江",400,4);

    Truck t2=new Truck("依维柯",1000,20);

    System.out.println("欢迎使用租车系统");

    System.out.println("是否租车 0否-1是");

    //选择是否租车

    Scanner s1=new Scanner(System.in);

    double x1=s1.nextDouble();

    if(x1==1)

    {

    //输出租车信息

    System.out.println("当前可租类型及其价目表");

    System.out.println("序号    汽车名称    租金      容量");

    System.out.print("1.   ");

    c1.Introduce();

    System.out.print("2.   ");

    c2.Introduce();

    System.out.print("3.   ");

    p1.Introduce();

    System.out.print("4.   ");

    t1.Introduce();

    System.out.print("5.   ");

    t2.Introduce();

    //租车数量

    System.out.println("请输入您要租的数量");

    Scanner s2=new Scanner(System.in);

    int x2=s2.nextInt();

    //租的车 天数总和  金钱总和....

    int SumDay=0;

    int SumManey=0;

    int SumVolume=0; //总载人

    int SumVolume1=0;//总载货

    String st1="";

    String st2="";

    String st3="";

    String st4="";

    String st5="";

    for(int i=1;i<=x2;i++){

    System.out.println("请输入第"+i+"辆车的序号:");

    Scanner s3=new Scanner(System.in);

    int x=s3.nextInt();


    switch (x)

    {

    case 1:  SumManey+=c1.maney;SumVolume+=c1.volume;st1=c1.name;break;

    case 2:  SumManey+=c2.maney;SumVolume+=c2.volume;st2=c2.name;break;

    case 3:  SumManey+=p1.maney;SumVolume+=p1.volume;SumVolume1+=p1.volume1;st3=p1.name;break;

    case 4:  SumManey+=t1.maney;SumVolume1+=t1.volume;st4=t1.name;break;

    case 5:  SumManey+=t2.maney;SumVolume1+=t2.volume;st5=t2.name;break;

    default: System.out.println("输入有误");break;

    }//switch语句里

    }//for循环里

    System.out.println("请输入租车天数");

    Scanner s4=new Scanner(System.in);

    int day=s4.nextInt();

    System.out.println("账单详情:");

    System.out.println("可载人的有:"+st1+"  "+st2+"  "+st3+"  共"+SumVolume+"人");

    System.out.println("可载货的有: "+st3+"  "+st4+"  "+st5+"  共"+SumVolume1+"吨");

    SumManey*=day;

    System.out.println("总租金为"+SumManey);


    }


    }


    }