主函数:
package 租车系统;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// 显示界面
System.out.println("欢迎使用答答租车系统!");
System.out.println("您是否需要租车:1是 2否");
Scanner scan = new Scanner (System.in);
int re = scan.nextInt();
int totalPrice = 0;
int totalPeople = 0;
int totalWeight = 0;
while(true){
if(re==2){
System.out.println("谢谢使用,欢迎下次光临!");
break;
}else if(re==1){
System.out.println("您可租车的类型及其价目表:");
System.out.println("序号\t汽车名称\t日租金\t载客\t载货");
Vehicle[] vehicles = {new Car("奥迪A4",4,500),
new Car("马自达6",4,400),
new Car("金龙",20,800),
new Pickup("皮卡雪6",450,2,4),
new Truck("松花江",400,4),
new Truck("依维柯",1000,20)};
for(int i=0;i<vehicles.length;i++) {
System.out.println((i+1)+".\t"+vehicles[i].name+"\t"
+vehicles[i].price+"\t"+vehicles[i].people+
"\t"+vehicles[i].weight);
}
System.out.println("请输入您要租车的数量:");
int num=scan.nextInt();
for(int j=0;j<num;j++) {
System.out.println("请输入您要租的第"+(j+1)+"辆车的序号:");
int zu=scan.nextInt();
System.out.println("您要租的是:"+vehicles[zu-1].name);
totalPrice = totalPrice+vehicles[zu-1].price;
totalPeople = totalPeople+vehicles[zu-1].people;
totalWeight = totalWeight +vehicles[zu-1].weight;
}
System.out.println("请输入您要租车的天数:");
int day = scan.nextInt();
totalPrice = totalPrice*day;
System.out.println("您的账单:");
System.out.println("总载客数为:"+totalPeople+"人");
System.out.println("总载货量为:"+totalWeight+"吨");
System.out.println("总价格为:"+totalPrice+"元");
break;
}else{
System.out.println("您的输入有误,请重新输入!");
break;
}
}
}
}车辆类(父类)
package 租车系统;
public class Vehicle {
//所有车辆的父类,要有所有车辆共有的属性
public int id;//车辆编号
public String name;//车辆名称
public int price;//日租金
public int people;//载人数量
public int weight;//载货量
}car类
package 租车系统;
public class Car extends Vehicle {
public Car(String name,int people,int price) {
this.name=name;
this.price=price;
this.people=people;
}
}truck类
package 租车系统;
public class Truck extends Vehicle {
public Truck(String name, int price, int weight) {
this.name=name;
this.price=price;
this.weight=weight;
}
}pickup类
package 租车系统;
public class Pickup extends Vehicle {
public Pickup(String name,int price,int people,int weight) {
this.name=name;
this.people=people;
this.price=price;
this.weight=weight;
}
}输出:
欢迎使用答答租车系统! 您是否需要租车:1是 2否 1 您可租车的类型及其价目表: 序号 汽车名称 日租金 载客 载货 1. 奥迪A4 500 4 0 2. 马自达6 400 4 0 3. 金龙 800 20 0 4. 皮卡雪6 450 2 4 5. 松花江 400 0 4 6. 依维柯 1000 0 20 请输入您要租车的数量: 3 请输入您要租的第1辆车的序号: 1 您要租的是:奥迪A4 请输入您要租的第2辆车的序号: 2 您要租的是:马自达6 请输入您要租的第3辆车的序号: 5 您要租的是:松花江 请输入您要租车的天数: 6 您的账单: 总载客数为:8人 总载货量为:4吨 总价格为:7800元
参照其他同学的,写的很简单。
继续努力!
点击查看更多内容
1人点赞
评论
共同学习,写下你的评论
评论加载中...
作者其他优质文章
正在加载中
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦