package com.imooc;
public class Rent {
int number;//序号
String name;//汽车名称
int rent;//租金
//容量
int room1;
double room2;
double room3;
//构造方法
public Rent(int number,String name,int rent,int room1) {
this.number=number;
this.name=name;
this.rent=rent;
this.room1=room1;
System.out.println(number+"."+name+rent+"元/天 "+" 载人:"+room1+"人");
}//只载人
public Rent(int number,String name,int rent,int room1,double room2) {
this.number=number;
this.name=name;
this.rent=rent;
this.room1=room1;
this.room2=room2;
System.out.println(number+"."+name+rent+"元/天 "+" 载人:"+room1+"人 "+" 载货: "+room2+"吨");
}//载人载货
public Rent(int number,String name,int rent,double room3) {
this.number=number;
this.name=name;
this.rent=rent;
this.room3=room3;
System.out.println(number+"."+name+rent+"元/天 "+" 载货: "+room3+"吨");
}//只载货
}
package com.imooc;
import java.util.Arrays;
import java.util.Scanner;
public class test2 {
@SuppressWarnings("null")
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner input =new Scanner(System.in);
System.out.println("欢迎使用嗒嗒租车系统!");
System.out.println("你是否要租车?1是 0否");
int a=input.nextInt();
if(a==1) {
System.out.println("你可租车的类型及价格表:");
System.out.println("序号 汽车名称 价格 容量");
Rent object1=new Rent(1," 奥迪A8 ",500,4);
Rent object2=new Rent(2," 马自达6 ",400,4);
Rent object3=new Rent(3," 皮卡雪6 ",450,4,2.0);
Rent object4=new Rent(4," 金龙 ",800,20);
Rent object5=new Rent(5," 松花江 ",400,4.0);
Rent object6=new Rent(6," 依维柯 ",1000,20.0);
}
System.out.print("请输入你要租车的数量:");
@SuppressWarnings("resource")
Scanner input1=new Scanner(System.in);
int b=input1.nextInt();
System.out.println("您要租车的数量是:"+b);
String car = null;
String carMessage1[] = new String [b] ;//用于存放载人的车
String carMessage2[] = new String [b] ;//用于存放载货的车
int money=0;
int people=0;
int sumMoney=0;
int sumPeople=0;
double capacity=0;
double sumCapacity=0;
for(int i=1,p=0;i<=b;i++,p++) {
int count =i;
System.out.println("请输入第"+count+"辆车的序号:");
@SuppressWarnings("resource")
Scanner input2=new Scanner(System.in);
int c=input2.nextInt();
switch(c) {
case 1:
money=500;people=4; car= "奥迪A8";
break;
case 2:
money=400;people=4;car="马自达6";
break;
case 3:
money=450;people=4;capacity=2.0;car="皮卡雪6";
break;
case 4:
money=800;people=20;car="金龙 ";
break;
case 5:
money=400;capacity=4.0;car="松花江 ";
break;
case 6:
money=1000;capacity=2.0;car="依维柯";
}
if(c!=5 && c!=6) {
carMessage1[p]=car;
}else {
carMessage2[p]=car;
}
sumMoney=money+sumMoney;
sumPeople=people+sumPeople;
sumCapacity=capacity+sumCapacity;
}
System.out.print("请输入租车天数:");
@SuppressWarnings("resource")
Scanner input3=new Scanner(System.in);
int d=input3.nextInt();
System.out.println("**你的账单如下**");
System.out.println("可载人的车有:");
System.out.println(Arrays.toString(carMessage1));
System.out.println("总载人数为:"+sumPeople);
System.out.println("可载货的车有:");
System.out.println(Arrays.toString(carMessage2));
System.out.println("总载货数为:"+sumCapacity);
System.out.println("租车总价格为:"+sumMoney*d);
}
}