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++;
}
}
} 做到这一步 程序没问题 就是不知道如何让皮卡那一栏既显示载人 又显示载客
if(xz==1){
System.out.println("您可租车的类型及其价目表"+"\n"+"序号"+"\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;
}
这样判断就可以
我已经解决了
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++;
}
}
}
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("请问你是要租车吗?租车请按1,路过请安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("请输入需要车型:1:皮卡、2:小货车、3:小汽车、4:客车、5:货车!");
Scanner string=new Scanner(System.in);
int chexing=string.nextInt();
if (chexing>=6){
System.out.println("你的输入有误请重新输入!");
// 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("请输入租赁天数");
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("不租车来干嘛?");
return;
}
}
}
我也是新手
问题描述的不太清楚:
继承个 接口可以吗?