package com.dadaleasing;
import java.util.*;
public class InitialDaDaLeasing {
public static void main(String[] args) {
// TODO Auto-generated method stub
//输出基础界面代码块
Scanner input = new Scanner(System.in);
Face face = new Face(); //创建face引用指向Face类
face.showInitial(); //输出提示信息
if(input.nextInt() == 1){
;
}else{
System.out.println("欢迎您再次使用!");
return ;
}
face.showFace(); //在控制台上打印出基本的板块
//创建六种车对象,选择车代码块
CarLoad toyota = new Toyota();
CarLoad fordMustang = new FordMustang();
CarLoad hongdaGod = new HongdaGod();
CarLoad fordGod = new FordGod();
CarLoad mazda = new Mazda();
CarLoad carola = new Carola();
CarOption carOption = new CarOption(toyota, fordMustang, hongdaGod, fordGod, mazda, carola);
carOption.option();
System.out.println("请在购物车内结账");
System.out.println("******欢迎下次光临!******");
}
}
package com.dadaleasing;
//抽象类
public abstract class CarLoad {
public abstract int loading(); //用于给子类返回载货重量
public abstract int seating(); //用于给子类返回载人数量
public abstract double money(); //用于给子类返回租赁单价
}
package com.dadaleasing;
//在控制台上打印出基础界面
public class Face {
public void showInitial(){
System.out.println("******欢迎使用达达车辆租赁!*****");
System.out.println("租赁车辆请输入1,退出请输入其余任意数字");
}
public void showFace(){
System.out.println("================================================================================================");
System.out.println("以下为本公司车辆租赁的基本信息:");
System.out.printf("车辆编号 车辆类型 车辆品牌 车辆载客数量 车辆载货重量(kg) 租赁价格(rmb/天)\n");
System.out.printf("%4d 小轿车 丰田86 %4d %4d %9d\n", 1, 2, 0, 200);
System.out.printf("%4d 小轿车 福特野马 %7d %4d %9d\n", 2, 2, 0, 200);
System.out.printf("%4d 大货车 东风大力神 %6d %4d %9d\n", 3, 2, 50000, 1000);
System.out.printf("%4d 大货车 福特大力神 %6d %4d %9d\n", 4, 2, 60000, 1300);
System.out.printf("%4d 皮卡车 马自达 %12d %4d %7d\n", 5, 4, 800, 500);
System.out.printf("%4d 皮卡车 卡罗拉 %12d %4d %7d\n", 6, 4, 1000, 700);
}
}
package com.dadaleasing;
import java.util.*;
public class CarOption {
//定义六个Object类型变量用于保存从主函数接受的数据
CarLoad toyota;
CarLoad fordMustang;
CarLoad hongdaGod;
CarLoad carola;
CarLoad fordGod;
CarLoad mazda;
int intAllCarSums = 0; //定义一个变量用于统计租赁汽车总数
int intAllLoading = 0; //定义一个变量用于统计租赁汽车总共载货重量
int intAllSeating = 0; //定义一个变量用于统计租赁汽车的总载人数
int intAllMoney = 0; //定义一个变量用于统计租赁汽车总共需要花费的金额
int carSums = 0; //定义一个变量用于保存用户输入租赁的数量
int carDays = 0; //定义一个变量用于保存用户输入租赁的天数
//重写有参构造函数,用于从入口类中接受创建的对象
public CarOption(CarLoad newToyota, CarLoad newFordMustang, CarLoad newHongdaGod, CarLoad newCarola,
CarLoad newFordGod, CarLoad newMazda){
//将入口类中创建的对象与本类中的Object变量相对应的赋值
toyota = newToyota;
fordMustang = newFordMustang;
hongdaGod = newHongdaGod;
carola = newCarola;
fordGod = newFordGod;
mazda = newMazda;
}
void option(){
//租赁代码块
Scanner input = new Scanner(System.in);
for(int intKeyboard = 1; intKeyboard != 0;){
System.out.println("请输入要租赁车辆的编号,输入0结账:");
intKeyboard = input.nextInt();
switch(intKeyboard){
case 1 :{
System.out.println("请输入您想要租赁的数量:");
carSums = input.nextInt();
System.out.println("请输入您想要租赁的天数");
carDays = input.nextInt();
System.out.println("您想要租赁" + carSums + "辆丰田86共" + carDays + "天,一共可乘坐乘客" + (toyota.seating() * carSums) +
"人,一共可装载货物" + (toyota.loading() * carSums)+ "kg,一共需要花费" + (toyota.money() * carDays
* carSums) + "元人民币");
intAllLoading += (toyota.loading() * carSums);
intAllSeating += (toyota.seating() * carSums);
intAllMoney += (toyota.money() * carSums * carDays);
intAllCarSums += carSums;
};break;
case 2 :{System.out.println("请输入您想要租赁的数量:");
carSums = input.nextInt();
System.out.println("请输入您想要租赁的天数");
carDays = input.nextInt();
System.out.println("您想要租赁" + carSums + "福特野马共" + carDays + "天,一共可乘坐乘客" + (fordMustang.seating() * carSums) +
"人,一共可装载货物" + (fordMustang.loading() * carSums)+ "kg,一共需要花费" + (fordMustang.money() * carDays
* carSums) + "元人民币");
intAllLoading += (fordMustang.loading() * carSums);
intAllSeating += (fordMustang.seating() * carSums);
intAllMoney += (fordMustang.money() * carSums * carDays);
intAllCarSums += carSums;
};break;
case 3 :{System.out.println("请输入您想要租赁的数量:");
carSums = input.nextInt();
System.out.println("请输入您想要租赁的天数");
carDays = input.nextInt();
System.out.println("您想要租赁" + carSums + "辆东风大力神共" + carDays + "天,一共可乘坐乘客" + (hongdaGod.seating() * carSums) +
"人,一共可装载货物" + (hongdaGod.loading() * carSums)+ "kg,一共需要花费" + (hongdaGod.money() * carDays
* carSums) + "元人民币");
intAllLoading += (hongdaGod.loading() * carSums);
intAllSeating += (hongdaGod.seating() * carSums);
intAllMoney += (hongdaGod.money() * carSums * carDays);
intAllCarSums += carSums;
};break;
case 4 :{System.out.println("请输入您想要租赁的数量:");
carSums = input.nextInt();
System.out.println("请输入您想要租赁的天数");
carDays = input.nextInt();
System.out.println("您想要租赁" + carSums + "辆福特大力神共" + carDays + "天,一共可乘坐乘客" + (fordGod.seating() * carSums) +
"人,一共可装载货物" + (fordGod.loading() * carSums)+ "kg,一共需要花费" + (fordGod.money() * carDays
* carSums) + "元人民币");
intAllLoading += (fordGod.loading() * carSums);
intAllSeating += (fordGod.seating() * carSums);
intAllMoney += (fordGod.money() * carSums * carDays);
intAllCarSums += carSums;
};break;
case 5 :{System.out.println("请输入您想要租赁的数量:");
carSums = input.nextInt();
System.out.println("请输入您想要租赁的天数");
carDays = input.nextInt();
System.out.println("您想要租赁" + carSums + "辆马自达共" + carDays + "天,一共可乘坐乘客" + (mazda.seating() * carSums) +
"人,一共可装载货物" + (mazda.loading() * carSums)+ "kg,一共需要花费" + (mazda.money() * carDays
* carSums) + "元人民币");
intAllLoading += (mazda.loading() * carSums);
intAllSeating += (mazda.seating() * carSums);
intAllMoney += (mazda.money() * carSums * carDays);
intAllCarSums += carSums;
};break;
case 6 :{System.out.println("请输入您想要租赁的数量:");
carSums = input.nextInt();
System.out.println("请输入您想要租赁的天数");
carDays = input.nextInt();
System.out.println("您想要租赁" + carSums + "辆卡罗拉共" + carDays + "天,一共可乘坐乘客" + (carola.seating() * carSums) +
"人,一共可装载货物" + (carola.loading() * carSums)+ "kg,一共需要花费" + (carola.money() * carDays
* carSums) + "元人民币");
intAllLoading += (carola.loading() * carSums);
intAllSeating += (carola.seating() * carSums);
intAllMoney += (carola.money() * carSums * carDays);
intAllCarSums += carSums;
}
}
System.out.println("您当前租赁车辆共" + intAllCarSums + "辆,总共可以乘坐" + intAllSeating + "名乘客,可载物" + intAllLoading
+ "kg,总计消费" + intAllMoney + "元人民币");
}
System.out.println("================================================================================================================");
System.out.println("您总计租赁车辆共" + intAllCarSums + "辆,总共可以乘坐" + intAllSeating + "名乘客,可载物" + intAllLoading
+ "kg,总计消费" + intAllMoney + "元人民币");
}
}
package com.dadaleasing;
public class Toyota extends CarLoad {
private final int intLoading = 0;
private final int intSeating = 2;
private final int intMoney = 200;
@Override
public int loading() {
// TODO Auto-generated method stub
return intLoading;
}
@Override
public int seating() {
// TODO Auto-generated method stub
return intSeating;
}
@Override
public double money() {
// TODO Auto-generated method stub
return intMoney;
}
}
package com.dadaleasing;
public class FordMustang extends CarLoad {
private final int intLoading = 0;
private final int intSeating = 2;
private final int intMoney = 200;
@Override
public int loading() {
// TODO Auto-generated method stub
return intLoading;
}
@Override
public int seating() {
// TODO Auto-generated method stub
return intSeating;
}
@Override
public double money() {
// TODO Auto-generated method stub
return intMoney;
}
}
package com.dadaleasing;
public class HongdaGod extends CarLoad {
private final int intLoading = 5000;
private final int intSeating = 2;
private final int intMoney = 1000;
@Override
public int loading() {
// TODO Auto-generated method stub
return intLoading;
}
@Override
public int seating() {
// TODO Auto-generated method stub
return intSeating;
}
@Override
public double money() {
// TODO Auto-generated method stub
return intMoney;
}
}
package com.dadaleasing;
public class HongdaGod extends CarLoad {
private final int intLoading = 5000;
private final int intSeating = 2;
private final int intMoney = 1000;
@Override
public int loading() {
// TODO Auto-generated method stub
return intLoading;
}
@Override
public int seating() {
// TODO Auto-generated method stub
return intSeating;
}
@Override
public double money() {
// TODO Auto-generated method stub
return intMoney;
}
}
package com.dadaleasing;
public class Mazda extends CarLoad {
private final int intLoading = 4;
private final int intSeating = 800;
private final int intMoney = 500;
@Override
public int loading() {
// TODO Auto-generated method stub
return intLoading;
}
@Override
public int seating() {
// TODO Auto-generated method stub
return intSeating;
}
@Override
public double money() {
// TODO Auto-generated method stub
return intMoney;
}
}
package com.dadaleasing;
public class Carola extends CarLoad {
private final int intLoading = 1000;
private final int intSeating = 4;
private final int intMoney = 700;
@Override
public int loading() {
// TODO Auto-generated method stub
return intLoading;
}
@Override
public int seating() {
// TODO Auto-generated method stub
return intSeating;
}
@Override
public double money() {
// TODO Auto-generated method stub
return intMoney;
}
}
//程序能在MyEclipse2014上跑起来,但是在选车那里选编号4以后的车输出出来的信息就会混乱,编号6的车的信息会出现在编号5上,编号4的车的信息会出现在编号6上
//实在找不出哪里错了