/* Vehicle父类,包含Truck类、PassengerCar类、Pickup类
其中Truck父类,包含LightTruck类、HeavyTruck类
PassengerCar父类,包含Car类、Bus类
*/
package vehicle;
public abstract class Vehicle {
public String name;
public float rent = 0;
public int carry = 0;
public float load = 0;
}
package vehicle;
import java.util.Scanner;
public class Initail {
public static void main(String[] args) {
// TODO Auto-generated method stub
PassengerCar v1 = new Car();
v1.name = "奥迪A4";
v1.rent = 500;
v1.carry = 4;
PassengerCar v2 = new Car();
v2.name = "马自达6";
v2.rent = 400;
v2.carry = 4;
Pickup v3 = new Pickup();
v3.name = "皮卡雪6";
v3.rent = 450;
v3.carry = 4; v3.load = 2;
PassengerCar v4 = new Bus();
v4.name = "金龙";
v4.rent = 800;
v4.carry = 20;
Truck v5 = new LightTruck();
v5.name = "松花江";
v5.rent = 400;
v5.load = 4;
Truck v6 = new HeavyTruck();
v6.name = "依维柯";
v6.rent = 1000;
v6.load = 20;
System.out.println("欢迎使用答答租车系统:");
System.out.println("您可租车的类型及价目表:");
System.out.println("序号\t汽车名称\t租金/(元/天)\t载客量/人\t载重量/吨\t");
Vehicle[] v = {v1,v2,v3,v4,v5,v6};
int[] a = {1,2,3,4,5,6};
for(int i=0; i<6;i++) {
System.out.println(" "+a[i]+"\t"+" "+v[i].name+"\t"+" "+v[i].rent+"\t"+" "+v[i].carry+"\t"+" "+v[i].load+"\t");
}
int b;
Scanner sc = new Scanner(System.in);
do {
System.out.println("您是否要租车:1是 0否");
b = sc.nextInt();
}while(b!=1&&b!=0);
if(b == 0)
System.out.println("欢迎下次再来!");
if(b == 1) {
System.out.println("请输入您要租汽车数量:");
int c = sc.nextInt();
Vehicle[] d = new Vehicle[c];
int n;
for(int i=0;i<c;i++) {
System.out.println("请输入第" + (i+1) + "辆车的编号:(数字0-6)");
n = sc.nextInt();
d[i] = v[n-1];
}
System.out.println("请输入租车天数:");
int m = sc.nextInt();
float s=0;
for(int i=0;i<c;i++) {
s = s+d[i].rent;
}
System.out.println("您的账单:");
int t = 0;
System.out.println("可载人的车有:");
for(int i=0;i<c;i++) {
if(d[i] instanceof PassengerCar || d[i] instanceof Pickup) {
System.out.print(d[i].name+" ");
t = t + d[i].carry;
}
}
System.out.println("共载人:"+ t +"人");
float p = 0;
System.out.println("可载货的车有:");
for(int i=0;i<c;i++) {
if(d[i] instanceof Truck || d[i] instanceof Pickup) {
System.out.print(d[i].name+" ");
p = p + d[i].load;
}
}
System.out.println("共载重:"+ p +"吨");
System.out.println("租车总价格:"+s*m+"元");
}
}
}
点击查看更多内容
为 TA 点赞
评论
共同学习,写下你的评论
评论加载中...
作者其他优质文章
正在加载中
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦