就是关于JAVA入门第二季最后那个综合练习题,请问最后怎样可以实现对已经选择了的车辆name的输出?以下是自己写的程序
(父类) package imooc1; public class car { public String number; public String name; public int people; public int weight; public int price; /*生产setter和getter方法*/ public String getNumber() { return number; } public void setNumber(String number) { this.number = number; } public String getName() { return name; } public void setName(String name) { this.name = name; } public int getPeople() { return people; } public void setPeople(int people) { this.people = people; } public int getWeight() { return weight; } public void setWeight(int weight) { this.weight = weight; } public int getPrice() { return price; } public void setPrice(int price) { this.price = price; } } (子类) package imooc1; import java.util.Scanner; public class rental extends car { public static void main(String[] args){ System.out.println("欢迎使用达达租车系统:"); System.out.println("您是否要租车:1是0否"); /*创建Scanner对象,用户输入数据*/ Scanner input=new Scanner(System.in); /*获取用户输入的信息*/ int wh=input.nextInt(); if(wh==1){ /*调用并输出6个方法可供选择,并输出6个对象的全部信息*/ rental car1=new rental(); car1.aud(); rental car2=new rental(); car2.maz(); rental car3=new rental(); car3.pick(); rental car4=new rental(); car4.jinl(); rental car5=new rental(); car5.sonha(); rental car6=new rental(); car6.yiwek(); System.out.println("请输入您要租的车的数量:"); } /*输出客户选择的汽车数量*/ Scanner input1=new Scanner(System.in); /*获取用户输入的信息*/ int wc=input1.nextInt(); double count=0; double wei=0; int peo=0; //String har; for(int i=1;i<=wc;i++){ System.out.println("请输入第"+i+"辆车的序号:"); Scanner input2=new Scanner(System.in); int w=input2.nextInt();//输入选择的车序号 switch(w){ case 1:count+=500;peo+=4;break;//奥迪A4 case 2:count+=400;peo+=4;break;//马自达6 case 3:count+=450;wei+=2;break;//皮卡雪6 case 4:count+=800;peo+=20;break;//金龙 case 5:count+=400;wei+=4;break;//松花江 case 6: count+=1000;wei+=20;//依维柯 } } System.out.println("请输入租车天数:"); Scanner input2=new Scanner(System.in); int w=input2.nextInt();//输入租用天数 count= count*wc;//所有租车费用 System.out.println("您的账单:"); System.out.println("可载人的车有:"); System.out.println("总载人数:"+peo); System.out.println("可载货的车有:"); System.out.println("总载货:"+wei+"吨"); System.out.println("租车总费用为"+count); } /*创建6个车型对象方法*/ public void aud(){ this.number="1"; this.price=500; this.name="奥迪A4"; this.people=4; System.out.println("序号"+number+" 车型"+name+" 价格"+price+"元/天 载物量"+people+"人"); } public void maz(){ this.number="2"; this.price=400; this.name="马自达6"; this.people=4; System.out.println("序号"+number+" 车型"+name+" 价格"+price+"元/天 载物量"+people+"人"); } public void pick(){ this.number="3"; this.price=450; this.name="皮卡雪6"; this.people=4; this.weight=6; System.out.println("序号"+number+" 车型"+name+" 价格"+price+"元/天 载物量"+people+"人 /"+weight+"吨"); } public void jinl(){ this.number="4"; this.price=800; this.name="金龙"; this.people=20; System.out.println("序号"+number+" 车型"+name+" 价格"+price+"元/天 载物量"+people+"人"); } public void sonha(){ this.number="5"; this.price=400; this.name="松花江"; this.weight=4; System.out.println("序号"+number+" 车型"+name+" 价格"+price+"元/天 载物量"+weight+"吨"); } public void yiwek(){ this.number="6"; this.price=1000; this.name="依维柯"; this.weight=20; System.out.println("序号"+number+" 车型"+name+" 价格"+price+"元/天 载物量"+weight+"吨"); } }
怎样在switch语句中收集已选择了的汽车车型名字?当局者迷,求老师指点。。。。。。。Iam waiting