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

建立一个简单的答答租车系统

慕少8724786
关注TA
已关注
手记 1
粉丝 2
获赞 0

package com.CarDemo;
import java.util.*;

public class Car {
Scanner count =new Scanner(System.in);
public void Sense(int line){
if(line==1){
System.out.println("您可租车的价目表和类型:"+"\n序号 车型 价格 容量\n"

  • "1. 奥迪A4 500元/天 载人:4人\t\n"
  • "2. 马自达6 400元/天 载人:4人\t\n"
  • "3. 皮卡雪6 450元/天 载人:4人 载货:2吨\t\n"
  • "4. 金龙 800元/天 载人:20人\t\n"
  • "5. 松花江 400元/天 载货:20吨\t\n"
  • "6. 依维柯 1000元/天 载货:20吨\t\n");
    }
    }
    String[] stely={"奥迪A4","马自达6","皮卡雪6","金龙","松花江","依维柯"};
    int[] money = {500,400,450,800,400,1000};
    int[] person = {4,4,4,20,0,0};
    int[] weight = {0,0,2,0,20,20};
    int[] stely1 = new int[6];
    int pos = 0;
    public void setCar(int num){
    for(int x = 1;x<=num;x++){
    System.out.println("请输入第"+x+"辆车的序号:");
    int temp = count.nextInt();
    stely1[pos++]=temp-1;
    }
    //System.out.println(pos);
    }
    public void printAccount(int num1){
    int personNum = 0;
    int weightNum = 0;
    int sum = 0;
    System.out.println("****可载人的车有:");
    for(int y = 0; y<pos;y++){
    if(person[stely1[y]]!=0){
    System.out.print(stely[stely1[y]]+"\t");
    personNum = personNum+person[stely1[y]];
    }

        }
        System.out.println("共载人:"+personNum+"人");
        System.out.println("****可载货的车有:");
        for(int y = 0; y<pos;y++){
        if(weight[stely1[y]]!=0){
            System.out.print(stely[stely1[y]]+"\t");
            weightNum = weightNum + weight[stely1[y]];
        }
    
        }
        System.out.println("共载货:"+weightNum+"吨");
        for(int x = 0 ; x<pos;x++){
            sum =sum + money[stely1[x]] ;
        }
    
        System.out.println("****租车总价格:"+num1*sum+"元");
    }

}
package com.CarDemo;
import java.util.Scanner;
public class CarTest {

public static void main(String[] args) {
    // TODO Auto-generated method stub
    Car p = new Car();
    System.out.println("欢迎使用答答租车系统");
    System.out.println("------------------------");
    System.out.println("您是否要租车:"+"\n1、是"+"\t2、不是\n");
    Scanner con = new Scanner(System.in);
    int line = con.nextInt();
    p.Sense(line);
    System.out.println("请输入您要租汽车的数量:\n");
    int num = con.nextInt();
    p.setCar(num);
    System.out.println("请输入租车天数:");
    int num1 = con.nextInt();
    p.printAccount(num1);
}

}

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