package cn.form1;
import java.util.Scanner;
//import java.util.Arrays;
public class Runmain {
private static Scanner scanner;
public static void main(String[] args) {
int isrental = 0;
int carcount = 0;
int cardays = 0;
int car_total = 0;
String strs = "";
scanner = new Scanner(System.in);
System.out.println("欢迎使用租车系统:");
System.out.println("您是否要租车?1是、0否");
isrental = scanner.nextInt();
if(isrental == 0){
System.out.println("欢迎下次光临!!!");
}else if(isrental == 1){
Car[] arrcar = new Car[3];
arrcar[0] = new Aodi(1,"奥迪",600,5);
arrcar[1] = new Pika(2,"皮卡",300,3,2);
arrcar[2] = new Sohujang(3,"花江",200,5);
System.out.println("可租车的类型与价格表:");
System.out.println("序号 名称 租金 容量");
for(int i = 0; i < arrcar.length; i++){
Car car = arrcar[i];
if(car.goods != 0) strs = "载货:" + car.goods + "吨";
if(car.persons != 0) strs = "载人:" + car.persons + "个";
if(car.persons != 0 && car.goods != 0) strs = "载人:" + car.persons + "个, 载货:" + car.goods + "吨";
System.out.println(car.id + " " + car.name + " " + car.price + "元/每天 " + strs);
}
System.out.println("输入您要租车数量:");
carcount = scanner.nextInt();
int[] input = new int[carcount];//保存客户输入的序号
Car[] newcar = new Car[carcount];//存放客户选择的车
if(carcount > arrcar.length){
System.out.println("超出可租车数量");
}else{
for(int i = 0; i < carcount; i++){
System.out.println("请输入第"+ (i + 1)+"辆的序号");
input[i] = scanner.nextInt();
}
System.out.println("请输租车天数:");
cardays = scanner.nextInt();
System.out.println("您的账单:");
for(int i = 0; i < arrcar.length; i++){
Car car = arrcar[i];
for(int l = 0; l < input.length; l++){
if(car.id == input[l]){
newcar[l] = car;//得到客户选择的车
}
}
}
String str_goods = "";
int good_count = 0;
String str_persons = "";
int person_count = 0;
for(int i = 0; i < newcar.length; i++){
Car car = newcar[i];
if(car.goods != 0){//载货
str_goods += car.name+" ";
good_count += car.goods;
}
if(car.persons != 0){//载人
str_persons += car.name+" ";
person_count += car.persons;
}
car_total += car.price * cardays;
}
System.out.println("****可载人的车如下:");
System.out.println(str_persons + "共载人:"+person_count+"人");
System.out.println("****可载货的车如下:");
System.out.println(str_goods+"共载货:"+good_count+"吨");
System.out.println("****总价格:" + car_total +"元");
}
}else{
System.out.println("输入错误");
}
}
}
打开App,阅读手记