package com.imooc2_6_1;
//基类car
public class car {
private String carName;// 车名
private double burden;// 载货量
private int mannedVolume;// 载人量
private int price;// 价格/日
public car(String carName, double burden, int mannedVolume, int price) {
this.carName = carName;
this.burden = burden;
this.mannedVolume = mannedVolume;
this.price = price;
System.out.println("carName:" + carName + ' ' + "burden:" + burden + "kg" + ' ' + "mannedVolume:" + mannedVolume + "人" + ' ' + "price:" + price + "元" + '\n');
}
}
package com.imooc2_6_1;
//载货车类
public class Truck extends car {
public Truck(String carName, double burden, int mannedVolume, int price) {
super(carName, burden, mannedVolume, price);
}
}
package com.imooc2_6_1;
//载人车
public class passengerCar extends car {
public passengerCar(String carName, double burden, int mannedVolume, int price) {
super(carName, burden, mannedVolume, price);
}
}
package com.imooc2_6_1;
//两用车
public class pickUp extends car{
public pickUp(String carName, double burden, int mannedVolume, int price) {
super(carName, burden, mannedVolume, price);
}
}
package com.imooc2_6_1;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
System.out.println("Welcome!");
System.out.println("是否租车:1是, 0否");
Scanner choice = new Scanner(System.in);
int q = choice.nextInt();
if(q == 1) {
System.out.println("您可租车的类型及价目表:");
car[] type = {new Truck("0货车", 1000.0, 2, 3000),
new passengerCar("1客车", 0.0, 18, 2000),
new pickUp("2两用车", 200.0, 4, 1000)};
System.out.println("请选择需要几种车辆类型");
int x = choice.nextInt();
int[] n = new int[x];
int[] m = new int[x];
for(int i = 0; i < x; ++i) {
System.out.println("请选择需要的车辆类型及其数量:");
n[i] = choice.nextInt();
m[i] = choice.nextInt();
}
int sum = 0;
for(int i = 0; i < x; ++i) {
if(n[i] == 0) {
sum += (3000 * m[i]);
}
else if(n[i] == 1) {
sum += (2000 * m[i]);
} else {
sum += (1000 * m[i]);
}
}
System.out.println("总共需支付金额" + sum + "元, 请支付!");
}
System.out.println("谢谢使用!");
}
}
欢迎大家指出错误与不足 谢谢~
点击查看更多内容
5人点赞
评论
共同学习,写下你的评论
评论加载中...
作者其他优质文章
正在加载中
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦