首页 > 代码库 > 汽车租赁

汽车租赁

import java.util.Scanner;
class Java继承 
{
    public static void main(String[] args) 
    {
        Company company = new Company();
        company.name = "江工租赁公司";
        company.limousine = new Limousine();
        company.passengerCar = new PassengerCar();
        company.fun();
    }
}

class Company
{
    String name;
    Limousine  limousine;
    PassengerCar passengerCar;
    public void fun(){
        System.out.println("\t\t欢迎你拉来到"+name);
        System.out.println("\n\n本公司有:\n1.轿车\n2.客车");
        System.out.println("\n温馨提醒:输入1或2即可");
        Scanner sc = new Scanner(System.in);
        System.out.print("\n请输入你想租赁的车种: ");
        int car = sc.nextInt();
        switch(car){
            case 1 : limousine.l();break;
            case 2 : passengerCar.p();break;
            default : System.out.print("\n你的输入有误!");
        }        
    }
    public void rent(int price){
        Scanner sc = new Scanner(System.in);
        System.out.print("\n请输入你想租赁多少天: ");
        int days = sc.nextInt();
        System.out.println("\n你好!租赁总价为: "+price*days);
    }
}

class Limousine extends Company
{
    String[] model;
    int[] price;
    public void l(){
        String[] str = {"1.别克商务舱GL8","2.宝马550i","3.别克林荫大道"};
        int [] number = {600,500,300};
        model = str;
        price = number;
        System.out.println("\n轿车拥有的车型编号如下:");
        for (String i:model)
        {
            System.out.println("\n"+i);
        }
        
        System.out.print("\n请输入你想租赁的车型编号: ");
        Scanner sc = new Scanner(System.in);
        int temp = sc.nextInt()-1;
        rent(price[temp]);
    }
}

class PassengerCar extends Company
{
    String[] model;
    int[] price;
    public void p(){
        String[] str = {"1.金杯客车","2.金龙客车"};
        int [] number = {800,1500};
        model = str;
        price = number;
        System.out.println("\n客车拥有的车型编号如下:");
        for (String i:model)
        {
            System.out.println("\n"+i);
        }
        
        System.out.print("\n请输入你想租赁的车型编号: ");
        Scanner sc = new Scanner(System.in);
        int temp = sc.nextInt()-1;
        rent(price[temp]);
    }
}

 

汽车租赁