Java 도움말.Java 열과 행
화면에 좌석표를 인쇄하는 프로그램을 작성하고 은 사용자에게 좌석 또는 가격을 선택하라는 메시지를 표시합니다. 에 의해 좌석을 팔아서 가격을 0으로 변경하십시오. 사용자가 좌석을 지정하면 을 사용할 수 있는지 확인하십시오. 사용할 수없는 경우 사용자에게 알려서 에게 좌석 또는 가격을 선택하도록 요청하십시오.
교사는 A-I과 열이 난 내 교양 학교에서이 고급 자바를 배울하지 않았기 때문에 내가이 얻을 수 없습니다 1-10로 수 행을 원한다. 또한 선생님은 내가 할 수없는 Stage를 출력하기를 원합니다. 당신이 참조를 정의 할 때
public class TheatreSeating {
public static void main(String[] args) {
// Two dimensional array to hold seats
int[10][9] seatsArray =
{{ 30, 40, 50, 50, 50, 50, 50, 50, 40, 30 },
{ 20, 30, 30, 40, 50, 50, 40, 30, 30, 20 },
{ 20, 20, 30, 30, 40, 40, 30, 30, 20, 20 },
{ 10, 10, 20, 20, 20, 20, 20, 20, 10, 10 },
{ 10, 10, 20, 20, 20, 20, 20, 20, 10, 10 },
{ 10, 10, 20, 20, 20, 20, 20, 20, 10, 10 },
{ 10, 10, 10, 10, 10, 10, 10, 10, 10, 10 },
{ 10, 10, 10, 10, 10, 10, 10, 10, 10, 10 },
{ 10, 10, 10, 10, 10, 10, 10, 10, 10, 10 }};
String continueFlag = "Y";
Scanner input = new Scanner(System.in);
while (continueFlag.equals("Y") || continueFlag.equals("y")) {
System.out.println("Please Select an option");
System.out.println("1. Select Seat");
System.out.println("2. Select Price");
// Get selected option
int option = input.nextInt();
if (option == 1) {
System.out
.println("Please enter the row number of seat (1-10):");
// Subtract 1 as array starts from 0
char row = input.nextInt() - 1;
System.out
.println("Please enter the column number of seat (1-10):");
// Subtract 1 as array starts from 0
int column = input.nextInt() - 1;
boolean seatAvailable = isSeatAvailable(seatsArray, row, column);
if (seatAvailable) {
// Assign Seat
seatsArray[row][column] = 0;
} else {
System.out.println("Requested seat is not available");
}
} else if (option == 2) {
System.out
.println("Please enter the Price(10,20,30,40 or 50):");
int price = input.nextInt();
// Check available seat
boolean found = false;
for (int i = 0; i < seatsArray.length; i++) {
// Continue looking only if not found
if (found == false) {
for (int j = 0; j < seatsArray[i].length; j++) {
if (seatsArray[i][j] == price) {
// Assign the seat
seatsArray[i][j] = 0;
found = true;
// Exit from inner loop
break;
}
}
}
}
}
printSeats(seatsArray);
System.out.println("Do you want to enter more seats (Y/N)");
continueFlag = input.next();
}
System.out.println("Bye");
}
private static void printSeats(int[][] seatsArray) {
for (int i = 0; i < seatsArray.length; i++) {
for (int j = 0; j < seatsArray[i].length; j++) {
System.out.print(seatsArray[i][j] + " ");
}
System.out.println();
}
}
private static boolean isSeatAvailable(int[][] seatsArray, int row,
int column) {
for (int i = 0; i < seatsArray.length; i++) {
for (int j = 0; j < seatsArray[i].length; j++) {
if (i == row && j == column && seatsArray[i][j] != 0) {
return true;
}
}
}
return false;
}
}
정확히 문제는 무엇인가? 그것은 심지어 컴파일합니까? –
그것은 그냥 힘든 시간이 있도록 행 수 코드와 오는 데 컴파일 (A-I)과 열 (1-10) 필자는 모든 노력을 표시하고 난 내 코드에 넣어하려고 할 때 그것을 엉망으로 유지합니다. 또한 상단에 단어 무대를 출력해야합니다. – Joy
'int [10] [9] seatsArray = .....;'컴파일합니까? 또한 –