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

答答租车 新手表示好难

标签:
Java
package com.dada;

import java.util.*;

public class 欢迎 {

String[] a = { "奥迪A4", "马自达6", "皮卡雪", "金龙", "松花江", "依维柯" };
int[] b = { 500, 400, 450, 800, 400, 1000 };
int[] c = { 4, 4, 4, 20, 0, 0 };
int[] d = { 0, 0, 2, 0, 4, 20 };
int people = 0, thing = 0, price = 0;
String[] h = new String[4];

public void work()

{
    System.out.println("您是否要租车:1.是   2.否");
    Scanner input = new Scanner(System.in);
    int welcome = input.nextInt();
    if (welcome != 1) {
        System.out.println("感谢使用,再见");
    } else {
        System.out.println("您可租车的类型及价目表:");
        System.out.println("序号\t汽车名称\t租金\t容量");
        for (int i = 0; i < 6; i++) {
            System.out.println(i + 1 + "\t" + a[i] + "\t" + b[i] + "\t载客数:" + c[i] + "   货运数:" + d[i]);
        }
        System.out.println("请输入您需要的车辆数");

        Scanner input4 = new Scanner(System.in);
        int carnum = input4.nextInt();
        if (carnum < 1) {
            System.out.println("您的输入不正确");

        } else {

            int[] num = new int[carnum];
            for (int j = 0; j < carnum; j++) {
                System.out.println("请输入第" + (j + 1) + "辆车的序号");

                Scanner input2 = new Scanner(System.in);
                int number = input2.nextInt();

                if (number < 1  number > 6) {
                    System.out.println("您的输入有误\n");
                    j--;
                    continue;
                } else
                    num[j] = number;
                people += c[num[j] - 1];
                thing += d[num[j] - 1];
                price += b[num[j] - 1];
            }

            System.out.println("请输入租车天数");

            Scanner input3 = new Scanner(System.in);
            int day = input3.nextInt();
            System.out.println("您的账单:\n");
            System.out.println("您载人的车有:");

            for (int l = 0; l < carnum; l++) {

                if (c[num[l] - 1] != 0) {
                    System.out.print(a[num[l] - 1] + "\t");

                }

            }
            System.out.print("共计" + people + "人\t");
            System.out.println("\n");
            System.out.println("您载货的车有:");
            for (int m = 0; m < carnum; m++) {

                if (d[num[m] - 1] != 0) {

                    System.out.print(a[num[m] - 1] + "\t");
                }

            }
            int pricetotal = price * day;
            System.out.print("共可载" + thing + "吨货");
            System.out.println("\n");
            System.out.print("租车总价格" + pricetotal + "\t");
        }

    }

}

public static void main(String[] args) {

    System.out.println("欢迎使用嗒嗒租车系统");
    欢迎 workbegin = new 欢迎();
    try {
        workbegin.work();
    } catch (InputMismatchException exception) {
        System.out.println("您输入的不是整数,再见");
    }
}

}

点击查看更多内容
5人点赞

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

评论

作者其他优质文章

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

100积分直接送

付费专栏免费学

大额优惠券免费领

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

举报

0/150
提交
取消