java基础第二季,哒哒租车系统

测试类(main)

package com.imooc.rentcar;

import java.util.Scanner;

public class test01 {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner in = new Scanner(System.in);
        int number;
        Car[] car =new Car[7];
        Car[] rentcar;
        System.out.println("欢迎使用哒哒租车系统:您是否要租车? 1是0否");
        System.out.println();
        if(in.nextInt()==1){
            System.out.println("您可租车的类型及价目表:n"+
        "序号t汽车名称t租金t容量");

            car[1]=new LoadPersonCar("奥迪A4",500,4);
            car[2]=new LoadPersonCar("马自达6",400,4);
            car[3]=new PickUp("皮卡雪6",450,4,2);
            car[4]=new LoadPersonCar("金龙",800,20);
            car[5]=new LoadThingCar("松花江",400,4);
            car[6]=new LoadThingCar("依维柯",1000,20);
            for(int i=1;i

车的父类

package com.imooc.rentcar;

public class Car {
    String name;
    int price;
    int PersonNum;
    int ThingNum;
    public Car(String name,int price){
        this.name=name;
        this.price=price;
    }

}

载人车

package com.imooc.rentcar;

public class LoadPersonCar extends Car {

    public LoadPersonCar(String name, int price) {
        super(name, price);
        // TODO Auto-generated constructor stub
    }
    public LoadPersonCar(String name,int price,int PersonNum) {
        // TODO Auto-generated constructor stub
        this(name, price);
        this.PersonNum=PersonNum;
    }

}

载物车

package com.imooc.rentcar;

public class LoadThingCar extends Car {

    public LoadThingCar(String name, int price) {
        super(name, price);
        // TODO Auto-generated constructor stub
    }

    public LoadThingCar(String name,int price,int ThingNum) {
        // TODO Auto-generated constructor stub
        this(name, price);
        this.ThingNum=ThingNum;
    }

}

皮卡

package com.imooc.rentcar;

public class PickUp extends Car {

    public PickUp(String name, int price) {
        super(name, price);
        // TODO Auto-generated constructor stub
    }

    public PickUp(String name,int price,int PersonNum,int ThingNum) {
        // TODO Auto-generated constructor stub
        this(name, price);
        this.PersonNum=PersonNum;
        this.ThingNum=ThingNum;
    }

}

运行结果

图片描述

请使用浏览器的分享功能分享到微信等