qq_零_14
2016-07-25 16:47
package com.imooc;
import java.util.*;
public class Test {
public static void main(String[] args) {
// TODO Auto-generated method stub
List<car> cars = new ArrayList<car>();
System.out.println("欢迎来到达达租车系统");
System.out.println("你是否要租车 : 1 是 2 否");
car aodi=new aodi();
cars.add(aodi);
car jinlong=new jinlong();
cars.add(jinlong);
car mazida=new mazida();
cars.add(mazida);
car pikaxue=new pikaxue();
cars.add(pikaxue);
car song=new song();
cars.add(song);
car yiweike=new yiweike();
cars.add(yiweike);
Scanner k = new Scanner(System.in);
int num=k.nextInt();
if(num==1){
System.out.println("你可租车得类型及价格表:"+"\n"+"序号"+"\t"+"汽车名称"+"\t"+"租金"+"\t"+"载人"+"\t"+"容量");
aodi.Car(1);
jinlong.Car(2);
mazida.Car(3);
pikaxue.Car(4);
song.Car(5);
yiweike.Car(6);
System.out.println("请输入你要的汽车数量:");
Scanner amount=new Scanner(System.in);
int b=amount.nextInt();
int c;
int allmanned=0;
int allcargo=0;
int allrent=0;
String person="";
String Cars="";
for(int i=1;i<=b;i++){
do{
System.out.println("请输入第"+i+"辆车的序号");
Scanner k2=new Scanner(System.in);
c=k2.nextInt();
}while(c<1||c>6);
car cc=cars.get(c-1);
if(cc.manned>0){
allmanned+=cc.manned;
person+=cc.name+"";
}
if(cc.cargo>0){
allcargo+=cc.cargo;
Cars+=cc.name+"";
}
allrent+=cc.rent;
System.out.println("请输入要租用的天数");
Scanner k3=new Scanner(System.in);
int t=k3.nextInt();
allrent*=t;
System.out.println("你的账单:"+"\n"+"可载人的车有:"+person+"\t"+"共载客:"+allmanned);
System.out.println("可载货的车有:"+Cars+"共载货"+allcargo);
System.out.println("总租金为:"+allrent);
}
}
}
}
有参考成分。从car cc=cars.get(c-1);开始没有跳入if语句中。
Java入门第二季 升级版
530653 学习 · 6091 问题
相似问题