java基礎第二季,噠噠租車系統

gamebus發表於2021-09-09

測試類(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;
    }

}

執行結果

圖片描述

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/4687/viewspace-2807535/,如需轉載,請註明出處,否則將追究法律責任。

相關文章