查看: 1546|回复: 0

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

发表于 2018-2-4 10:14:34

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) {

  1. // TODO 自动生成的构造函数存根
  2. super.setId(id);
  3. super.setName(name);
  4. super.setPrice(price);
  5. super.setSeat(seat);
  6. super.setLoad(load);
  7. }
  8. @Override
  9. public String toString() {
  10. return super.getId()+"\t"+super.getName()+"\t"+super.getSeat()+"\t"+super.getLoad()+"\t"+super.getPrice();
  11. }
复制代码

}
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);
}

  1. @Override
  2. public String toString() {
  3. return super.getId()+"\t"+super.getName()+"\t"+super.getSeat()+"\t"+super.getLoad()+"\t"+super.getPrice();
  4. }
复制代码

}
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)
};

  1. public void didi(){
  2. System.out.println("欢迎使用滴滴选车,选车请按1,不选请按0");
  3. Scanner a=new Scanner(System.in);
  4. int in=a.nextInt();
  5. if(in ==1){
  6. System.out.println("您可租的车辆有:");
  7. System.out.println("序号"+"车名"+" 载客量"+"\t"+"载货量"+"\t"+"价格(元/天)");
  8. for(int i=0; i< car.length;i++){
  9. // System.out.println(car[i].getId()+"\t"+car[i].getName()+"\t"+car[i].getPrice());
  10. System.out.println(car[i]);
  11. }
  12. }else if(in ==0){
  13. System.out.println("谢谢使用");
  14. return;
  15. }else{
  16. System.out.println("你输入的是尼玛啥东西,看提示!.");
  17. return;
  18. }
  19. System.out.println("请输入需要的车数量");
  20. int num=a.nextInt();
  21. while(num<=0 || num>6){
  22. System.out.println("输入错误,请重新输入");
  23. int num2=a.nextInt();
  24. num=num2;
  25. }
  26. for(int i=0;i<num;i++){
  27. System.out.println("请输入第"+(i+1)+"辆车的序号:");
  28. int b=a.nextInt();
  29. int j=b-1;
  30. if(car[j].getLoad()!=0){
  31. outhuoname+=car[j].getName();
  32. }else if(car[j].getSeat()!=0){
  33. outkename+=car[j].getName();
  34. }
  35. outload+=car[j].getLoad();
  36. outseat+=car[j].getSeat();
  37. outprice+=car[j].getPrice();
  38. }
  39. System.out.println("请输入您要租的天数:");
  40. double tian=a.nextDouble();
  41. zongprice=outprice*tian;
  42. System.out.println("您的账单:");
  43. System.out.println("可载货车辆有"+outhuoname);
  44. System.out.println("可载客的车有:"+outkename);
  45. System.out.println("可载货量:"+outload+"吨");
  46. System.out.println("可载客:"+outseat+"人");
  47. System.out.println("总金额:"+zongprice+"元");
  48. }
  49. public static void main(String[] args) {
  50. // TODO 自动生成的方法存根
  51. test u=new test();
  52. u.didi();
  53. }
复制代码

}



回复

使用道具 举报