package rentCar.system; import java.util.Scanner; public class App { public static void main(String[] args) { App enterSystem = new App(); enterSystem.rentCarSystem(); } Car[] cI = {new Truck(1, "大货车", 2, 5, 300) //各车辆信息录入 , new Bus(2, "巴士", 50, 0, 200) , new Pickup(3, "皮卡", 2, 3, 100) , new Jaguar(4, "捷豹", 4, 0, 150)}; //询问是否需要租车 void rentCarSystem() { System.out.println("欢迎使用嗒嗒租车系统!"); System.out.println("请问您是否租车:1.是\t2.否"); Scanner input = new Scanner(System.in); int answer = input.nextInt(); if (answer == 1) { carInformation(); } else if(answer == 2) { System.out.println("谢谢使用!"); } else { System.out.println("输入有误!程序自爆!"); System.exit(0); } } //车辆信息 void carInformation(){ System.out.println("正在为您载入租车系统...\n"); System.out.println("=============\t\t车辆租用列表\t\t============="); System.out.println("序号\t车名\t载客量(人)\t载货量(吨)\t租金(元/天)"); for (int i = 0; i < cI.length; i++) { System.out.println(); System.out.println(cI[i].toString()); } System.out.println("=============\t\t欢迎使用本系统\t\t=============\n"); carRentNumber(); } //询问租车数量 void carRentNumber() { System.out.println("请问需要租几辆车?"); Scanner input = new Scanner(System.in); int answer = input.nextInt(); //得到租车数量值 carRentType(answer); //租车类型 } //询问租车类型 void carRentType(int num) { String[] name = new String[num]; //租用车辆名字 double totalRent = 0; //总租金 double totalBurden = 0; //总载货量 int totalBusload = 0; //总载客量 System.out.println("===================================================="); System.out.println("温馨提示:车辆序列号范围(1-" + cI.length + ")"); System.out.println("===================================================="); System.out.println(); for (int i = 1; i <= num; i++) { System.out.print("请输入租用第" + i + "辆车的序号:"); Scanner input = new Scanner(System.in); int id = input.nextInt(); //得到车辆ID序号 if (id <= cI.length && id >= 1) { totalRent += cI[id-1].rent; //得到全部租用车辆的总租金 totalBurden += cI[id-1].burden; //得到总载货量 totalBusload += cI[id-1].busload; //得到总载客量 name[i-1] = cI[id-1].name; //为数组name赋值 租用的车辆名 } else { System.out.println("输入有误!程序启动自爆!"); System.exit(0); } } double finalRent = carRentDay(totalRent); rentCarBill(name, totalBusload, totalBurden, finalRent); } //询问租车天数并返回租车总费用 double carRentDay(double total) { System.out.println("请输入您要租用的天数: "); Scanner input = new Scanner(System.in); int day = input.nextInt(); return total *= day; } //显示租用车辆名、 租用车辆总载客数、总载货量、总租金 void rentCarBill(String[] name, int busload, double burden, double rent) { System.out.println("正在为您生成租车清单...\n"); System.out.println("============= 本次租车清单 ============="); System.out.println("您租用以下车:\n"); for (int i =0; i < name.length; i++) { System.out.print(name[i] + "\t\t"); if ((i + 1) % 8 == 0) System.out.println("\n"); } System.out.println("\n\n总载客量: " + busload + " 人\t\t" + "总载货量: " + burden + " 吨\t" + "总费用: " + rent + " 元\n"); System.out.println("============= 欢迎再次使用 ============="); System.exit(0); } }
慕瓜9220888
wj903829182
William_Jing
相关分类