为了账号安全,请及时绑定邮箱和手机立即绑定

关于租车的实现,结构上有什么问题,求指导

关于租车的实现,结构上有什么问题,求指导

攻城狮1994 2016-08-29 18:42:16
package muke.stu.one; import java.util.Scanner; import muke.stu.one.entity.Car; import muke.stu.one.entity.Coatch; import muke.stu.one.entity.Pika; import muke.stu.one.entity.Truck; public class rentCar {     static Scanner in = new Scanner(System.in);     public static void main(String[] args) {         Boolean isRentCar = false;         int carNum = 0;         String rentInformation = null;         Car[] carInit = {new Pika("皮卡",2,6,1200), new Truck("大货车",20,800),new Coatch("客车",20,1000),new Pika("破皮卡",3,5,800),                         new Coatch("破客车",25,1000)};                  System.out.println("是否需要租车:1.是     2.否");         int rentCar = in.nextInt();         if(rentCar == 1){             isRentCar = true;         }         if(isRentCar){             System.out.println("租用几辆车:");             carNum = in.nextInt();             rentInformation = rent(carNum,carInit);             System.out.println("您的租车信息:"+"\n"+rentInformation);         }         System.out.println("谢谢使用");     }     //租车界面     public static String rent(int carNum,Car[] carArray){         String rentInformation = null;         int carID;         double cost =0.0;         int  people=0;         int capacity=0;         int days =0;         String addPeople ="";         String addCapacity="";         //展示车辆信息         System.out.println("序号 \t类型 \t容量 \t价格(元/天)");         for(int i=0;i<carArray.length;i++){             System.out.println(i+1+"\t"+carArray[i].getType()                             +"\t"+carArray[i].getContent()+"\t"+carArray[i].getPrice());         }         //获取选择车辆         for(int m=0;m<carNum;m++){             System.out.println("请输入您需要车辆序号:");             carID=in.nextInt();             Car carRent =carArray[carID-1];             if(carRent instanceof Pika){                 cost += carRent.getPrice();                 people += ((Pika) carRent).getManned();                 capacity += ((Pika) carRent).getCapacity();                 addPeople += carRent.getType()+"\t";                 addCapacity += carRent.getType()+"\t";             }else if(carRent instanceof Truck){                 cost += carRent.getPrice();                 capacity += ((Truck) carRent).getCapacity();                 addCapacity += carRent.getType()+"\t";             }else{                 cost += carRent.getPrice();                 people += ((Coatch) carRent).getManned();                 addPeople += carRent.getType()+"\t";             }         }         System.out.println("请输入您需要租借的天数");         days= in.nextInt();         cost = cost*days;         //格式化租车信息         rentInformation ="您租用载人的车有:"+"\n"+addPeople+"共载人:"+people+"\n"                  +"您租用货物的车有:"+"\n"+addCapacity+"共载货物:"+capacity+"\n"                 +"您租车:"+days+"天"+"\t"+"共花费:"+cost+"元";         return rentInformation;     } } package muke.stu.one.entity; public class Car {     //名字,类型     private String type;     //价钱     private double price;     //容量     private String content;     public String getContent() {         return content;     }     public void setContent(String content) {         this.content = content;     }     public String getType() {         return type;     }     public void setType(String type) {         this.type = type;     }     public double getPrice() {         return price;     }     public void setPrice(double price) {         this.price = price;     }      } package muke.stu.one.entity; import muke.stu.one.serivce.transportGoods; import muke.stu.one.serivce.transportPeople; public class Pika extends Car implements transportGoods,transportPeople{     private int capacity;     private int manned;          public int getCapacity() {         return capacity;     }     public void setCapacity(int capacity) {         this.capacity = capacity;     }     public int getManned() {         return manned;     }     public void setManned(int manned) {         this.manned = manned;     }     public Pika(){         super();     }     public Pika(String type,int manned,int capacity,double price){         this.setType(type);         this.setCapacity(capacity);         this.setManned(manned);         this.setPrice(price);         this.setContent(transportPeople()+transportGoods());     }               @Override     public String transportPeople() {         String transportPeople ="载人量:"+this.getManned();         return transportPeople;              }     @Override     public String transportGoods() {         String transportGoods="载货量:"+this.getCapacity();         return transportGoods;     }      } package muke.stu.one.entity; import muke.stu.one.serivce.transportPeople; public class Coatch extends Car implements transportPeople{     private int manned;     public int getManned() {         return manned;     }     public void setManned(int manned) {         this.manned = manned;     }     public Coatch(){         super();     }     public Coatch(String type,int manned,double price){         this.setType(type);         this.setManned(manned);         this.setPrice(price);         this.setContent(transportPeople());     }     @Override     public String transportPeople() {         String transportPeople ="载人量:"+this.getManned();         return transportPeople;              } } package muke.stu.one.entity; import muke.stu.one.serivce.transportGoods; public class Truck extends Car implements transportGoods{     private int capacity;     public int getCapacity() {         return capacity;     }     public void setCapacity(int capacity) {         this.capacity = capacity;     }     public Truck(){         super();     }     public Truck(String type,int capacity,double price){         this.setType(type);         this.setCapacity(capacity);         this.setPrice(price);         this.setContent(transportGoods());     }     @Override     public String transportGoods() {         String transportGoods="载货量:"+this.getCapacity();         return transportGoods;     }      } package muke.stu.one.serivce; public interface transportGoods {     public String transportGoods(); } package muke.stu.one.serivce; public interface transportPeople {     public  String transportPeople(); }
查看完整描述

1 回答

?
qq_昼绽_0

TA贡献82条经验 获得超17个赞

哪里出错了,这么多怎么看,

查看完整回答
反对 回复 2016-08-29
  • 攻城狮1994
    攻城狮1994
    没错啊,但是接口到底用来做什么呢?只是作为不同功能的输出么?
  • 1 回答
  • 1 关注
  • 1170 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信