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

答答租车系统-感觉写的好乱啊,还有很多异常都没处理,等着我再写个第二版

标签:
Java
package com.meituan.qa.zonghelianxi;

/**
 * Created by sunfang on 2017/10/6.
 */
public abstract class Car {
     int carType;
     float pricePerDay;
     String name;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getCarType() {
        return carType;
    }

    public void setCarType(int carType) {
        this.carType = carType;
    }

    public float getPricePerDay() {
        return pricePerDay;
    }

    public void setPricePerDay(float pricePerDay) {
        this.pricePerDay = pricePerDay;
    }
    public abstract void showInfo();

}
package com.meituan.qa.zonghelianxi;

/**
 * Created by sunfang on 2017/10/6.
 */
public class Truck extends Car{
    private int cargoNum;

    public int getCargoNum(){
        return cargoNum;
    }
    public void setCargoNum(int cargoNum){
        this.cargoNum=cargoNum;
    }

    public Truck(int cargoNum,int carType,float pricePerDay,String name){
    this.cargoNum=cargoNum;
    this.carType=carType;
    this.pricePerDay=pricePerDay;
    this.name=name;
    }

    public Truck(){

    }

    @Override
    public  void showInfo(){
        System.out.println(this.getName()+"\t"+this.getPricePerDay()+"\t"+"载货:"+getCargoNum());
    }

}
package com.meituan.qa.zonghelianxi;

import com.meituan.qa.springtest.Cat;
import netscape.security.PrivilegeTable;

/**
 * Created by sunfang on 2017/10/6.
 */
public class PrivateCar extends Car {
    private int passengersNum;

    public int getPassengersNum() {
        return passengersNum;
    }

    public void setPassengersNum(int passengersNum) {
        this.passengersNum = passengersNum;
    }

    public PrivateCar(int passengersNum,int carType,float pricePerDay,String name){
        this.passengersNum=passengersNum;
        this.carType=carType;
        this.pricePerDay=pricePerDay;
        this.name=name;
    }
    public PrivateCar(){}

    @Override
    public  void showInfo(){
        System.out.println(this.getName()+"\t"+this.getPricePerDay()+"\t"+"载客:"+getPassengersNum());
    }

}
package com.meituan.qa.zonghelianxi;

/**
 * Created by sunfang on 2017/10/6.
 */
public class PickUp extends Car {
    private int cargoNum;
    private int passengersNum;

    public int getCargoNum() {
        return cargoNum;
    }

    public void setCargoNum(int cargoNum) {
        this.cargoNum = cargoNum;
    }

    public int getPassengersNum() {
        return passengersNum;
    }

    public void setPassengersNum(int passengersNum) {
        this.passengersNum = passengersNum;
    }

    public PickUp(int cargoNum,int passengersNum,int carType,float pricePerDay,String name){
        this.cargoNum=cargoNum;
        this.passengersNum=passengersNum;
        this.carType=carType;
        this.pricePerDay=pricePerDay;
        this.name=name;
    }
    public PickUp(){}

    @Override
    public  void showInfo(){
        System.out.println(this.getName()+"\t"+this.getPricePerDay()+"\t"+"载货:"+this.getCargoNum()+" 载客:"+this.getPassengersNum());
    }

}
package com.meituan.qa.zonghelianxi;

import java.util.Scanner;

/**
 * Created by sunfang on 2017/10/6.
 */
public class RentCarSystem {
    public static void main(String[] args) {
        System.out.println("欢迎使用答答租车系统:\n"+"您是否要租车:1是 0否");
        float rentMoney=0;

        Scanner scanner=new Scanner(System.in);
//        for (int i=0;i<10;i++)
        int input=scanner.nextInt();

        Car[] cars={new Truck(10,1,800,"货车-松花江"),new PrivateCar(4,2,500,"轿车-奥迪A4"),new PickUp(5,2,3,600,"皮卡雪")};

        if (input==1){
            System.out.println("您可租车的类型及价目表:");
            System.out.println("序号\t"+"汽车名称\t\t"+"租金\t\t"+"容量");
            for (int i=0;i<cars.length;i++){
                System.out.print((i+1)+".\t");
                cars[i].showInfo();
            }
        }
        else if (input==0){
        }
        else{
            System.out.println("您输入的选择有误!");
        }

        System.out.println("请输入您要租车的数量:");

        int rentCarNum=scanner.nextInt();
        Car[] selectCars=new Car[rentCarNum];

        for (int i=0;i<rentCarNum;i++){
          System.out.println("请输入第"+(i+1)+"辆车的序号:");
          int rentCarNo=scanner.nextInt();
          selectCars[i]=cars[rentCarNo-1];

          rentMoney=selectCars[i].pricePerDay+rentMoney;
        }

        System.out.println("请输入租车天数:");
        int rentDays=scanner.nextInt();

        //计算所选车及价格
        int passengersAllNum=0;
        int cargoAllNum=0;
        System.out.println("您的账单:");
        System.out.println("---可载人的车有:");
        for (Car car:selectCars) {
            if (car.carType==2){
                System.out.print(car.getName()+" ");
                passengersAllNum=((PrivateCar)car).getPassengersNum()+passengersAllNum;
            }
            else if (car.carType==3){
                System.out.print(car.getName()+" ");
                passengersAllNum=((PickUp)car).getPassengersNum()+passengersAllNum;
            }
        }
        System.out.println("共载人:"+passengersAllNum);

        System.out.println("---可载货的车有:");
        for (Car car:selectCars) {
            if (car.carType==1){
                System.out.print(car.getName()+" ");
                cargoAllNum=((Truck)car).getCargoNum()+cargoAllNum;
            }
           else if(car.carType==3){
                System.out.print(car.getName()+" ");
                cargoAllNum=((PickUp)car).getCargoNum()+cargoAllNum;
            }
        }
        System.out.println("共载货:"+cargoAllNum);

        rentMoney=rentMoney*rentDays;
        System.out.println("---租车总价格为"+rentMoney+"元");

    }
}
点击查看更多内容
TA 点赞

若觉得本文不错,就分享一下吧!

评论

作者其他优质文章

正在加载中
  • 推荐
  • 2
  • 收藏
  • 共同学习,写下你的评论
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦
今天注册有机会得

100积分直接送

付费专栏免费学

大额优惠券免费领

立即参与 放弃机会
意见反馈 帮助中心 APP下载
官方微信

举报

0/150
提交
取消