亲们 怎么删除课程问答?
2 回答
好吧,为了不浪费,粘段代码做备用
import java.util.Scanner; /* * 哒哒租车系统 * 系统还有N多错误需要改正,先留做备用 */ public class DaDaTest { private Scanner scan;// 选项输入 private int carRental;// 租车服务选择 private String[][] car = { { "1.", "奥迪A4", "500", "4", "" }, { "2.", "马自达6", "400", "4", "" }, { "3.", "皮卡雪6", "450", "4", "2" }, { "4.", "金龙", "800", "20", "" }, { "5.", "松花江", "400", "", "4" }, { "6.", "依维柯", "1000", "", "20" } };//仿照数据存储 private int cars;// 输入的租车数量 private int days;//用来存放租车天数 private String carName1 = "";//可乘人汽车名称汇总 private String carName2 = "";//可装货汽车名称汇总 private int carPrice;// 汽车租金价格汇总 private int people;// 人数汇总 private int cargo;// 货物汇总 public static void main(String[] args) { // 实例化,用来调用其方法 DaDaTest dada = new DaDaTest(); dada.init(); } // 初始化系统,并询问是否使用哒哒租车系统 public void init() { System.out.println("欢迎使用哒哒租车系统:"); System.out.println("您是否要租车:1是 0否"); scan = new Scanner(System.in); carRental = scan.nextInt(); if (carRental == 0) { System.out.println("谢谢您的使用,谢谢,再见!"); } else if (carRental == 1) { price(); } else { System.out.println("对不起您输入的数据有误,请您重新输入!"); init();// 调用自身方法进行重新输入 } } // 出示租车价格表的方法 public void price() { System.out.println("您可租车的类型及其价格表:"); list(); back(); } // 价格表 public void list() { System.out.println("序号\t汽车名称\t租金\t容量"); for (int i = 0; i < 6; i++) { for (int j = 0; j < 5; j++) { if(j == 2){ car[i][j]=car[i][j]+"元/天"; } if(j == 3){ if(car[i][j] != ""){ car[i][j]="载人:"+car[i][j]+"人"; } } if(j == 4){ if(car[i][j] != ""){ car[i][j]="载货:"+car[i][j]+"吨"; } } if(car[i][j] != ""){ System.out.print(car[i][j]+"\t"); } } System.out.println(); } } //反馈回来对车量的需求 public void back(){ System.out.print("请输入您要租车的数量:"); scan = new Scanner(System.in); cars = scan.nextInt(); if (cars < 1 ) { System.out.println("对不起,您输入的数字不正确!");//未解决重新输入情况****** }else{ //根据反馈,分别对车的序号进行提供 for (int i = 1; i <= cars; i++) { System.out.print("请输入第"+ i +"辆车的序号:"); scan = new Scanner(System.in); int x; x = scan.nextInt(); if(x > 0 && x <= car.length){ sum(x); }else{ System.out.println("对不起,您输入的数字不正确!");//未解决重新输入情况,导致该辆车直接跳过 } } } System.out.print("请输入租车天数:"); scan = new Scanner(System.in); days = scan.nextInt(); bill(days); } //计算数据结果 public void sum(int i){ String[] str = car[i-1][2].split("元");//字符串去掉“元/天” carPrice = carPrice + Integer.parseInt(str[0]);//每天需要的价格 if(car[i-1][3] != ""){ str = car[i-1][3].split(":"); str = str[1].split("人"); people = people + Integer.parseInt(str[0]); if(carName1 == ""){ carName1 = car[i-1][1]+""; }else{ carName1 = carName1 +"\t" + car[i-1][1]; } } if(car[i-1][4] != ""){ str = car[i-1][4].split(":"); str = str[1].split("吨"); cargo = cargo +Integer.parseInt(str[0]); if(carName2 == ""){ carName2 = car[i-1][1]+""; }else{ carName2 = carName2 +"\t" + car[i-1][1]; } } } public void bill(int day){ carPrice = day * carPrice; System.out.println("您的账单:"); System.out.println("***可载人的车有:"); System.out.println(carName1 + "\t共载人:" + people + "人"); System.out.println("***载货的车有:"); System.out.println(carName2 + "\t共装货:" + cargo +"吨"); System.out.println("***租车总价格:"+ carPrice + "元"); } }
举报
0/150
提交
取消