手记

费了大劲才蒙出来,接口没方法不知道怎么写啊求指导

package com.didi;

public class Car {
private int id;//序号
private String name;// 车辆名称
private double price;//价格
private double load;//载重
private int seat;//载客
public double getLoad() {
return load;
}
public void setLoad(double load) {
this.load = load;
}
public int getSeat() {
return seat;
}
public void setSeat(int seat) {
this.seat = seat;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}

}
package com.didi;

public class KeCar extends Car {
private int seat;
public KeCar(int id, String name, int seat, double load,double price) {

    // TODO 自动生成的构造函数存根
    super.setId(id);
    super.setName(name);
    super.setPrice(price);
    super.setSeat(seat);
    super.setLoad(load);
}
@Override
public String toString() {
    return  super.getId()+"\t"+super.getName()+"\t"+super.getSeat()+"\t"+super.getLoad()+"\t"+super.getPrice();
}

}
package com.didi;

public class HuoCar extends Car {
public HuoCar(int id, String name, int seat,double load, double price) {
// TODO 自动生成的构造函数存根
super.setId(id);
super.setName(name);
super.setPrice(price);
super.setLoad(load);
super.setSeat(seat);
}

@Override
public String toString() {
    return super.getId()+"\t"+super.getName()+"\t"+super.getSeat()+"\t"+super.getLoad()+"\t"+super.getPrice();
}

}
package com.didi;

public class picar extends Car {
public picar(int id,String name,int seat,double load,double price){
super.setId(id);
super.setName(name);
super.setPrice(price);
super.setSeat(seat);
super.setLoad(load);
}
@Override
public String toString() {
return super.getId()+"\t"+super.getName()+"\t"+super.getSeat()+"\t"+super.getLoad()+"\t"+super.getPrice();
}

}
package com.didi;
import com.didi.Car;
import com.didi.KeCar;
import com.didi.HuoCar;
import com.didi.picar;
//import jiekou.huoche;
//import jiekou.keche;
import java.util.Scanner;

public class test {
String outkename="";
String outhuoname="";
int outseat=0;
double outload=0;
double outprice=0;
double zongprice=0;
Car[ ] car= {
new KeCar(1,"别克", 5 ,0.0 ,1500),
new HuoCar(2,"解放",0,50,1500),
new KeCar(3,"金龙", 50 ,0.0 ,1000),
new picar(4,"雪花",5,10,800),
new HuoCar(5,"长安",0,10,300),
new picar(6,"江卡",2,5,400)
};

public void didi(){
    System.out.println("欢迎使用滴滴选车,选车请按1,不选请按0");
   Scanner a=new Scanner(System.in);
   int in=a.nextInt();
   if(in ==1){
       System.out.println("您可租的车辆有:");
       System.out.println("序号"+"车名"+"  载客量"+"\t"+"载货量"+"\t"+"价格(元/天)");
       for(int i=0; i< car.length;i++){
         //  System.out.println(car[i].getId()+"\t"+car[i].getName()+"\t"+car[i].getPrice());
           System.out.println(car[i]);
       }
   }else if(in ==0){
       System.out.println("谢谢使用");
       return;
   }else{
       System.out.println("你输入的是尼玛啥东西,看提示!.");
       return;
   }
   System.out.println("请输入需要的车数量");

   int num=a.nextInt();
   while(num<=0 || num>6){
       System.out.println("输入错误,请重新输入");
      int num2=a.nextInt();
      num=num2;
   }
    for(int i=0;i<num;i++){
        System.out.println("请输入第"+(i+1)+"辆车的序号:");
          int b=a.nextInt();

       int j=b-1;
       if(car[j].getLoad()!=0){

         outhuoname+=car[j].getName();
       }else if(car[j].getSeat()!=0){
          outkename+=car[j].getName();
       }

      outload+=car[j].getLoad();
      outseat+=car[j].getSeat();
      outprice+=car[j].getPrice();
   }
    System.out.println("请输入您要租的天数:");
    double tian=a.nextDouble();
    zongprice=outprice*tian;
    System.out.println("您的账单:");
    System.out.println("可载货车辆有"+outhuoname);
    System.out.println("可载客的车有:"+outkename);
    System.out.println("可载货量:"+outload+"吨");
    System.out.println("可载客:"+outseat+"人");
    System.out.println("总金额:"+zongprice+"元");

}
public static void main(String[] args) {
    // TODO 自动生成的方法存根
    test u=new test();
    u.didi();

}

}

1人推荐
随时随地看视频
慕课网APP