/*
* 需求:答答租车系统
* 功能:实现客户自主选择所租车辆数量、类型及租车天数,系统返回详细账单,包括可载人、载货的车型名称、总载量及总费用。
*作者:奋斗的小龟龟
* 注:新手程序,如有建议,欢迎交流
* */
package com.rentcar;
import java.util.Scanner;
public class Rentcar {
public static void main(String[] args) {
Scanner input1 = new Scanner(System.in);
System.out.println("欢迎使用答答租车系统!\n您是否要租车:1 是 0 否");
int conf=input1.nextInt();
if(conf == 1){
String[] name = {"奥迪A4","马自达6","皮卡雪6","金龙","松花江","依维柯"};
int[] car = {500,400,450,800,400,1000};
int[] perNum = {4,4,4,20,0,0};
int[] ton = {0,0,2,0,4,20};
System.out.println("您可租车的类型及价目表:\n序号\t汽车名称\t 租金\t 容量\t ");
for(int i = 1;i <= 6; i++)
System.out.println( i+".\t "+name[i-1]+"\t "+car[i-1]+"元/天\t"+"载人:"+perNum[i-1]+"人 "+"载货"+ton[i-1]+"吨\t");
Scanner input2 = new Scanner(System.in);
System.out.println("请输入您要租车的数量:");
int num = input2.nextInt();
Scanner input3 = new Scanner(System.in);
int price=0;
int peNum=0,allton=0;
int[] isub = new int[6];
for(int i = 1;i <= num; i++)
{
System.out.println("请输入第"+i+"辆车的序号:");
int j = input3.nextInt();
price+=car[j-1];
peNum+=perNum[j-1];
allton+=ton[j-1];
isub [i-1] = j;
}
Scanner input4 = new Scanner(System.in);
System.out.println("请输入租车天数:");
int day = input4.nextInt();
int pay;
pay = price * day;
System.out.println("您的账单:\n***可载人的车有:");
for(int i = 0,j=0;i < num;i++)
{
j=isub[i];
if(perNum[j-1] != 0)
//将角标装入isub[]中,通过角标判断载人还是载货
System.out.print(name[j-1]+" ");
}
System.out.println("共载人:"+peNum+"人");
System.out.println("***载货的车有:");
for(int i = 0,j=0;i < num;i++)
{
j=isub[i];
if(ton[j-1] != 0)
//将角标装入isub[]中,通过角标判断载人还是载货
System.out.print(name[j-1]+" ");
}
System.out.println("共载货:"+allton+"吨");
System.out.println("***租车总价格:"+pay+"元");
}
}
}
打开App,阅读手记