汽车租赁

萝らか妹 提交于 2019-11-28 22:43:09
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]);
    }
}

 

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!