为了账号安全,请及时绑定邮箱和手机立即绑定

福尔摩灰_Java入门第二季_租车系统

标签:
Java
public abstract class Car {
    public String name;
    public int price;
    public void pr(){
        System.out.println(name + "\t" + price + "元/天\t");
    }
}
public class PeopleCar extends Car {
    public int people ;
    @Override
    public void pr() {
        // TODO 自动生成的方法存根
        System.out.println(name + "\t" + price + "\t载人量:" + people +"人");
    }

    public PeopleCar(String s,int a,int b)
    {
        this.name = s;
        this.price = a;
        this.people = b;
        }
}
public class PickUp extends Car {
    public int people ;
    public int goods;
    @Override
    public void pr() {
        // TODO 自动生成的方法存根
        System.out.println(name + "\t" + price + "\t载人量:" + people  +"人" +",载货量:"+goods +"吨");
    }
    public PickUp(String a,int b,int c,int d) {
        // TODO 自动生成的构造函数存根

        this.name = a;
        this.price = b;
        this.people = c;
        this.goods = d;
    }

}
public class Truck extends Car {
    public int goods;//载货量
    @Override
    public void pr() {
        // TODO 自动生成的方法存根
        System.out.println(name + "\t" + price + "\t载货量:" + goods +"吨");
    }
    public Truck(String s,int a,int b)
    {
        this.name = s;
        this.price = a;
        this.goods = b;
    }
}
import java.util.Scanner;

public class Test {

    public static void main(String[] args) {
        // TODO 自动生成的方法存根
        Test test = new Test();
        Car[] car={
            new PeopleCar("奥迪A4",500,4),
            new PeopleCar("马自达6", 400,4),
            new PickUp("皮卡雪6", 450, 4, 2),
            new PeopleCar("金龙", 800, 20),
            new Truck("松花江", 400, 4),
            new Truck("依维柯", 1000, 20),
        };
        int weather;
        int number,a;
        int day;
        int sum = 0;
        Scanner input = new Scanner(System.in);
        System.out.println("是否租车?1.是  0.不是");
        weather = input.nextInt();
        if(weather == 1)
        {
            System.out.println("可租的汽车类型及价格表");
            System.out.println("序号\t汽车名称\t租金\t容量\t");
            for(int i = 0;i<6;i++)
            {
                System.out.print( (i+1) + "\t" );
                car[i].pr();
            }
            System.out.println("请输入您要租的车辆数:");
            number = input.nextInt();
            for(int i = 0; i<number; i++)
            {
                System.out.println("请输入要选的车的序号:");
                a=input.nextInt();
                sum += car[a-1].price;
            }
            System.out.println("请输入租车天数:");
            day = input.nextInt();
            System.out.println("总的租金为:" + day*sum +"元");
        }
        else{System.out.println("退出租车系统");}
    }
}
点击查看更多内容
2人点赞

若觉得本文不错,就分享一下吧!

评论

作者其他优质文章

正在加载中
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦
今天注册有机会得

100积分直接送

付费专栏免费学

大额优惠券免费领

立即参与 放弃机会
意见反馈 帮助中心 APP下载
官方微信

举报

0/150
提交
取消