手记

答答租车系统 (written by 王爽)

/***********************************************************************
 * Module:  Test.java
 * Author:  王爽
 * Purpose: Defines the Class Test
 ***********************************************************************/

import java.util.Scanner;

/** @pdOid 5a50094b-625a-4c9c-9516-5403b2350b0e */
public class Test {

    static Car[][]car={{new Bus("奥迪A4",500,4),new Bus("马自达6", 400, 4),new Bus("金龙", 800, 20)},{new Trunk("松花江", 400, 4),new Trunk("依维柯", 1000, 20)},{new PickUp("皮卡雪6", 450, 4, 2)}};

    public static void main(String[] args) {

        System.out.println("欢迎使用答答租车系统:"+'\n'+"您是否要租车:1、是 2、否");
        Scanner input=new Scanner(System.in);
        int k=1;
        int totalMoney=0,totalPassenger=0,totalCargo=0;
        while(true){
            int a=input.nextInt();
        if(a==1){
            System.out.println("您可租车辆及其价目表:");
            System.out.println("序号"+"\t"+"汽车名称"+"\t"+"租金"+"\t"+"容量");
            for(int i=0;i<=2;i++)
            for(int j=0;j<car[i].length;j++){
                System.out.println(k+"."+"\t"+car[i][j].getName()+"\t"+car[i][j].getMoney()+"\t"+"载人:"+car[i][j].getCarryNumber()+"人 载货:"+car[i][j].getCarryNumber2()+"吨");
                k++;
            }
            System.out.println("请输入您要租车的数量:");
            int n=input.nextInt();
            int[]b=new int[n];
            for(int i=0;i<n;i++){
                System.out.println("请输入第"+(i+1)+"辆车的序号");
                b[i]=input.nextInt();
                if(1<=b[i]&&b[i]<=3){
                    totalMoney+=car[0][b[i]-1].getMoney();
                    totalPassenger+=car[0][b[i]-1].getCarryNumber();
                }
                if(3<b[i]&&b[i]<=5){
                    totalMoney+=car[1][b[i]-1-car[0].length].getMoney();
                    totalCargo+=car[1][b[i]-1-car[0].length].getCarryNumber2();
                }
                if(b[i]==6){
                    totalMoney+=car[2][b[i]-1-car[0].length-car[1].length].getMoney();
                    totalPassenger+=car[2][b[i]-1-car[0].length-car[1].length].getCarryNumber();
                    totalCargo+=car[2][b[i]-1-car[0].length-car[1].length].getCarryNumber2();
                }
            }
            System.out.println("请输入租车天数:");
            int day=input.nextInt();
            totalMoney*=day;
            System.out.println("您的帐单:"+'\n'+"***可载人的车有:");
            for(int c:b){
                if(1<=c&&c<=3)
                    System.out.print(car[0][c-1].getName()+" ");
                if(c==6)
                    System.out.print(car[2][0].getName()+" ");
            }
            System.out.println("共载人:"+totalPassenger+"人");
            System.out.println("***载货的车有:");
            for(int c:b){
                if(3<c&&c<=5)
                    System.out.print(car[1][c-4].getName()+" ");
                if(c==6)
                    System.out.print(car[2][0].getName()+" ");
            }
            System.out.println("共载货:"+totalCargo+"吨");
            System.out.println("***租金/总价格:"+totalMoney+"元");
            break;
        }else if(a==2){
            System.out.println("感谢您的再次使用!再见!");
            break;
        }else{
            System.out.println("您输入的信息有误,请重新输入:");
            continue;
        }
        }

}
}
/***********************************************************************
 * Module:  Car.java
 * Author:  王爽
 * Purpose: Defines the Class Car
 ***********************************************************************/

import java.util.*;

/** @pdOid 7b8ae4ee-d956-4484-ad3a-d774bf14921e */
public class Car {
   /** @pdOid b698c56f-725e-4f49-ad5c-f4314387542b */
   private String name;
   /** @pdOid a63b35ef-7a0f-4718-83bf-73016743027b */
   private int money;
   private int carryNumber=0,carryNumber2;

public String getName() {
    return name;
}
public void setName(String name) {
    this.name = name;
}
public int getMoney() {
    return money;
}
public void setMoney(int money) {
    this.money = money;
}
public int getCarryNumber() {
    return carryNumber;
}
public void setCarryNumber(int carryNumber) {
    this.carryNumber = carryNumber;
}
public int getCarryNumber2() {
    return carryNumber2;
}
public void setCarryNumber2(int carryNumber2) {
    this.carryNumber2 = carryNumber2;
}

}
/***********************************************************************
 * Module:  Bus.java
 * Author:  王爽
 * Purpose: Defines the Class Bus
 ***********************************************************************/

import java.util.*;

/** @pdOid f81f99ed-3fed-4d44-9ca4-9c8f85ca79e9 */
public class Bus extends Car {

    public Bus(String name,int money,int carryNumber){
    this.setName(name);
    this.setMoney(money);
    this.setCarryNumber(carryNumber);

    }

}
/***********************************************************************
 * Module:  Trunk.java
 * Author:  王爽
 * Purpose: Defines the Class Trunk
 ***********************************************************************/

import java.util.*;

/** @pdOid f5485c3d-0607-48b8-9c66-4a4aa0424eaf */
public class Trunk extends Car {

    public Trunk(String name,int money,int carryNumber){
    this.setName(name);
    this.setMoney(money);
    this.setCarryNumber2(carryNumber);
    }

}

public class PickUp extends Car {

    public PickUp(String name,int money,int carryNumber,int carryNumber2){
    this.setName(name);
    this.setMoney(money);
    this.setCarryNumber(carryNumber);
    this.setCarryNumber2(carryNumber2);
    }

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

热门评论

怎么一点文字说明都没有啊

查看全部评论