源码,求大神指点指点哪里还能改进

  1. 主页面设计

    public class Mainpage2 {

Scanner sure = new Scanner(System.in);

int[] cunchu = new int[20];int ave;

int sum = 0; // 总价

int sum2;

int Cunchu;

String newString = new String();

RentMoney rentMoney = new RentMoney();

Car menu = new Car();

Rent rent = new Rent();

String[] string = new String[10];


public Mainpage2() {

System.out.println("*******您是否是要使用嗒嗒租车系统(1/Y,0/N)********");

int choose1 = sure.nextInt();

if (choose1 == 1) {

System.out.println("您可选择的车辆和价目如下:");

System.out.println("  序号          租金(RMB)   容量");

System.out.println("1.奥迪A4    200/天           载人:4人");

System.out.println("2.宝马3系     400/天           载人:4人");

System.out.println("3.马自达       100/天           载人:4人");

System.out.println("4.福特F-150 200/天           载人:4人 载货:20t");

System.out.println("5.金龙          800/天           载货:4t");

System.out.println("6.松花江      1000/天          载货:4t");

System.out.println("请输入您需要租借的车辆数:");

mainpage();


} else {

System.out.println("您已退出系统!");

System.exit(0);

}

}


public void mainpage() {


int choose2 = sure.nextInt(); // 租车的数量

int choose3; // 租车的序号

for (int i = 1; i <= choose2; i++) {

System.out.println("请输入第" + i + "辆车子的序号");

choose3 = sure.nextInt();

cunchu[i - 1] = choose3;                               // 将租车序号保存到数组中

}                                                          // 定义一个类,存储每类车的价钱

System.out.println("请输入您需要租车的天数");

int choose = sure.nextInt();

 

for (int u = 0; u < choose2; u++) {                        //调用RentMoney(租金类)

Cunchu = cunchu[u];

ave = rentMoney.character(Cunchu);

sum += rent.jisuan(choose, ave);

}

for (int t = 0; t < choose2; t++) {                        //调用Car(车名),将用户已选择的租车车名存入数组

Cunchu = cunchu[t];

string[t] = menu.car(Cunchu);

}

System.out.println("您所选择的车子有:");

for (int x = 0; x < choose2; x++) {

newString = string[x];

System.out.println("    " + newString);

}

System.out.println("一共租" + choose + "天,是否确定(1/Y,0/N)");

int choose5 = sure.nextInt();

if (choose5 == 1) {

System.out.println("您需要支付:" + sum);

} else {

System.out.println("请重新选择");

mainpage();

}}}

2.租金类

public class RentMoney {

public int character(int x) {

int y = 0;

switch (x) {

case 1:

y = 200;

break;

case 2:

y = 400;

break;

case 3:

y = 100;

break;

case 4:

y = 200;

break;

case 5:

y = 800;

break;

case 6:

y = 1000;

break;

default:

System.out.println("输入错误");

break; }

return y;

}

3.车名类

public class Car {

public String car(int x) {

String string = new String();

switch (x) {

case 1:

string = "奥迪A4";


break;

case 2:

string = "宝马3系";

break;

case 3:

string = "马自达";

break;

case 4:

string = "福特F150";

break;

case 5:

string = "东风马自达";

break;

case 6:

string = "松花江";

break;


default:

break;

}

return string;}}

4.计算租金

public class Rent {

int sum;

int q, p;


public int jisuan(int x, int y) {


return sum = x * y;


}


}




慕粉3229069
浏览 1260回答 1
1回答

香飘飘丶

对于输入1/0,没有判断输入其他数字时的情况而一味归为0,显得代码不够严谨
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java