java语言实现简易答答租车系统
- 1.项目背景介绍
- 2.项目分析
1.项目背景介绍
根据抽象类,编写一个控制台版的“答答租车系统”
功能:
- 展示所有可租车辆
- 选择车型、租车量
- 展示租车清单,包含:总金额,总载货量及其车型…
2.项目分析
- 数据模型分析
- 业务模型分析
- 显示和流程分析
在我们做任何项目之前都要对其进行详细分析,具体分析我就不在这里一一分析了,请看下列代码
第一步:我们需要写一个名为Car的抽象类,里面需要包含天数和车辆编号的属性
package com.imooc;
public abstract class Car {
public abstract void Days(int day);
public abstract void Vehicle_number(int num);
}
第二步:我们需要编写一个客车类并且继承Car类
package com.imooc;
public class Passenger_car extends Car {
int Smart_Num_car1;
int Smart_Days_car1;
int Big_Num_car1;
int Big_Days_car1;
@Override
public void Days(int day) {
this.Big_Days_car1=day;
this.Smart_Days_car1=day;
}
@Override
public void Vehicle_number(int num) {
this.Big_Num_car1=num;
this.Smart_Num_car1=num;
}
public int Smart_car() {
int moneyfrist=(500*Smart_Days_car1)*Smart_Num_car1;
return moneyfrist;
}
public int Big_car() {
int moneysecond=(800*Big_Days_car1)*Big_Num_car1;
return moneysecond;
}
}
第三步:我们需要编写一个皮卡车类并且继承Car类
package com.imooc;
public class Pickup extends Car {
int Num_car3;
int Days_car3;
@Override
public void Days(int day) {
// TODO 自动生成的方法存根
this.Days_car3=day;
}
@Override
public void Vehicle_number(int num) {
// TODO 自动生成的方法存根
this.Num_car3=num;
}
public int pickup_car() {
// TODO 自动生成的方法存根
int money=(1000*Days_car3)*Num_car3;
return money;
}
}
第四步:我们需要编写一个货车类并且继承Car类
package com.imooc;
public class Truck extends Car {
int Smart_Num_car2;
int Smart_Days_car2;
int Big_Num_car2;
int Big_Days_car2;
@Override
public void Days(int day) {
// TODO 自动生成的方法存根
this.Big_Days_car2=day;
this.Smart_Days_car2=day;
}
@Override
public void Vehicle_number(int num) {
// TODO 自动生成的方法存根
this.Big_Num_car2=num;
this.Smart_Num_car2=num;
}
public int Smart_truck_car() {
// TODO 自动生成的方法存根
int moneyfrist=(4500*Smart_Days_car2)*Smart_Num_car2;
return moneyfrist;
}
public int Big_truck_var() {
// TODO 自动生成的方法存根
int moneysecond=(10000*Big_Days_car2)*Big_Num_car2;
return moneysecond;
}
}
第五步:编写主类,实现调用;
package com.imooc;
import java.util.Scanner;
public class Main_page {
@SuppressWarnings("resource")
public static void main(String[] args) {
Main_page main_page = new Main_page();
Passenger_car passenger_car = new Passenger_car();
Truck truck = new Truck();
Pickup pickup = new Pickup();
while (true) {
System.out.println("欢迎使用答答租车系统:");
System.out.println("----------------");
System.out.println(" 您是否需要租车:");
System.out.println("---1.是---2.否---");
Scanner scanner = new Scanner(System.in);
int Vaule = scanner.nextInt();
if (Vaule == 1) {
main_page.Tips();
} else {
break;
}
System.out.println("请输入您要租汽车的数量:");
Scanner scanner1 = new Scanner(System.in);
int Vaule1 = scanner1.nextInt();
System.out.println("同一型号的车需要多少辆:");
Scanner scanner2 = new Scanner(System.in);
int num = scanner2.nextInt();
System.out.println("请输入租车天数:");
Scanner Time = new Scanner(System.in);
int Time_car = Time.nextInt();
Scanner inPut = new Scanner(System.in);
int array1[] = new int[Vaule1];
int array2[] = new int[Vaule1];
int Vaule2 = 0;
int sum=0;
String name[]=new String[5];
for (int i = 0; i < array1.length; i++) {
System.out.println("请输入第" + (i + 1) + "辆车的序号");
array2[i] = inPut.nextInt();
Vaule2 = array2[i];
if (Vaule2 == 1) {
passenger_car.Days(Time_car);
passenger_car.Vehicle_number(num);
sum=sum+passenger_car.Smart_car();
String name_Smart_car="奥迪";
name[0]=name_Smart_car;
}
else if (Vaule2 == 2) {
passenger_car.Days(Time_car);
passenger_car.Vehicle_number(num);
sum=sum+passenger_car.Big_car();
String name_Big_car="金龙";
name[1]=name_Big_car;
}
else if (Vaule2 == 3) {
truck.Days(Time_car);
truck.Vehicle_number(num);
sum=sum+truck.Smart_truck_car();
String name_Smart_truck_car="小货车";
name[2]=name_Smart_truck_car;
}
else if (Vaule2 == 4) {
truck.Days(Time_car);
truck.Vehicle_number(num);
sum=sum+truck.Big_truck_var();
String name_Big_truck_car="大货车";
name[3]=name_Big_truck_car;
}
else if (Vaule2 == 5) {
pickup.Days(Time_car);
pickup.Vehicle_number(num);
sum=sum+pickup.pickup_car();
String name_pickup_car="皮卡";
name[4]=name_pickup_car;
}
}
System.out.println("****************");
System.out.println("一共需要付款:"+sum);
for(String name_arrays:name) {
if(name_arrays!=null) {
System.out.print("购买车辆:"+name_arrays+" ");
}
}
System.out.println();
System.out.println("****************");
}
}
public void Tips() {
System.out.println("您可租车的类型及其价目表:");
System.out.println("序号 汽车名称 租金 容量");
System.out.println("1. 奥迪 500元/天 载人:4人");
System.out.println("2. 金龙 800元/天 载人:20人");
System.out.println("3. 小货车 4500元/天 载重:4吨");
System.out.println("4. 大货车 10000元/天 载重:15吨");
System.out.println("5. 皮车 1000元/天 载人:4 载货:2吨");
}
}