问题:选票系统方法中的 char 和 调用时String 矛盾,问一下怎么改。
首先是getSeat方法:
public static char[][] getSeat () {
Scanner sc1 = new Scanner(System.in);
Scanner sc2 = new Scanner(System.in);
char[][] A = {
{'A', 'B', 'C', 'D'},
{'A', 'B', 'C', 'D'},
{'A', 'B', 'C', 'D'},
{'A', 'B', 'C', 'D'},
{'A', 'B', 'C', 'D'},
{'A', 'B', 'C', 'D'},
{'A', 'B', 'C', 'D'},
};
int row = sc1.nextInt();
char col = sc2.next().charAt(0);
;
int column;
column = (int) col - 97;
if (row >= NUMROWS && column >= NUMSEATS) {
System.out.println("Invalid seat, please re-enter");
} else if (A[row][column] == 'X') {
System.out.println("Sorry, " + row + col + " is already taken. ");
} else {
A[row][column] = 'X';
System.out.println("OK, you've chosen " + row + col);
}
return A ;
}
然后是main方法里调用getSeat方法的部分
do {
// Show seat diagram
printSeats(planeSeats);
// Get seat choice
String seatChoice = getSeat(); <-----------这是报错的那一行
//parse the seatChoice string and book the seat
seatsTaken = parseAndBook(seatChoice, planeSeats, seatsTaken);
// If there are seats left, see if we should keep going
System.out.println( "You have booked " + seatsTaken + " seats." );
if (seatsTaken < totalSeats)
{
System.out.println("Choose another seat? (y/n) ");
String yesNo = stdInput.next();
keepGoing = yesNo.charAt(0);
}
else
{
System.out.println("Plane is now full!" );
break; //break out of the loop if all seats have been taken
}
} while (keepGoing == 'y' || keepGoing == 'Y');
//Show final seating chart
System.out.println( "Final seating chart" );
System.out.println();
printSeats(planeSeats);
这是报错内容:
下面main里的代码是不能改的,那怎么改上面方法里的代码呢?
求解答,谢谢!