public static void buildSeats()
{
char seatLetter = 'A';
for (int i = 0; i < seats.length; i++)
{
for (int j = 0; j < seats[i].length; j++)
seats[i][j] = seatLetter++;
seatLetter = 'A';
}
}
public static void printSeats()
{
System.out.println("Available Seats:");
for (int i = 0; i < seats.length; i++)
{
System.out.print((i + 1) + " ");
for (int j = 0; j < seats[i].length; j++)
System.out.print(seats[i][j] + " ");
System.out.println();
}
}
public static void reserveSeat(int row, char col)
{
String seatNo=String.valueOf(row)+col;
if (checkAvailability(seatNo))
{
reservedSeats.add(seatNo);
for (int i = row - 1; i == row - 1; i++)
{
for (int j = 0; j < seats[i].length; j++)
{
if (seats[i][j] == col)
{
seats[i][j] = 'X';
}
}
}
System.out.println(" Seat " + seatNo + " is Reserved ");
}
else
{
System.out.println("Sorry! The Seat "+seatNo+" is NOT available.Please look up for another seat.");
}
printSeats();
}
public static boolean checkAvailability(String seatNo)
{
boolean available = true;
for(int i=0;i<reservedSeats.size();i++)
{
if(reservedSeats.get(i).equalsIgnoreCase(seatNo))
{
available = false;
}
}
return available;
}
}
问题是,我怎么改以上的coding so that when the user enter '1E' or '8A', 系统会show 'invalid seat input'呢?
谢谢各位的回复。。
小弟感激不尽。。