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

答答租车系统代码分享

标签:
Java
//Bus.java 抽象类表示车
package pratice1;
public abstract class Bus {
    public int rent;
    public String name;
    public abstract void showInformation();
    public Bus(int rent,String name){
        this.rent = rent;
        this.name = name;
    }
    public int getRent() {
        return rent;
    }
}
//PasserBus.java 载客车类
package pratice1;
public class PasserBus extends Bus{
    private int busload_person;
    public void showInformation(){
        System.out.println(name+"  "+ rent +"/天"+"     "+"载人:"+busload_person+"人");
    }
    public PasserBus(int r,String n,int per){
        super(r,n);
        this.busload_person = per;
    }
}
//GoodBus.java 载物车类
package pratice1;
public class GoodBus extends Bus{
    private int busload_good;
    public void showInformation(){
        System.out.println(name +"     "+rent+"/天"+"    "+"载货:"+busload_good+"吨");
    }
    public GoodBus(int r,String n,int g){
        super(r,n);
        busload_good = g;
    }
}
//Pickup.java 载客又载物车类
package pratice1;
public class Pickup extends Bus {
    private int busload_passer;
    private int busload_good;
    public void showInformation(){
        System.out.println(name+"   "+rent+"/天"+"    "+"载人:"+busload_passer+"人   "+"载货:" +busload_good+"吨");
    }
    public Pickup(int r,String n,int p,int g){
        super(r,n);
        this.busload_passer = p;
        this.busload_good =g;
    }
}
//Test.java 入口类
package pratice1;
import java.util.*;
public class Test {
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Bus no1 = new PasserBus(500,"奥迪A4",4);
        Bus no2 = new PasserBus(400,"马自达",4);
        Bus no3 = new Pickup(450,"皮卡雪6",4,2);
        Bus no4 = new PasserBus(800,"金龙",20);
        Bus no5 = new GoodBus(400,"松花江",4);
        Bus no6 = new GoodBus(1000,"依维柯",20);
        Bus[] b = {no1,no2,no3,no4,no5,no6};
        Scanner input = new Scanner(System.in);
        System.out.println("欢迎使用答答租车胸膛:");
        System.out.println("您是否要租车:1是  0否");
        int t = input.nextInt();
        if(t == 1)
        {
            System.out.println("您可租车的类型及其价目表:");
            System.out.println("序号     汽车名称        租金                容量");
            for(int i = 0;i<b.length;i++){
                System.out.print((i+1)+".  ");
                b[i].showInformation();
            }
            System.out.println("请输入您要租汽车的数量");
            int num = input.nextInt();
            int sum = 0;
            for(int i = 0;i<num;i++){
                System.out.print("第"+(i+1)+"辆的序号是: ");
                int j = input.nextInt();
                System.out.print("租用天数:");
                int k = input.nextInt();
                sum = sum + b[j-1].getRent()*k;
            }
            System.out.println("总费用是:"+sum+"元");
        }
        else{
            System.out.println("谢谢光临");
        }   
    }
}

运行结果图如下
图片描述

点击查看更多内容
3人点赞

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

评论

作者其他优质文章

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

100积分直接送

付费专栏免费学

大额优惠券免费领

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

举报

0/150
提交
取消