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

答答租车系统(大家一起进来学习,有不足的请大家提出来)

标签:
Java

package second;

public abstract class Car {
String name;
double price;
int seatingCapacity;
float carryCapacity;
}
package second;

public class Trust extends Car{
public Trust(String name, double price, float carryCapacity) {
this.name = name;
this.price = price;
this.carryCapacity = carryCapacity;
}

@Override
public String toString() {
    return name + "\t" + price + "元/天\t" + "载货:" + carryCapacity + "吨";
}

}
package second;

public class Bus extends Car{
public Bus(String name, double price, int seatingCapacity) {
this.name = name;
this.price = price;
this.seatingCapacity = seatingCapacity;

}

@Override
public String toString() {
    return name + "\t" + price + "元/天\t" + "载人:" + seatingCapacity + "人 ";
}

}
package second;

public class PickUp extends Car{
public PickUp(String name,double price,int seatingCapacity,float carryCapacity) {
this.name=name;
this.price=price;
this.seatingCapacity=seatingCapacity;
this.carryCapacity=carryCapacity;
}

@Override
public String toString() {
return name+"\t"+price+"元/天\t"+"载人:"+seatingCapacity+"人 "+"载货:"+carryCapacity+"吨";
}
}
package second;

import java.util.Scanner;

public class Initial {
public static void main(String[] args) {
Car[] car = { new Bus("奥迪A4", 500, 4), new Bus("马自达6", 400, 4), new PickUp("皮卡雪", 450, 4, 2),
new Bus("金龙", 800, 20), new Trust("松花江", 400, 4), new Trust("依维柯", 100, 20) };
System.out.println("欢迎试用答答租车系统:");
System.out.println("您是否要租车:1是 0否");
Scanner in = new Scanner(System.in);
int input = in.nextInt();
if (input == 1) {
System.out.println("您可租车的类型及其价目表:");
System.out.println("序号\t汽车名称\t租金\t\t容量");
for (int i = 0; i < car.length; i++) {
System.out.println((i + 1) + ".\t" + car[i]);
}

        String carCarry = "";
        String carPeople = "";
        float allCarry = 0;
        int allPeople = 0;
        double allPrice = 0;
        System.out.println("请输入您要租车的数量:");
        int count = in.nextInt();
        for (int i = 0; i < count; i++) {
            System.out.println("请输入第" + (i + 1) + "辆车的序号");
            int a = in.nextInt();
            System.out.println("该车为:" + car[i].name);
            System.out.println("请输入租车的天数:");
            int b = in.nextInt();
            if (car[i].seatingCapacity != 0) {
                carPeople += car[i].name+" " ;
                allPeople += car[i].seatingCapacity;
            }
            if (car[i].carryCapacity != 0) {
                carCarry += car[i].name+" " ;
                allCarry += car[i].carryCapacity;
            }
            allPrice += car[i].price * b;

        }
        System.out.println("您的账单:");
        System.out.println("****在载人的车有:\n" + carPeople);
        System.out.println("****在载货的车有:\n" + carCarry);
        System.out.print("总租金为:"+allPrice);
    } else
        return;
}

}

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

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

评论

作者其他优质文章

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

100积分直接送

付费专栏免费学

大额优惠券免费领

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

举报

0/150
提交
取消