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

答答租车 新手表示好难

慕粉3490021
关注TA
已关注
手记 1
粉丝 0
获赞 11
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("您输入的不是整数,再见");
    }
}

}

打开App,阅读手记
5人推荐
发表评论
随时随地看视频慕课网APP

热门评论

厉害了我的弟。。。。。

Java程序里除了注释最好不要有汉字,给变量还有类命名的时候尽量见名知义

不要注意这些小节,好好领悟

查看全部评论