JAVA 第二季项目作业-租车系统

第一次完成JAVA项目作业,花了近4个小时
弄懂了CMD下的运行和eclips下运行的不一样
父类CAR

package car_demo;

public  class car {
    // 车的属性
     String Car_id; // 车牌号
     String Car_nm; // 汽车名
     String Car_kind; // 类别
     int P_qty; // 最大载客数
     double C_qty; // 最大载货量
     double Price; // 日单价
     void Set_Car_id(String V_Car_id){
        this.Car_id = V_Car_id;
    }
     void Set_Car_nm(String V_Car_nm){
        this.Car_nm = V_Car_nm;
    }
     void Set_Car_kind(String V_Car_kind){
        this.Car_kind = V_Car_kind;
    }
     void Set_P_qty(int V_P_qty){
        this.P_qty = V_P_qty;
    }
     void Set_C_qty(double V_C_qty){
        this.C_qty = V_C_qty;
    }
     void Set_Price(double V_Price){
        this.Price = V_Price;
    }
     String Get_Car_id(){
        return Car_id ;
    }
     String Get_Car_nm(){
        return Car_nm ;
    }
     String Get_Car_kind(){
        return Car_kind ;
    }
     int Get_P_qty(){
        return P_qty ;
    }
     double Get_C_qty(){
        return C_qty;
    }
     double Get_Price(){
        return Price ;
    }
}

子类
1、Car_Per载人

package car_demo;

public class Car_Per extends car {
    // 载人车的属性
    private String Car_id; // 车牌号
    private String Car_nm; // 汽车名
    private String Car_kind="1"; // 类别
    private int P_qty; // 最大载客数
    private double Price; // 日单价
    public Car_Per(String Car_id,String Car_nm,int P_qty,double Price){
        this.Car_id = Car_id;
        this.Car_nm = Car_nm;
        this.Car_kind ="1";
        this.P_qty = P_qty;
        this.Price = Price;     
    }
    public void Set_Car_id(String V_Car_id){
        this.Car_id = V_Car_id;
    }
    public void Set_Car_nm(String V_Car_nm){
        this.Car_nm = V_Car_nm;
    }
    public void Set_Car_kind(String V_Car_kind){
        this.Car_kind = V_Car_kind;
    }
    public void Set_P_qty(int V_P_qty){
        this.P_qty = V_P_qty;
    }
    public void Set_C_qty(double V_C_qty){
        this.C_qty = V_C_qty;
    }
    public void Set_Price(double V_Price){
        this.Price = V_Price;
    }
    public String Get_Car_id(){
        return Car_id ;
    }
    public String Get_Car_nm(){
        return Car_nm ;
    }
    public String Get_Car_kind(){
        return Car_kind ;
    }
    public int Get_P_qty(){
        return P_qty ;
    }
    public double Get_C_qty(){
        return C_qty;
    }
    public double Get_Price(){
        return Price ;
    }
}

2、Car_G载货

package car_demo;

public class Car_G extends car {
    // 载货车的属性
    private String Car_id; // 车牌号
    private String Car_nm; // 汽车名
    private String Car_kind; // 类别
    private int P_qty; // 最大载客数
    private double Price; // 日单价
    public Car_G(String Car_id,String Car_nm,int C_qty,double Price){
        this.Car_id = Car_id;
        this.Car_nm = Car_nm;
        this.Car_kind ="2";
        this.C_qty = C_qty;
        this.Price = Price;
    }
    public void Set_Car_id(String V_Car_id){
        this.Car_id = V_Car_id;
    }
    public void Set_Car_nm(String V_Car_nm){
        this.Car_nm = V_Car_nm;
    }
    public void Set_Car_kind(String V_Car_kind){
        this.Car_kind = V_Car_kind;
    }
    public void Set_P_qty(int V_P_qty){
        this.P_qty = V_P_qty;
    }
    public void Set_C_qty(double V_C_qty){
        this.C_qty = V_C_qty;
    }
    public void Set_Price(double V_Price){
        this.Price = V_Price;
    }
    public String Get_Car_id(){
        return Car_id ;
    }
    public String Get_Car_nm(){
        return Car_nm ;
    }
    public String Get_Car_kind(){
        return Car_kind ;
    }
    public int Get_P_qty(){
        return P_qty ;
    }
    public double Get_C_qty(){
        return C_qty;
    }
    public double Get_Price(){
        return Price ;
    }
}

3、Car_T载人及货

package car_demo;

public class Car_T extends car {
    // 载人、载货车的属性
    private String Car_id; // 车牌号
    private String Car_nm; // 汽车名
    private String Car_kind="3"; // 类别
    private int P_qty; // 最大载客数
    private double C_qty; // 最大载货量
    private double Price; // 日单价
    public Car_T(String Car_id,String Car_nm,int P_qty,double C_qty,double Price){
        this.Car_id = Car_id;
        this.Car_nm = Car_nm;
        this.Car_kind ="3";
        this.P_qty = P_qty;
        this.C_qty = C_qty;
        this.Price = Price;
    }
    public void Set_Car_id(String V_Car_id){
        this.Car_id = V_Car_id;
    }
    public void Set_Car_nm(String V_Car_nm){
        this.Car_nm = V_Car_nm;
    }
    public void Set_Car_kind(String V_Car_kind){
        this.Car_kind = V_Car_kind;
    }
    public void Set_P_qty(int V_P_qty){
        this.P_qty = V_P_qty;
    }
    public void Set_C_qty(double V_C_qty){
        this.C_qty = V_C_qty;
    }
    public void Set_Price(double V_Price){
        this.Price = V_Price;
    }
    public String Get_Car_id(){
        return Car_id ;
    }
    public String Get_Car_nm(){
        return Car_nm ;
    }
    public String Get_Car_kind(){
        return Car_kind ;
    }
    public int Get_P_qty(){
        return P_qty ;
    }
    public double Get_C_qty(){
        return C_qty;
    }
    public double Get_Price(){
        return Price ;
    }
}

三、主程序

package car_demo;
import java.util.Scanner;
public class Car_Test {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
         car[] cars={       new Car_Per("00001","JEEP自由光",5,1500),
                                  new Car_Per("00002","富士康",5,600),
                                  new Car_Per("00003","依维柯",18,2300),
                                  new Car_Per("00004","金杯",36,5000),
                                  new Car_G("10001","大解放",2800,800),
                                  new Car_G("10002","后八轮",32000,5000),
                                  new Car_T("20001","大皮卡",5,28000,2000),
                                  new Car_T("20002","小皮卡",2,3200,1500)};
        System.out.println("欢迎您使用答答租车系统");
        System.out.println("您是否租车:1 是  0 否");
        Scanner v_input = new Scanner(System.in);
        int is = v_input.nextInt();
        if(is==1){           
            System.out.println("您可租车的类型和日价格表如下:");
            System.out.println("类别          车牌号      车名             最大载客数       最大载货量        日租金价格");
            for(int i=0;i<cars.length;i++){
                if(cars[i].Get_Car_kind()=="1"){
                    System.out.print(cars[i].Get_Car_kind()+"载人         ");
                    System.out.print(cars[i].Get_Car_id()+"      ");
                    System.out.print(String.format("%1$-20s",cars[i].Get_Car_nm()));
                    System.out.print(cars[i].Get_P_qty()+"                             ");
                    System.out.println(cars[i].Get_Price());
                }else if(cars[i].Get_Car_kind()=="2"){
                    System.out.print(cars[i].Get_Car_kind()+"载货         ");
                    System.out.print(cars[i].Get_Car_id()+"      ");
                    System.out.print(String.format("%1$-20s",cars[i].Get_Car_nm()));
                    System.out.print("             "+cars[i].Get_C_qty()+"           ");
                    System.out.println(cars[i].Get_Price());
                }else if(cars[i].Get_Car_kind()=="3"){
                    System.out.print(cars[i].Get_Car_kind()+"载人及货     ");
                    System.out.print(cars[i].Get_Car_id()+"      ");
                    System.out.print(String.format("%1$-20s",cars[i].Get_Car_nm()));
                    System.out.print(cars[i].Get_P_qty()+"            ");
                    System.out.print(cars[i].Get_C_qty()+"           ");
                    System.out.println(cars[i].Get_Price()); 
                }       
            }
            System.out.println("请输入您租车的数量:");
            Scanner v_input2 = new Scanner(System.in);
            int qty = v_input2.nextInt();
            String[] car_re = new String[qty];
            if(qty>0 && qty<=8){
                for(int i=0;i<=qty-1;i++){
                    System.out.println("请输入第"+(i+1)+"辆车的号码:");
                    Scanner v_input3 =new Scanner(System.in);
                    String v_car = v_input3.next();
                    car_re[i] = v_car;
                }
                System.out.println("请输入您要租的天数:");
                Scanner v_input3 = new Scanner(System.in);
                int day = v_input3.nextInt();
                System.out.println("您的账单如下:");
                int max_p =0;
                double max_g =0;
                double amt =0;
                System.out.println("类别          车牌号      车名             最大载客数       最大载货量        日租金价格");
                for(int i=0;i<cars.length;i++){

                    for (int j=0;j<car_re.length;j++){
                        if(cars[i].Get_Car_id().equals(car_re[j])){
                            switch(cars[i].Get_Car_kind()){
                                case "1":
                                    System.out.print(cars[i].Get_Car_kind()+"载人         ");
                                    break;
                                case "2":
                                    System.out.print(cars[i].Get_Car_kind()+"载货         ");
                                    break;
                                default:
                                    System.out.print(cars[i].Get_Car_kind()+"载人及货     ");
                                    break;
                            }
                            System.out.print(cars[i].Get_Car_id()+"      ");
                            System.out.print(String.format("%1$-20s",cars[i].Get_Car_nm()));
                            System.out.print(cars[i].Get_P_qty()+"            ");
                            System.out.print(cars[i].Get_C_qty()+"           ");
                            System.out.println(cars[i].Get_Price());  
                            max_p = max_p+cars[i].Get_P_qty();
                            max_g = max_g+cars[i].Get_C_qty();
                            amt = amt+cars[i].Get_Price()*day;
                        }
                    }
                }
                System.out.println();
                System.out.println();
                System.out.print("总载人数:"+max_p);
                System.out.print("          总载货重量:"+max_g);
                System.out.println("        总金额:"+amt);
            }else{
                System.out.println("您输入的租车数量不符合要求!");
            }

        }else {
            System.out.println("感谢您使用答答租车系统!"); 
        }
    }

}
点赞