public class Vehicle { //父类
public String name;
public int capacity;//可容纳的乘客数量
public int load;//可装载的货物量
public int price;
public void sure(int sureNum){
//确认是否租车的方法
if(sureNum == 0){
System.out.println("小答提示:您已确认租车");
}
if(sureNum == 1){
System.out.println("小答提示:您已结束租车,欢迎下次再来");
}
}
}
package dadaRent;
import java.util.Scanner;
public class Bus extends Vehicle {
public int choice(int busNum){
System.out.println("小答提示:1.小型客车 2.大型客车");
System.out.print("小答提示:请输入车辆类型编号: ");
Scanner input = new Scanner(System.in);
busNum = input.nextInt();
if(busNum==1){
int mNum = 10;
System.out.println("小答提示:您选择了小型客车,剩余车辆:"+mNum);
minBus(mNum);
}
if(busNum == 2){
int mNum = 10;
System.out.println("小答提示:您选择了大型客车,剩余车辆:"+mNum);
maxBus(mNum);
}
input.close();
return 0;
}
public void minBus(int mNum){
int capacity = 10;
int price = 100;
System.out.println("小答提示:小型客车的载客量为:"+capacity+" 价格为:每辆车一天"+price+"元");
System.out.print("小答提示:请输入要租车的数量: ");
Scanner input = new Scanner(System.in);
int p = input.nextInt();
System.out.print("小答提示:请输入要租车的天数: ");
int day = input.nextInt();
minBusPrice(p,day);
int sureNum;
System.out.println("小答提示:是否确认租车:0.是 1.结束租车");
sureNum = input.nextInt();
sure(sureNum);
if(sureNum == 1){
}else{
mNum = mNum - p;
System.out.println("*小答提示*:您已成功租车,剩余车辆:"+mNum);
}
input.close();
}
public void maxBus(int mNum){
int capacity = 60;
int price = 200;
System.out.println("*小答提示*:大型客车的载客量为:"+capacity+ " 价格为:每辆车一天"+price+"元");
System.out.print("*小答提示*:请输入要租车的数量: ");
Scanner input = new Scanner(System.in);
int q = input.nextInt();
System.out.print("*小答提示*:请输入要租车的天数: ");
int day = input.nextInt();
maxBusPrice(q,day);
int sureNum;
System.out.println("*小答提示*:是否确认租车:0.是 1.结束租车");
sureNum = input.nextInt();
sure(sureNum);
if(sureNum == 1){
}
else{
mNum = mNum - q;
System.out.println("*小答提示*:您已成功租车,剩余车辆:"+mNum);
}
input.close();
}
public void minBusPrice(int q,int day){
int allPrice = 100*q*day;
System.out.println("*小答提示*:您需要支付"+allPrice+"元");
}
public void maxBusPrice(int q,int day){
int allPrice = 200*q*day;
System.out.println("*小答提示*:您需要支付"+allPrice+"元");
}
}
package dadaRent;
import java.util.Scanner;
public class Truck extends Vehicle {
public int tchoice(int truckNum){
System.out.println("小答提示:1.小型货车 2.大型货车");
System.out.print("小答提示:请输入车辆类型编号: ");
Scanner input = new Scanner(System.in);
truckNum = input.nextInt();
if(truckNum==1){
int mNum = 15;
System.out.println("小答提示:您选择了小型货车,剩余车辆:"+mNum);
minTruck(mNum);
}
if(truckNum == 2){
int mNum = 20;
System.out.println("小答提示:您选择了大型货车,剩余车辆:"+mNum);
maxTruck(mNum);
}
input.close();
return 0;
}
public void minTruck(int mNum){
int load =5;
System.out.println("小答提示:小型货车的载货量为:"+load+"t"+" 小型货车的价格为:每辆150元每天");
System.out.print("小答提示:请输入要租车的数量: ");
Scanner input = new Scanner(System.in);
int p = input.nextInt();
System.out.print("小答提示:请输入要租车的天数: ");
int day = input.nextInt();
minTruckPrice(p,day);
int sureNum;
System.out.println("小答提示:是否确认租车:0.是 1.结束租车");
sureNum = input.nextInt();
sure(sureNum);
if(sureNum == 1){
}else{
mNum = mNum - p;
System.out.println("*小答提示*:您已成功租车,剩余车辆:"+mNum);
}
input.close();
}
public void maxTruck(int mNum){
int load = 15;
System.out.println("*小答提示*:大型客车的载客量为:"+load+"t"+" 大型货车的价格为:每辆300元每天");
System.out.print("*小答提示*:请输入要租车的数量: ");
Scanner input = new Scanner(System.in);
int q = input.nextInt();
System.out.print("*小答提示*:请输入要租车的天数: ");
int day = input.nextInt();
maxTruckPrice(q,day);
int sureNum;
System.out.println("*小答提示*:是否确认租车:0.是 1.结束租车");
sureNum = input.nextInt();
sure(sureNum);
if(sureNum == 1){
}
else{
mNum = mNum - q;
System.out.println("*小答提示*:您已成功租车,剩余车辆:"+mNum);
}
input.close();
}
public void minTruckPrice(int q,int day){
int allPrice = 150qday;
System.out.println("小答提示:您需要支付"+allPrice+"元");
}
public void maxTruckPrice(int q,int day){
int allPrice = 300qday;
System.out.println("小答提示:您需要支付"+allPrice+"元");
}
}
package dadaRent;
import java.util.Scanner;
public class Bus_Truck extends Vehicle {
int price = 150;
int avaiNum = 20;
public void ss(){
System.out.println("小答提示:您选择了两用车,剩余车辆:"+avaiNum);
System.out.println("小答提示:该类型载货量为:"+"2t"+" 载客量为:"+avaiNum+" 价格为:每辆150元每天");
System.out.print("小答提示:请输入要租车的数量: ");
Scanner input = new Scanner(System.in);
int w = input.nextInt();
System.out.print("小答提示:请输入要租车的天数: ");
int day = input.nextInt();
doublePrice(w,day);
int sureNum;
System.out.println("小答提示:是否确认租车:0.是 1.结束租车");
sureNum = input.nextInt();
sure(sureNum);
if(sureNum == 1){
}else{
avaiNum =avaiNum - w;
System.out.println("*小答提示*:您已成功租车,剩余车辆:"+avaiNum);
}
input.close();
}
public void doublePrice(int q,int day){
int allPrice = 150qday;
System.out.println("小答提示:您需要支付"+allPrice+"元");
}
}
package dadaRent;
import java.util.Scanner;
public class Text {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("欢迎来到答答租车,小答将为您全程服务");
System.out.println("小答提示:请选择租车类型: 1.客车 2.货车 3.客、货双用车");
System.out.print("小答提示:请在此输入编号:");
Scanner mm = new Scanner(System.in);
int fNum = mm.nextInt();
if(fNum == 1){
Bus p1 = new Bus();
p1.choice(1);
}else if(fNum==2){
Truck p2 = new Truck();
p2.tchoice(1);
}else{
Bus_Truck p3 = new Bus_Truck();
p3.ss();
}
mm.close();
}
}
共同学习,写下你的评论
评论加载中...
作者其他优质文章