package rentcar;
public class Car {
private String name;
private int price;
private int capacity;
private double load;
public Car(String name, int price, int capacity) {
super();
this.name = name;
this.price = price;
this.capacity = capacity;
}
public Car(String name, int price, int capacity, double load) {
super();
this.name = name;
this.price = price;
this.capacity = capacity;
this.load = load;
}
public Car(String name, int price, double load) {
super();
this.name = name;
this.price = price;
this.load = load;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getPrice() {
return price;
}
public void setPrice(int price) {
this.price = price;
}
public double getCapacity() {
return capacity;
}
public void setCapacity(int capacity) {
this.capacity = capacity;
}
public double getLoad() {
return load;
}
public void setLoad(double load) {
this.load = load;
}
}
package rentcar;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
public class RentSystem {
Scanner scan=new Scanner(System.in);
public List<Car> choosecar;
public RentSystem()
{
this.choosecar=new ArrayList<Car>();
}
public void MakeList()
{
Car car[]={new Car("奥迪A4",500,4),new Car("马自达6",400,4),new Car("皮卡雪6",450,4,2.0),new Car("金龙",800,20),
new Car("松花江",400,4.0),new Car("依维柯",1000,20.0)};
choosecar.addAll(Arrays.asList(car));
}
public void ShowList()
{
System.out.println("序号\t"+"汽车名称\t\t"+"租金\t\t"+"容量\t\t");
System.out.println("1.\t"+choosecar.get(0).getName()+"\t\t"+choosecar.get(0).getPrice()+"元/天\t\t"+"载人:"+choosecar.get(0).getCapacity()+"人");
System.out.println("2.\t"+choosecar.get(1).getName()+"\t\t"+choosecar.get(1).getPrice()+"元/天\t\t"+"载人:"+choosecar.get(1).getCapacity()+"人");
System.out.println("3.\t"+choosecar.get(2).getName()+"\t\t"+choosecar.get(2).getPrice()+"元/天\t\t"+"载人:"+choosecar.get(2).getCapacity()+"人"+"载货:"+choosecar.get(2).getLoad()+"吨");
System.out.println("4.\t"+choosecar.get(3).getName()+"\t\t"+choosecar.get(3).getPrice()+"元/天\t\t"+"载人:"+choosecar.get(3).getCapacity()+"人");
System.out.println("5.\t"+choosecar.get(4).getName()+"\t\t"+choosecar.get(4).getPrice()+"元/天\t\t"+"载货:"+choosecar.get(4).getLoad()+"吨");
System.out.println("6.\t"+choosecar.get(5).getName()+"\t\t"+choosecar.get(5).getPrice()+"元/天\t"+"载货:"+choosecar.get(5).getLoad()+"吨");
}
public void Rent()
{ String name=null ;
String name2=null;
int totalprice=0;
int totalcapacity=0;
double totalload=0;
System.out.println("请输入你要租车的数量");
try {
int in2=scan.nextInt();
for(int i=0;i<in2;i++)
{
System.out.println("请输入第"+(i+1)+"辆车的序号");
{
try {
int in3=scan.nextInt();
if(in3>=1&&in3<=4)
{
name+=choosecar.get(in3-1).getName();
if(in3==3)
name2+=choosecar.get(in3-1).getName();
}
}
else
{
name2+=choosecar.get(in3-1).getName();
}
totalprice+=choosecar.get(in3-1).getPrice();
totalcapacity+=choosecar.get(in3-1).getCapacity();
totalload+=choosecar.get(in3-1).getLoad();
} catch (Exception e) {
System.out.println("输入错误,请重新输入");
scan=new Scanner(System.in);
}
}
}
} catch (Exception e) {
System.out.println("输入错误,请重新输入");
scan=new Scanner(System.in);
}
System.out.println("请输入你租车的天数:");
int in4=scan.nextInt();
System.out.println("可载人的车有:"+name);
System.out.println("共载人:"+totalcapacity+"人");
System.out.println("可载货的车有:"+name2);
System.out.println("共载货:"+totalload+"吨");
System.out.println("租车总价格为:"+totalprice*in4+"元");
}
public static void main(String[] args) {
System.out.println("欢迎进入答答租车系统!");
Scanner scan=new Scanner(System.in);
while(true)
{
System.out.println("你是否要租车:0:是;1:否");
try {
int in1=scan.nextInt();
if(in1==1)
{
return;
}
if(in1==0){
break;
}
else{
System.out.println("输入错误,请重新输入");
scan=new Scanner(System.in);
}
} catch (Exception e) {
System.out.println("输入错误,请重新输入");
scan=new Scanner(System.in);
}
}
System.out.println("您可租车的类型及其价目表:");
RentSystem rs=new RentSystem();
rs.MakeList();
rs.ShowList();
rs.Rent();
}
}