关闭

智障租车(JAVA小项目)

633人阅读 评论(0) 收藏 举报
分类:

慕课网JAVA第二季最后留的小作业http://www.imooc.com/video/3334

源码存一下,留到若干年以后笑笑自己

package Prim;

//汽车父类
public class Car {
    private String CarName;
    private double CarPrice;

    public String getCarName() {
        return CarName;
    }

    public void setCarName(String carName) {
        CarName = carName;
    }

    public double getCarPrice() {
        return CarPrice;
    }

    public void setCarPrice(double carPrice) {
        CarPrice = carPrice;
    }
}
package Prim;

//客车类
public class Bus extends Car {
    private int BusNum;// 载人数量

    public Bus(String Name, double Price, int BusNum) {
        super.setCarName(Name);
        super.setCarPrice(Price);
        this.setBusNum(BusNum);
    }

    public int getBusNum() {
        return BusNum;
    }

    public void setBusNum(int busNum) {
        BusNum = busNum;
    }

    @Override
    public String toString() {
        return this.getCarName() + "\t" + this.getCarPrice() + "元/天\t载人" + BusNum + "人";

    }
}
package Prim;

//货车类
public class Truck extends Car {
    private int TruckNum;// 载货量

    public Truck(String CarName, double CarPrice, int TruckNum) {
        super.setCarName(CarName);
        super.setCarPrice(CarPrice);
        this.setTruckNum(TruckNum);
    }

    public int getTruckNum() {
        return TruckNum;
    }

    public void setTruckNum(int truckNum) {
        TruckNum = truckNum;
    }

    @Override
    public String toString() {
        return this.getCarName() + "\t" + this.getCarPrice() + "元/天\t载人" + TruckNum + "人";
    }
}
package Prim;

//皮卡的类
public class Pickup extends Car {
    private int BusNum;// 载人数量
    private int TruckNum;// 载货数量

    public Pickup(String CarName, double CarPrice, int BusNum, int TruckNum) {
        super.setCarName(CarName);
        super.setCarPrice(CarPrice);
        this.setBusNum(BusNum);
        this.setTruckNum(TruckNum);
    }

    public int getBusNum() {
        return BusNum;
    }

    public void setBusNum(int busNum) {
        BusNum = busNum;
    }

    public int getTruckNum() {
        return TruckNum;
    }

    public void setTruckNum(int truckNum) {
        TruckNum = truckNum;
    }

    @Override
    public String toString() {
        return this.getCarName() + "\t" + this.getCarPrice() + "元/天\t载人" + BusNum + "人" + TruckNum + "吨";
    }

}
package Prim;

import java.util.Scanner;
import java.io.*;

public class Lease extends Car {

    public static void main(String[] args) {
        // TODO 自动生成的方法存根
        int FinalPrice = 0;// 总价格
        int FinalBusNum = 0;// 总载人数
        int FinalTruckNum = 0;// 总载货量
        System.out.println("欢迎使用智障租车系统\n想证明自己不是智障请扣1");// 这段可能有问题
        Scanner input = new Scanner(System.in);
        if (input.nextInt() != 1) {
            System.out.println("你还真是个智障,再会!");
            input.close();
            return;
        }
        System.out.println("您可租车的类型及其价目表:\n序号\t汽车名称\t租金\t容量");
        Bus car1 = new Bus("奥迪A4", 500, 4);// 实例化对象
        Bus car2 = new Bus("马自达6", 400, 4);// 其实这里可以改成人工后台输入数据
        Bus car3 = new Bus("金龙", 800, 20);
        Truck car4 = new Truck("松花江", 400, 4);
        Truck car5 = new Truck("依维柯", 1000, 20);
        Pickup car6 = new Pickup("皮卡雪6", 450, 4, 2);
        Car cars[] = { car1, car2, car3, car4, car5, car6 };
        // 下面展示车辆信息
        for (int i = 0; i < cars.length; i++) {
            System.out.println((i + 1) + ".\t" + cars[i].toString());
        }
        System.out.println("告诉我你想租几辆");
        int CarNum = input.nextInt();
        int car[] = new int[CarNum];// 开个CarNum大小的数组(这算不算C++的动态数组)
        for (int i = 0; i < CarNum; i++) {
            System.out.println("告诉我你的租车序号");
            int LeaseNum = input.nextInt();
            if (LeaseNum >= 1 && LeaseNum <= 6)
                car[i] = LeaseNum;
            else
                System.out.println("小店只有六辆车,怎么输自己看着办");
        }
        for (int i = 0; i < car.length; i++) {
            switch (car[i]) {
            case 1:
                FinalBusNum += car1.getBusNum();// 累加载人数
                FinalPrice += car1.getCarPrice();// 累加价格
                break;

            case 2:
                FinalBusNum += car2.getBusNum();// 累加载人数
                FinalPrice += car2.getCarPrice();// 累加价格
                break;

            case 3:
                FinalBusNum += car3.getBusNum();// 累加载人数
                FinalPrice += car3.getCarPrice();// 累加价格
                break;

            case 4:
                FinalTruckNum += car4.getTruckNum();// 累加载人数
                FinalPrice += car4.getCarPrice();// 累加价格
                break;

            case 5:
                FinalTruckNum += car5.getTruckNum();// 累加载人数
                FinalPrice += car5.getCarPrice();// 累加价格
                break;

            case 6:
                FinalTruckNum += car6.getTruckNum();// 累加载人数
                FinalPrice += car6.getCarPrice();// 累加价格
                break;
            }
        }
        System.out.println("告诉我你想租几天");
        int LeaseDays = input.nextInt();
        System.out.println("看看你的账单");
        System.out.println("共载人:" + FinalBusNum);
        System.out.println("共载货:" + FinalTruckNum + "吨");
        System.out.println("***租车总价格:" + FinalPrice * LeaseDays);
        System.out.println("请在十五分钟内汇款到支付宝账户");
        System.out.println("或者给我微信转账");
        input.close(); // 关闭用户输入
    }
}
1
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:100120次
    • 积分:5078
    • 等级:
    • 排名:第5716名
    • 原创:414篇
    • 转载:6篇
    • 译文:0篇
    • 评论:42条
    最新评论