package com.zuoye;import java.util.Scanner;public class Initial { private static final String NULL=null; private static Scanner input; //用来输入数据 public static void main(String[] args) { // TODO Auto-generated method stub for(;;){ //无条件执行语句,直到执行循环内部的跳出语句 System.out.println("欢迎使用租车系统!"); System.out.println("您是否需要租车1:是 2:否"); input=new Scanner(System.in); int i=input.nextInt(); //完成数据的输入 if(i==1){ //显示可以租车的信息 System.out.println("您可以租车的相关信息:"); Car[] car={new PersonCar(1,"奥迪A4",500,4),new PersonCar(2,"马自达6",400,4), new PersonCar(3," 金龙 ",800,20), new Pickup(4,"皮卡雪6",450,4,2),new Truck(5,"松花江",400,4), new Truck(6,"依维柯",1000,20)}; //初始化对象,建立Car类对象的数组car //遍历car类对象输出 System.out.println("序号"+" 名称"+" 价格"+" 容量1"); for(Car rendcar:car){ if(rendcar instanceof PersonCar){ //判断是否有客车类对象的元素,输出相关的信息 System.out.println(rendcar.getCarNum()+" "+rendcar.getCarName()+" "+rendcar.getCarPrice()+"/天"+" "+ ((PersonCar)rendcar).getCarCapacity()+"人"); //注意这里必须进行强制类型转换,转换为客车类,否则无法调用输出容量的信息 } if(rendcar instanceof Pickup){ //判断是否有皮卡类对象的元素,输出相关的信息 System.out.println(rendcar.getCarNum()+" "+rendcar.getCarName()+" "+rendcar.getCarPrice()+"/天"+" "+ ((Pickup)rendcar).getCarCapacity()+"人"+" "+((Pickup)rendcar).getCarryingCapacity()+"吨"); } if(rendcar instanceof Truck){ //判断是否有货车类对象的元素,输出相关的信息 System.out.println(rendcar.getCarNum()+" "+rendcar.getCarName()+" "+rendcar.getCarPrice()+"/天"+" "+ ((Truck)rendcar).getCarryingCapactity()); } //System.out.println(rendcar); //直接输出,输出的是对象的哈希码 } System.out.println("请输入您的租车数量!"); int rendNum=input.nextInt(); //获开租车数量 String[] name=new String[rendNum]; //建立数组,保存租车的名称 String[] name2=new String[rendNum]; int sumCapacity=0; //计算总的载人数 int sumCCapacity=0; //计算中的载货量 int sumPrice=0; //计算总的价格 int a=0; int b=0; for(int i1=0;i1 |