如何使皮卡既顯示載人又顯示載客
?if(is==1){
???for(Didi currentCar:carsForRent){
????if(currentCar instanceof PassengerCar){
?????System.out.println(""+i+"\t"+currentCar.getName()+"\t"+currentCar.getRentm()+"元/天"+"\t"+currentCar.getTake()+"人");
????i++;
????}
????else{
?????System.out.println(""+i+"\t"+currentCar.getName()+"\t"+currentCar.getRentm()+"元/天"+"\t"+currentCar.getTon()+"噸");
????i++;
????}
???}
??} 做到這一步 程序沒(méi)問(wèn)題 就是不知道如何讓皮卡那一欄既顯示載人 又顯示載客
2016-11-17
? ??? if(xz==1){
?? ??? ??? ?System.out.println("您可租車的類型及其價(jià)目表"+"\n"+"序號(hào)"+"\t"+"汽車名稱"+"\t"+"租金"+"\t"+"容量");
?? ??? ??? ?for(int i=0;i<6;i++){
?? ??? ??? ??? ?if(car[i].dun==0){
?? ??? ??? ?System.out.println((i+1)+".\t"+car[i].name+"\t"+car[i].price+"元/天"+"\t"+car[i].person+"人");
?? ??? ??? ?}else if(car[i].person==0){
?? ??? ??? ??? ?System.out.println((i+1)+".\t"+car[i].name+"\t"+car[i].price+"元/天"+"\t"+"載貨:"+car[i].dun+"噸");
?? ??? ??? ?}else{
?? ??? ??? ??? ?System.out.println((i+1)+".\t"+car[i].name+"\t"+car[i].price+"元/天"+"\t"+car[i].person+"人"+"載貨:"+car[i].dun+"噸");
?? ??? ??? ?}
?? ??? ??? ?}
?? ??? ?}else{
?? ??? ??? ?return;
?? ??? ?}
這樣判斷就可以
2016-10-23
我已經(jīng)解決了?
if(is==1){
for(Didi currentCar:carsForRent){
if(currentCar instanceof PassengerCar){
System.out.println(""+i+"\t"+currentCar.getName()+"\t"+currentCar.getRentm()+"元/天"+"\t"+"載人:"+currentCar.getTake()+"人");
i++;
}
else if(currentCar instanceof PickUp){
System.out.println(""+i+"\t"+currentCar.getName()+"\t"+currentCar.getRentm()+"元/天"+"\t"+"載人:"+currentCar.getTake()+"人"+"載貨:"+currentCar.getTon()+"噸");
i++;
}else{
System.out.println(""+i+"\t"+currentCar.getName()+"\t"+currentCar.getRentm()+"元/天"+"\t"+"載貨:"+currentCar.getTon()+"噸");
i++;
}
}
}
2016-10-21
public ?class DaDaZhuChe {
?static void zhonglei(){
? ? ?String name;int money;int day; int people;
?}
}
class huoche extends DaDaZhuChe{
? static void zhonglei(){
? ? ? String name="貨車"; int money=580;int day=1;String zaizhong="5噸以上";int people=2;
? ? ? System.out.println(name+money+"元、"+day+"天、"+"載重:"+zaizhong+"、可以坐"+people+"人");
? }
}
class xiaohuoche extends DaDaZhuChe{
? ?static void zhonglei(){
? ? ? ?String name="小貨車"; int money=400;int day=1;String zaizhong="5噸以下";int people=2;
? ? ? ?System.out.println(name+money+"元、"+day+"天、"+"載重:"+zaizhong+"、可以坐"+people+"人");
? ?}
}
class keche extends DaDaZhuChe{
? ?static void zhonglei(){
? ? ? ?String name="客車"; int money=1000;int day=1 ;int people=50;
? ? ? ?System.out.println(name+money+"元、"+day+"天、"+"可以坐"+people+"人");
? ?}
}
class xiaoqiche extends DaDaZhuChe{
? ?static void zhonglei(){
? ? ? ?String name="小汽車"; int money=800;int day=1 ;int people=5;
? ? ? ?System.out.println(name+money+"元、"+day+"天、"+"可以坐"+people+"人");
? ?}
}
class pika extends DaDaZhuChe{
? ?static void zhonglei(){
? ? ? ?String name="皮卡"; int money=500;int day=1 ;int people=5;String zaizhong="2噸";
? ? ? ?System.out.println(name+money+"元、"+day+"天、"+"載重:"+zaizhong+"、可以坐"+people+"人");
? ?}
? ?public static void main(String[] args) {
? ? ? ?pika p1 = new pika();
? ? ? ?xiaohuoche xiaohuoche = new xiaohuoche();
? ? ? ?huoche huoche = new huoche();
? ? ? ?xiaoqiche xiaoqiche = new xiaoqiche();
? ? ? ?keche keche = new keche();
? ? ? ?System.out.println("歡迎光臨滴滴租車");
? ? ? ?System.out.println("請(qǐng)問(wèn)你是要租車嗎?租車請(qǐng)按1,路過(guò)請(qǐng)安2");
? ? ? ?Scanner A=new Scanner(System.in);
? ? ? ?int a = A.nextInt();
? ? ? ?if(a==1){
? ? ? ? ? ?System.out.println("我們公司有:");
? ? ? ? ? ?p1.zhonglei();
? ? ? ? ? ?xiaohuoche.zhonglei();
? ? ? ? ? ?xiaoqiche.zhonglei();
? ? ? ? ? ?keche.zhonglei();
? ? ? ? ? ?huoche.zhonglei();
? ? ? ? ? ?outer:
? ? ? ? ? ?System.out.println("請(qǐng)輸入需要車型:1:皮卡、2:小貨車、3:小汽車、4:客車、5:貨車!");
? ? ? ? ? ?Scanner string=new Scanner(System.in);
? ? ? ? ? ?int chexing=string.nextInt();
? ? ? ? ? ?if (chexing>=6){
? ? ? ? ? ? ? ?System.out.println("你的輸入有誤請(qǐng)重新輸入!");
// ? ? ? ? ? ? ? continue outer;
? ? ? ? ? ?}
? ? ? ? ? ?switch (chexing){
? ? ? ? ? ? ? ?case 1:p1.zhonglei();break;
? ? ? ? ? ? ? ?case 2:xiaohuoche.zhonglei();break;
? ? ? ? ? ? ? ?case 3:huoche.zhonglei();break;
? ? ? ? ? ? ? ?case 4:keche.zhonglei();break;
? ? ? ? ? ? ? ?case 5:xiaoqiche.zhonglei();break;
? ? ? ? ? ?}
? ? ? ? ? ?System.out.println("請(qǐng)輸入租賃天數(shù)");
? ? ? ? ? ?Scanner scanner=new Scanner(System.in);
? ? ? ? ? ?int day=scanner.nextInt();
? ? ? ? ? ?switch (chexing){
? ? ? ? ? ? ? ?case 1:
? ? ? ? ? ? ? ? ? ?System.out.println("車型:皮卡\r\n"+"租期"+day+"天.\r\n需要租金:"+(500*day)+"元");break;
? ? ? ? ? ? ? ?case 2:
? ? ? ? ? ? ? ? ? ?System.out.println("車型:小貨車\r\n"+"租期"+day+"天.\r\n需要租金:"+(400*day)+"元");break;
? ? ? ? ? ? ? ?case 3:
? ? ? ? ? ? ? ? ? ?System.out.println("車型:小汽車\r\n"+"租期"+day+"天.\r\n需要租金:"+(800*day)+"元");break;
? ? ? ? ? ? ? ?case 4:
? ? ? ? ? ? ? ? ? ?System.out.println("車型:客車\r\n"+"租期"+day+"天.\r\n需要租金:"+(1000*day)+"元");break;
? ? ? ? ? ? ? ?case 5:
? ? ? ? ? ? ? ? ? ?System.out.println("車型:貨車\r\n"+"租期"+day+"天.\r\n需要租金:"+(580*day)+"元");break;
? ? ? ?}
? ? ? ?}
? ? ? ? ?else{
? ? ? ? ? ?System.out.println("不租車來(lái)干嘛?");
? ? ? ? ? ?return;
? ? ? ?}
? ? ? ?}
? ?}
我也是新手?
2016-10-21
問(wèn)題描述的不太清楚:
繼承個(gè) ?接口可以嗎?