继续浏览精彩内容
慕课网APP
程序员的梦工厂
打开
继续
感谢您的支持,我会继续努力的
赞赏金额会直接到老师账户
将二维码发送给自己后长按识别
微信支付
支付宝支付

简易的达达租车系统,程序写的实现的比较笨,希望得到老司机指点!

采菊大侠
关注TA
已关注
手记 4
粉丝 0
获赞 18
//入口类
import java.util.Scanner;
public class ddRental{
 public static void main(String[] args){
  System.out.println("**********欢迎您实用达达租车系统**********");
  System.out.println("请问您是否需要租车:1表示【是】  其他表示【否】");
  Scanner in = new Scanner(System.in);
  boolean f = true;
  for(int z=0;f;z++){
  int input = in.nextInt();
  if(input!=1){System.out.print("需要租车请输数字1哦:"+"\n");}
  while(input==1){//如果用户输入1则显示车辆信息,循环整懵了!!暂时这样实现

        System.out.println("序号  汽车名称     租金                   容量");
        Car s1 = new SmallCar(1,"奥迪A6",500,4);
        Car s2 = new SmallCar(2,"马自达6",400,4);
        Car p  = new Pickup(3,"皮卡雪6",450,4,2);
        Car b  = new Buss(4,"金龙",800,20);
        Car t1  = new Truck(5,"松花江",400,4);
        Car t2  = new Truck(6,"依维柯",1000,20);
        System.out.println(s1.getInfo());
        System.out.println(s2.getInfo());
        System.out.println(p.getInfo());
        System.out.println(b.getInfo());
        System.out.println(t1.getInfo());
        System.out.println(t2.getInfo());
        f=false;
        break;
      }

  }
  System.out.print("请输入您要租汽车的数量:");
  int count = in.nextInt();//保存租车数量
  int zz = 0;//保存总载客
  int zr = 0;//保存载人总数
  double zj = 0;//保存总租金
  for(int i=1;i<=count;i++){//根据租车数量计算和判断
      System.out.print("请输入第"+i+"辆车的序号:");
      int a = in.nextInt();
      switch(a){
      case 1:zj+=500;zr+=4;break;
      case 2:zj+=400;zr+=4;break;
      case 3:zj+=450;zr+=4;zz+=2;break;
      case 4:zj+=800;zr+=20;break;
      case 5:zj+=400;zz+=4;break;
      case 6:zj+=1000;zz+=20;break;
      default:System.out.println("您输入有误请重新输入车辆序号");i--;
      }
    }
   System.out.print("\n*总租金为:"+zj+"元"+"\n"+"*总载货为:"+zz+"吨"+"\n"+"*总载客量:"+zr+"人");

  }
}
class Car{//创建一个叫car的父类 
      private int id;
      private String name;
      private double rent;
      private int passenger;
      private int capacity;
      public String getInfo(){
       return id+" "+name+" "+rent+"元/天"+" "+"载人"+passenger+"人"+capacity+"吨";
      }
      //构造方法
      public Car(){}//
      public Car(int id,String name,double rent,int passenger,int capacity){
      this.id = id;
      this.name = name;
      this.rent = rent;
      this.passenger = passenger;
      this.capacity = capacity;
      }
      //setter 方法
      public void setId(int id){
       this.id = id;
      }
      public void setName(String name){
       this.name = name;
      }
      public void setRent(double rent){
       this.rent = rent;
      }
      public void setPassenger(int passenger){
       this.passenger = passenger;
      }
      public void setCapacity(int capacity){
       this.capacity = capacity;
      }
      //getter
      public int getId(){
       return this.id;
      }
      public String getName(){
       return this.name;
      }
      public double getRent(){
       return this.rent;
      }
      public int getPassenger(){
       return this.passenger;
      }
      public int getCapacity(){
       return this.capacity;
      }
    } 
class SmallCar extends Car{小车类
        public String getInfo(){
               return getId()+"   "+getName()+"   "+getRent()+"元/天"+"   "+"载人"+getPassenger()+"人"+"   "+getCapacity()+"吨";
              }
        public SmallCar(int id,String name,double rent,int passenger){
            setId(id);
            setName(name);
            setRent(rent);
            setPassenger(passenger);
        }
    }
class Pickup extends Car{皮卡车类
        public String getInfo(){
               return getId()+"   "+getName()+"   "+getRent()+"元/天"+"   "+"载人"+getPassenger()+"人"+"   "+getCapacity()+"吨";
              }
     public Pickup(int id,String name,double rent,int passenger,int capacity){
        setId(id);
        setName(name);
        setRent(rent);
        setPassenger(passenger);
        setCapacity(capacity);
    }

}
    class Buss extends Car{//客车类
        public String getInfo(){
               return getId()+"   "+getName()+"       "+getRent()+"元/天"+"   "+"载人"+getPassenger()+"人"+"   "+getCapacity()+"吨";
              }
     public Buss(int id,String name,double rent,int passenger){
        setId(id);
        setName(name);
        setRent(rent);
        setPassenger(passenger);

    }

  }
public class Truck extends Car {//货车类

        public String getInfo(){
               return getId()+"   "+getName()+"   "+getRent()+"元/天"+"   "+"载人"+getPassenger()+"人"+"   "+getCapacity()+"吨";
              }
      public Truck(int id,String name,double rent,int capacity){
        setId(id);
        setName(name);
        setRent(rent);
        setCapacity(capacity);
      }
}
打开App,阅读手记
1人推荐
发表评论
随时随地看视频慕课网APP