我用数组做的,请问各位大神还有啥可以改进的地方么
package com.imooc.test;
import java.util.Scanner;
public class Test2 {
static boolean flag = true;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
// 1. 名称,2. 载人量,3 载重量,4 价格 嗯?这些还需要我挨个提示么?
String[][] car = new String[4][4];
// 呐!初始化!
System.out.println("( *******(********************^^^^^----!----^^^^^********************)*******)");
System.out.println("( **欢迎来到全网最炫酷的MC吃鸡王的租车间,药!~易购窝里狗够!全场的先生们女士们这里所有的车辆任你们挑选**)");
System.out.println("( *******(********************^^^^^----!----^^^^^********************)*******)");
//拿本子记好接下来循环就要开始啦-
while(true) {
if(flag) {
System.out.println("快点的租不租,不租赶紧走 ----> 1 - (租,大哥,我租,租还不行)\t2 - (不租,走就走,谁怕谁)");
}else {
System.out.println("还租不租了 ----> 1 - (租,租呢租呢大哥,别生气)\\t2 - (不租了吧,大哥你放过我吧,我是真没钱了)");
}
String isZu = sc.nextLine();
if(isZu.equals("1") || isZu.equals("是")) {
zuChe(car);
}else if(isZu.equals("2") || isZu.equals("否")){
System.out.println("赶紧走,穷比");
break;
}else {
System.out.println("搁这瞎鸡儿输啥呢?眼睛长后脑勺上了啊?");
}
}
}
public static void zuChe(String[][] car) {
Scanner sc = new Scanner(System.in);
car = init(car);
print(car);
System.out.println("看哪个好自己挑");
String zuCar = sc.nextLine();
switch (zuCar) {
case "1":
case "三轮车" : buy(1,car);
break;
case "2":
case "小黄车" : buy(2,car);
break;
case "3":
case "没轮胎的九手汽车" : buy(3,car);
break;
case "4":
case "婴儿车" : buy(4,car);
break;
default:
System.out.println("你会不会输啊?是不是眼睛不好使?给我看清楚再输");
break;
}
}
public static void buy(int num,String[][] car) {
Scanner sc = new Scanner(System.in);
System.out.println("租几天?我劝你最好多租点:");
int day = sc.nextInt();
System.out.println("租几量就不用我提醒了吧");
int nums = sc.nextInt();
String name = car[num-1][0];
int price = nums * day * Integer.parseInt(car[num-1][3]);
System.out.println("奶奶的才花了这么点钱,这是车的信息,再问你一遍:");
System.out.println("\t租用的车辆:\t" + name);
System.out.println("\t租用的数量:\t" + nums);
System.out.println("\t车的载重量:\t" + car[num-1][2]+"/辆");
System.out.println("\t车的载人量:\t" + car[num-1][1]+"/辆");
System.out.println("总金额:" + price + "元");
flag = false;
}
public static void print(String[][] car) {
for(int i = 0;i<car.length;i++) {
System.out.print(i+1);
for(int j = 0;j<car[i].length;j++) {
System.out.print("\t"+car[i][j]);
}
System.out.println();
}
}
public static String[][] init(String[][] car){
car[0][0] = "三轮车";
car[1][0] = "小黄车";
car[2][0] = "没轮胎的九手汽车";
car[3][0] = "婴儿车";
System.out.println("序号\t车名\t载人量\t载重\t价格/天");
for(int i = 0;i<car.length;i++) {
for(int j = 1;j<car[i].length;j++) {
if( j == 1) {
car[i][j] = String.valueOf((int)(Math.random() * 10)+1)+" 人";
}else if(j == 2){
car[i][j] = String.valueOf((int)(Math.random() * 10)+1)+" 吨";
}else {
car[i][j] = String.valueOf((int)(Math.random() * 100)+1);
}
}
}
return car;
}
}