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

java进阶.答答打车系统

标签:
Java 测试

继承的两个抽象类里面的两个抽象方法如下:

public abstract class Capacity{
public abstract int passengerCapacity(int e[], int d);
public abstract int carryingCapacity(int s[], int b);
}

主类调用并实现功能:

import java.util.Scanner;
public class Text extends Capacity{
    @Override
    public int passengerCapacity(int e[], int d){
        int humannumber=0;
        int money=0;
        int eeeee = 0,ee = 0, eee = 0, eeee= 0;
        for(int j = 0; j<d;j++){
            if(e[j] == 1){
                eeeee = eeeee+1;
                System.out.print("奥迪A4: "+ eeeee+"辆 ");
                humannumber = humannumber+4;
                money = money+500;
            }
            else if(e[j] == 2){
                ee = ee + 1;
                System.out.print("马自达6: "+ ee +"辆 ");
                humannumber = humannumber+4;
                money = money + 400;
            }
            else if(e[j] == 3 ){
                eee = eee +1;
                System.out.print("皮卡雪6: "+ eee+ "辆 ");
                humannumber = humannumber+4;
                money = money + 450;
            }
            else if(e[j] == 4 ){
                eeee = eeee +1;
                System.out.print("金龙: "+eeee +"辆  ");
                humannumber = humannumber+20;
                money = money + 800;
            }
        }
        System.out.print("总载客量为: ");
        System.out.println(humannumber);
        return money;
    }
    @Override
    public int carryingCapacity(int e[], int d){
        int goodsquantity=0;
        int money=0;
        int o =0,oo = 0, ooo = 0;
        for(int j = 0; j<d;j++){
            if(e[j] == 3){
                o = o+1;
                System.out.print("皮卡雪6: "+ o +"辆 ");
                goodsquantity = goodsquantity + 2;
            }
            else if(e[j] == 5){
                oo = oo+1;
                System.out.print("松花江: "+ oo +"辆 ");
                goodsquantity = goodsquantity + 4;
                money = money + 400;
            }
            else if(e[j] == 6 ){
                ooo = ooo+1;
                System.out.print("依维柯: "+ ooo +"辆 ");
                goodsquantity = goodsquantity + 200;
                money = money + 450;
            }
        }
        System.out.print("总载货量为: ");
        System.out.println(goodsquantity);
        return money;
    }
public static void main(String[] args){
System.out.println("您是否需要呼叫张宸打车系统:1需要,0不需要");
Scanner a = new Scanner(System.in);
int b = a.nextInt();
if(b == 1){
System.out.println("序号 汽车名称 租金      容量");
System.out.println(" 1   奥迪A4   500元/天  载人:4人");
System.out.println(" 2   马自达6  400元/天  载人:4人");
System.out.println(" 3   皮卡雪6  450元/天  载人:4载货:2吨");
System.out.println(" 4   金龙     800元/天  载人:20人");
System.out.println(" 5   松花江   400元/天  载货:4吨");
System.out.println(" 6   依维柯   1000元/天 载货:200吨");
System.out.println("请输入您要选车辆数:");
Scanner c = new Scanner(System.in);
int d = c.nextInt();
int[] e = new int[d];
    int k = 0;
    for(int i =0 ; i<d;i++){
        k=i+1;
        System.out.println("请输入您要选择的第"+ k +"辆车的序号");
        Scanner f = new Scanner(System.in);
        e[i]= f.nextInt();
    }
    int z = 0;
    Text text = new Text();
    z = text.passengerCapacity(e,d) + text.carryingCapacity(e,d);
    System.out.println("总价钱为: " + z);
}
}
}

图片描述

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

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

评论

作者其他优质文章

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

100积分直接送

付费专栏免费学

大额优惠券免费领

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

举报

0/150
提交
取消