阅读以下说明和Java代码,填补代码中的空缺,将解答填入答题纸的对应栏内。【说明】以下Java代码实现两类交通工具(Flight和Train)的简单订票处理,类Vehicle、Flight、Train之间的关系如图5-1所示。 【Java代码】 importjava.util.ArrayList;importjava.util.List;abstractclassVehicle{voidbook(intn){//订n张票if(getTicket0()>=n){decreaseTicket(n);}else{System.out.println(“余票不足!!“);}}abstractintgetTicket();abstractvoiddecreaseTicket(intn);};classFlight(1){Private(2)tickets=216;//Flight的票数IntgetTicket(){Returntickets;}voiddecreaseTicket(intn){tickets=tickets-n;}}classTrain(3){Private(4)tickets=2016;//Train的票数intgetTicket(){returntickets;}voiddecreaseticket(intn){tickets=tickets-n;}}publicclassTest{publicstaticvoidmain(String[]args){System.out.println(“欢迎订票!");ArrayListVehiclev=newArrayListVehicle();v.add(newFlight());v.add(newTrain());v.add(newFlight());v.add(newTrain());v.add(newTrain());for(inti=0;iv.size();i++){(5)(i+1);//订i+1张票System.out.println(“剩余票数:”+v.get(i).getTicket());}}} 运行该程序时输出如下:欢迎订票!剩余票数:215剩余票数:2014剩余票数:(6)剩余票数:(7)剩余票数:(8)
extendsVehicleintextendsVehicleintv.get(i).book21320122011