手记

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

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);
}

}

0人推荐
随时随地看视频
慕课网APP