所以我为我的大学准备了这个项目,但我被困在这里,我尝试了所有我想到的让这段代码保存超过 1 个插槽的方法,因为我必须将多达 100 个保存到矩阵数据库中。一切正常,但程序总是覆盖第一行,永远不会传递到第二行......这是代码:
保留部分方法:
for (n=1; n<100; n++) {
parkinglot[n][0] = Integer.toString(n);
parkinglot[n][1] = JOptionPane.showInputDialog(null, "License plate: ").toUpperCase();
String hourofreservation = JOptionPane.showInputDialog(null, "Reservation hour(hh:mm): ");
parkinglot[n][2] = hourofreservation;
parkinglot[n][3] = formatter.format(date);
parkingtime = Integer.parseInt(JOptionPane.showInputDialog(null, "Hours : "));
parkinglot[n][4] = Integer.toString(parkingtime);
int totalfee = (toMinutes(parkingtime)/30) * fee;
pay(totalfee);
//SaveReservation(nrinmat, parkinglot);
//save
JOptionPane.showMessageDialog(null, "This is yout reservation" + "\n\n" + " | " + parkinglot[n][0] + " | " + parkinglot[n][1] + " | " + parkinglot[n][2] + " | " + parkinglot[n][3] + " | " + parkinglot[n][4] + " HOURS |");
break;
}
数据库方法:
public static String[][] database(String [][]parkinglot)
{
System.out.println("This is database");
for (int i = 1; i < parkinglot.length; i++) {
for (int j = 0; j < parkinglot[i].length; j++) {
System.out.print(parkinglot[i][j] + "\t");
}
System.out.println();
}
return parkinglot;
}