Java配车标识英文单词怎么写,我写的Java入门第二季那个答答租车系统(感谢慕友提的意见,改了一下)...

该博客展示了如何使用Java创建一个租车系统,包括Car、Truck、Bus和PickUp类,每个类都有相应的属性和方法。测试类中提供了用户交互界面,允许用户选择不同类型的车辆并计算租车费用和载客/载货量。程序还处理了输入错误的情况,并在最后输出租车详情和总费用。
摘要由CSDN通过智能技术生成

感谢两位慕友提的意见,加了一点进去,但还是感觉对这个程序的完善没有做好,由于自己的水平有限,所以只能做到这个地步了

//Car父类(加了一个返回车名的方法)

public class Car{

private String type;

private float rentmoney;

public Car(String type, float rentmoney) {

this.type = type;

this.rentmoney = rentmoney;

}

public float Sum(int day) {

return day * this.rentmoney;

}

public String ReturnType() {

return this.type+" ";

}

}

//Truck类(特有属性 载货量burden,所以加了一个返回这个载货量的方法)

public class Truck extends Car{

private float burden;

public Truck(String type, float rentmoney, float burden) {

super(type, rentmoney);

this.burden=burden;

}

public float ReturnBurden() {

return this.burden;

}

}

//Bus类(特有属性 载客量 busload,加了个返回这个属性的方法)

public class Bus extends Car{

private int busload;

public Bus(String type, float rentmoney, int busload) {

super(type, rentmoney);

this.busload=busload;

}

public int ReturnBusload() {

return this.busload;

}

}

//PickUp类(特有属性 载客量,载货量,也加了返回这两个属性的方法)

public class PickUp extends Car{

private int busload;

private float burden;

public PickUp(String type, float rentmoney, int busload, float burden) {

super(type, rentmoney);

this.busload=busload;

this.burden=burden;

}

public int ReturnBusload() {

return this.busload;

}

public float ReturnBurden() {

return this.burden;

}

}

//包含主函数的测试类(

import java.util.Scanner;

public class Test {

public static void main(String[] args) {

// TODO Auto-generated method stub

int num=0, per=0, flag=0;

float sum=0, huo=0;

String person="", huowu="", choice="", se="";

System.out.println("欢迎使用答答租车系统!");

System.out.println("租车请输入1 输入其它字符将退出程序");

Scanner input=new Scanner(System.in);

choice=input.next();

if ("1".equals(choice)) {

System.out.println("以下是所有你可租的车辆:");

System.out.println("序号 汽车名称 租金\t 容量");

System.out.println("1. 奥迪A4 500元/天\t 载人:4人");

System.out.println("2. 马自达6 400元/天\t 载人:4人");

System.out.println("3. 皮卡雪6 450元/天\t 载人:4人 载货:2吨");

System.out.println("4. 金龙 800元/天\t 载人:20人");

System.out.println("5. 松花江 400元/天\t 载货:4吨");

System.out.println("6. 依维柯 1000元/天 载货:20吨");

System.out.println("请输入您要租汽车的数量:(仅能输入整数!)");

num=input.nextInt();

for (int i=0; i

System.out.println("请输入第"+(i+1)+"辆车的序号:");

se=input.next();

switch(se) {

case "1":

Bus bus=new Bus("奥迪A4", 500, 4);

sum += bus.Sum(1);

per += bus.ReturnBusload();

person += bus.ReturnType();

break;

case "2":

Bus bus1=new Bus("马自达6", 400, 4);

sum += bus1.Sum(1);

per += bus1.ReturnBusload();

person += bus1.ReturnType();

break;

case "3":

PickUp pika=new PickUp("皮卡雪", 450, 4, 2);

per += pika.ReturnBusload();

huo += pika.ReturnBurden();

sum += pika.Sum(1);

person += pika.ReturnType();

huowu += pika.ReturnType();

break;

case "4":

Bus bus2=new Bus("金龙", 800, 20);

per += bus2.ReturnBusload();

sum += bus2.Sum(1);

person += bus2.ReturnType();

break;

case "5":

Truck truck=new Truck("松花江", 400, 4);

huo += truck.ReturnBurden();

sum += truck.Sum(1);

huowu += truck.ReturnType();

break;

case "6":

Truck truck1=new Truck("依维柯", 1000, 20);

sum += truck1.Sum(1);

huo += truck1.ReturnBurden();

huowu += truck1.ReturnType();

break;

default:

flag++;

System.out.println("很抱歉,您本次的输入有误,系统将默认这次序号为空,请下次注意");

continue;

}

}

System.out.println("请输入租车天数:");

int day=input.nextInt();

sum *= day;

System.out.println("您的账单:");

if (flag!=0)

System.out.println("注:由于您有"+flag+"次输入有误,故只显示您输入正确的订单");

System.out.println("***可载人的车有:");

if (per == 0)

System.out.println();

else

System.out.println(person+" 共载人:"+per+"人");

System.out.println("***载货的车有:");

if (huo == 0)

System.out.println();

else

System.out.println(huowu+"共载货:"+huo+"吨");

System.out.println("***租车总价格:"+sum+"元");

}

System.out.println("感谢您的使用!");

input.close();

}

}

主要是动了测试类那里,但动的不多,不好意思

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值