求大神:载人车车辆和载货车辆怎么分开输出,我结合别人的只能一块输出
package com.imooc;
public class Car {
String name;//定义一个名字
int price;//定义租金
int number;//载人数
int weight;//载货数
}
package com.imooc;
public class Manned extends Car {
Manned(String name,int price,int number){
this.name=name;
this.price=price;
this.number=number;
}
}
package com.imooc;
public class Cargo extends Car {
Cargo(String name,int price,int weight){
this.name=name;
this.price=price;
this.weight=weight;
}
}
package com.imooc;
public class Pickup extends Car {
Pickup(String name,int price,int number,int weight){
this.name=name;
this.price=price;
this.number=number;
this.weight=weight;
}
}
package com.imooc;
import java.util.Scanner;
public class Test {
Car[] rent=new Car[100];//定义一个大数组
Car cars[]={new Manned("江淮客车",300,40),new Cargo("陕汽奥龙",600,50),new Manned("奔驰",700,5),new Cargo("一汽",500,5),new Pickup("皮卡",200,4,1)};
int count;//数量
int day;//天数
int money;//价格
public static void main(String[] args) {
// TODO Auto-generated method stub
Test hello=new Test();
Scanner input =new Scanner(System.in);
System.out.println("欢迎您使用答答租车系统:");
System.out.println("您是否要租车:1是2否");
int inputNumber=input.nextInt();
if(inputNumber==1){
System.out.println("您可租车的类型及其价目表:");
System.out.println("序号 汽车名称 租金 容量:");
System.out.println("1. 江淮客车 300/天 载人:40人" );
System.out.println("2. 陕汽奥龙 600/天 载货:50吨");
System.out.println("3. 奔驰 700/天 载人:5人");
System.out.println("4. 一汽 500/天 载货5吨");
System.out.println("5. 皮卡 200/天 载人:4人,载货:1吨");
}
if(inputNumber==2){
input.close();
System.exit(-1);
}
System.out.println("请输入您要租车的数量");
int carNumber=input.nextInt();
for(int i=0;i<carNumber;i++){
System.out.println("请输入第"+(i+1)+"辆车的序号");
int a=input.nextInt();
while (a < 1 || a > 6) {
System.out.println("您输入的型号有误,请重新输入选择车型");
int b = input.nextInt();
a=b;
}
hello.money += hello.cars[a-1].price;
hello.rent[i]= hello.cars[a-1];
}
System.out.println("请输入租车天数");
int day=input.nextInt();
hello.money*=day;
System.out.println("您的租车账单为:");
int mannedNumber=0;
int cargoNumber=0;
for(int i=0;i<carNumber;i++){
System.out.print(hello.rent[i].name + " ");
mannedNumber+=hello.rent[i].number;
cargoNumber+=hello.rent[i].weight;
}
System.out.println("您的租车载人数量" + mannedNumber + "人");
System.out.println("您的租车载货量" + cargoNumber + "吨");
System.out.println("您的租车总费用:" + hello.money);
}
}