???又水?说好的反射呢?说好的泛型数组列表呢?鸽了,鸽了,就是这么任性。
package 租车系统;
import java.util.Scanner;
/**
*1轿车
* 奥迪Q3 500元/天
* 奥迪Q7 700元/天
* 宝马X3 200元/天
* 奥拓A1 300元/天
*
* 2.客车
* 金杯12坐 小于等于16座,800元/天
* 金龙24座 大于等于16座,1200元/天
*/
public class Test {
public static void main(String[] args) {
System.out.println("******************************租车系统***********************");
Scanner input = new Scanner(System.in);
Person person = new Person();
System.out.println("请输入你的姓名:");
person.setName(input.next());
System.out.println("请输入你的联系方式:");
person.setPhone(input.next());
int i = 0;
motorVehicles[] motor = new motorVehicles[100];
while (true){
System.out.println("---------------------------------------");
System.out.println("请输入想要租借的车型(1.轿车 2.客车 0.退出");
int chioce = input.nextInt();
if (chioce==1)
{
System.out.println("请选着车辆(1.奥迪Q3 2.奥迪Q7 3.宝马X3 4.奥拓A1");
int num = input.nextInt();
switch (num)
{
case 1:
motor[i++] = new Car("皖A11111","奥迪",carCountant.AUDI_Q3);
break;
case 2:
motor[i++] = new Car("皖A22222","奥迪",carCountant.AUDI_Q7);
break;
case 3:
motor[i++] = new Car("皖A33333","宝马",carCountant.BMW_X3);
break;
case 4:
motor[i++] = new Car("皖A44444","奥拓",carCountant.ALTO_A1);
break;
}
}
else if (chioce==2)
{
System.out.println("请选啧车辆:(1.金杯 2.金龙 3.退出");
int num = input.nextInt();
switch (num){
case 1:
motor[i++] = new Bus("皖A55555","金杯12座",12);
break;
case 2:
motor[i++] = new Bus("皖A66666","金龙24座",24);
break;
}
}
else if (chioce == 0)
{
break;
}
else {
System.out.println("输入有误");
}
}
System.out.println("请输入租借天数:");
int day = input.nextInt();
System.out.println("-----------------------------------------------");
System.out.println("客户"+ person.getName() + "您租的车辆信息如下:");
System.out.println("车牌号\t\t品牌");
System.out.println("-----------------------------------------------");
double totalMoney = 0.0;
for (int j = 0; j < i; j++)
{
totalMoney += motor[j].calcRant(day);
System.out.println(motor[j].getNo() + "\t\t" +motor[j].getMultitude());
}
System.out.println("租借天数:"+ day +"天\t总租金:"+totalMoney);
}
}
package 租车系统;
public class carCountant {
public static final String AUDI_Q3 = "Q3";
public static final String AUDI_Q7 = "Q7";
public static final String BMW_X3 = "X3";
public static final String ALTO_A1 = "A1";
}
package 租车系统;
public abstract class motorVehicles {
String multitude;
String no;
public motorVehicles(String multitude, String no) {
}
public String getMultitude() {
return multitude;
}
public void setMultitude(String multitude) {
this.multitude = multitude;
}
public String getNo() {
return no;
}
public void setNo(String no) {
this.no = no;
}
public abstract int calcRant(int day);
}
package 租车系统;
public class Car extends motorVehicles{
private String type;
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public Car(String no,String multitude,String type) {
super(no,multitude);
this.type = type;
}
double sum = 0;
public int calcRant(int day)
{
if (type.equals(carCountant.AUDI_Q3))
{
sum = 500*day;
}
if(type.equals(carCountant.AUDI_Q7))
{
sum=700*day;
}
if (type.equals(carCountant.BMW_X3))
{
return 300*day;
}
if (type.equals(carCountant.ALTO_A1))
{
return 800*day;
}
return 0;
}
}
package 租车系统;
public class Car extends motorVehicles{
private String type;
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public Car(String no,String multitude,String type) {
super(no,multitude);
this.type = type;
}
double sum = 0;
public int calcRant(int day)
{
if (type.equals(carCountant.AUDI_Q3))
{
sum = 500*day;
}
if(type.equals(carCountant.AUDI_Q7))
{
sum=700*day;
}
if (type.equals(carCountant.BMW_X3))
{
return 300*day;
}
if (type.equals(carCountant.ALTO_A1))
{
return 800*day;
}
return 0;
}
}
package 租车系统;
public class Bus extends motorVehicles{
private int seatCount = 0;
public int getSeatCount() {
return seatCount;
}
public void setSeatCount(int seatCount) {
this.seatCount = seatCount;
}
public Bus(String no,String multitude , int seatCount) {
super(no,multitude);
this.seatCount = seatCount;
}
double sum = 0;
public int calcRant(int day) {
if (seatCount <= 16)
{
sum = 800*day;
}
if (seatCount>16)
{
sum = 1600*day;
}
return 0;
}
}