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

租车系统核心代码功能

DreamChaser2016
关注TA
已关注
手记 1
粉丝 1
获赞 1
package com.imooc;

import java.util.Scanner;

public class CarRent {
    static Car[] cars = { new Manned(1, "奥迪A4", 500, 4), new Manned(2, "马自达6", 400, 4),
            new PickUp(3, "皮卡雪6", 450, 4, 2), new Manned(4, "金龙", 800, 20), new CargoCar(5, "松花江", 400, 4),
            new CargoCar(6, "依维柯", 1000, 20) };

    public void show() {
        for (Car i : cars) {
            System.out.println(i);
        }
    }

    public static void Calulate(int carnum) {   //carnum用户输入的租车数量
        int[] carn = new int[carnum];           //根据用户输入的租车数量建立对应大小的数组
        for (int i = 1; i < carnum + 1; i++) {  
            System.out.println("请输入第" + i + "辆车的序号:");
            Scanner sc3 = new Scanner(System.in);
            carn[i - 1] = sc3.nextInt() - 1;    //将用户输入的车辆序号存到carn数组中
        }
        System.out.println("请输入租车天数:");
        Scanner sc4 = new Scanner(System.in);
        int day = sc4.nextInt();
        System.out.println("您的账单:");
        System.out.println("***可载人的车有:");
        int TotalManned = 0;
        int TotalCargo = 0;
        int TotalPrice = 0;
        for (int i = 0; i < carn.length; i++) { //计算对应载人车量的载人数
            if (cars[carn[i]] instanceof Manned || cars[carn[i]] instanceof PickUp) {
                TotalManned += cars[carn[i]].getManned();
                System.out.print(cars[carn[i]].getName() + "\t");
            }
        }
        System.out.println("共载人:" + TotalManned + "人");
        System.out.println("***可载货的车有:");
        for (int i = 0; i < carn.length; i++) {
            if (cars[carn[i]] instanceof CargoCar || cars[carn[i]] instanceof PickUp) {
                TotalCargo += cars[carn[i]].getCargo();
                System.out.print(cars[carn[i]].getName() + "\t");
            }
        }
        System.out.println("共载货:" + TotalCargo + "吨");
        for (int i = 0; i < carn.length; i++) {
            TotalPrice += cars[carn[i]].getPrice();
        }
        System.out.println("***租车总价格:" + TotalPrice * day + "元");
    }
}
打开App,阅读手记
1人推荐
发表评论
随时随地看视频慕课网APP