Hi ppl, Im have trouble returning the array in this program the error's im getting
G:\sp.java:151: incompatible types
found : char[][]
required: char
return (array1);
^
G:\sp.java:187: incompatible types
found : char[][]
required: char
return (array1);
^
2 errors

class sp
{
	public static void main(String[] args) //calling of methods from main method
	{
		char choice;
		char array1[][] = new char[8][4];
		do
		{
			System.out.println("please choose from the options below");
			System.out.println("(a) View Seating (b) Book a Seat (c) Cancel a Booking (d) Reset All (q) Quit");
			choice = Keyboard.readChar();
			switch(choice)
			{
		     	case 'a':viewseating(array1);break;
		     	case 'b':bookseat(array1);break;
		     	case 'c':cancel(array1);break;
		     	case 'd':reset(array1);break;

		     	case 'e':System.out.println("thank you for your booking");break;
		     	default: System.out.print("Enter (a)(b)(c)(d)(e)");
      		}//close switch
		}while(choice != 'e');
	}//close main
/*****************************************************************************************************************/


static void viewseating(char array1[][])//output array
{
	int i, j;
	for(i=1; i<=4; i++)
	{
		for(j=1; j<=2; j++)
		{
			System.out.println(array1[i][j]);
		}//close inner for
	}//close outer for
	System.out.print("\n\n\n\n\n");
	for(i=1; i<= 4; i++)
	{
		for(j=3; j<=4; j++)
		{
			System.out.println(array1[i][j]);
		}//close inner for
	}//close outer for
	System.out.println("");
	for(i=5; i<=8; i++)
	{
		for(j=1; j<=2; j++)
		{
			System.out.println(array1[i][j]);
		}//close inner for
	}//close outer for
	System.out.print("\n\n\n\n\n");
	for(i=5; i<=8; i++)
	{
		for(j=3; j<=4; j++)
		{
			System.out.println(array1[i][j]);
		}//close inner for
	}//close outer for
}//close method viewseating

/******************************************************************************************************************/

static char bookseat(char array1[][])//to do//assign values to a =1 b = 2 c =3 d = 4 ??for array??//needs if statement to check if seat is booked already
{

	int seat, i, j;
	char row;
	char ans, ans1;
	array1[row][seat] = array1[i][j];
	System.out.println("would you like smoking or non smoking");
	System.out.println("press (a) for smoking or (b) for non smoking");
	ans = Keyboard.readChar();
	while(ans != 'a' && ans != 'b')//validating that correct letters have been entered
	{
		System.out.println("Please choose either (a) for smoking or (b) for non smoking");
		ans = Keyboard.readChar();
	}
	if(ans == 'a')
	{
		System.out.println("please enter the row you wish to sit in (a)(b)(c)(d)");
		row = Keyboard.readChar();
		while(row != 'a' && row != 'b' && row !='c' && row != 'd')//validating that correct letters have been entered
		{
			System.out.println("There are only four rows (a)(b)(c)(d) please choose one");
			row = Keyboard.readChar();
		}//close while
		System.out.println("please enter the seat number you wish to sit in");
		seat = Keyboard.readInt();
		while(seat > 4)
		{
			System.out.println("seat "+seat+ "is not in the smoking section");
			System.out.println("please choose a seat from the smoking section 1 - 4");
			System.out.println("please enter the seat number you wish to sit in");
			seat = Keyboard.readInt();
		}//close while
		System.out.println("are you sure you want to book this seat row"+row+" seat number "+seat);
		System.out.println("press (y) for yes and (n) for no");
		ans1= Keyboard.readChar();
		while(ans1 != 'y' && ans1 != 'n')//validating that correct letters have been entered
		{
			System.out.println("Please choose either (y) for yes or (n) for no");
			ans1 = Keyboard.readChar();
		}
		if(ans1 == 'y')
		{
			System.out.println("you have succesfully booked a seat row "+row+" seat number "+seat);
		}//close if
		if(ans1 == 'n')
		{
			System.out.println("you will be returned to the main menu");
		}//close if
	}//close if
	if(ans == 'b')
	{
		System.out.println("please enter the row you wish to sit in");
		row = Keyboard.readChar();
		while(row != 'a' && row != 'b' && row !='c' && row != 'd')//validating that correct letters have been entered
		{
			System.out.println("There are only four rows (a)(b)(c)(d) please choose one");
			row = Keyboard.readChar();
		}//close while
		System.out.println("please enter the seat number you wish to sit in");
		seat = Keyboard.readInt();
		while(seat < 4 && seat > 8)
		{
			System.out.println("seat "+seat+ "is not in the non smoking section");
			System.out.println("please choose a seat from the non smoking section, seat 5 to 8");
			System.out.println("please enter the seat number you wish to sit in");
			seat = Keyboard.readInt();
		}//close while loop
		System.out.println("are you sure you want to book this seat row "+row+" seatnumber "+seat);
		System.out.println("press (y) for yes and (n) for no");
		ans1= Keyboard.readChar();
		while(ans1 != 'y' && ans1 != 'n')//validating that correct letters have been entered
		{
			System.out.println("Please choose either (y) for yes or (n) for no");
			ans1 = Keyboard.readChar();
		}
		if(ans1 == 'y')
		{
			System.out.println("you have succesfully booked seat row "+row+" seat number "+seat);
		}//close if
		if(ans1 == 'n')
		{
			System.out.println("you will be returned to the main menu");
		}//close if
	}//close if

	return (array1);
}//close bookseat method

/**************************************************************************************************************************************/

static char cancel(char array1[][])
{
}

/**************************************************************************************************************************************/

static char reset(char array1[][])
{
	int i, j;
	char ans2;
	System.out.println("are you sure you want to reset the table (y) or (n)");
	ans2=Keyboard.readChar();
	while(ans2 != 'y' && ans2 != 'n')//validating that correct letters have been entered
	{
		System.out.println("Please choose either (y) for yes or (n) for no");
		ans2 = Keyboard.readChar();
	}//close while loop
	if(ans2 == 'y')
	{
		for(i = 0; i <array1.length; i++)
		{
			for(j = 0; j <array1.length; j++)
			{//Missing code
			}//close inner for
		}//close outer for
		System.out.println("All seats on the airplane have been reset to available");
	}//close if
	else
	{
		System.out.println("You will be returned to the main menu");
	}//close else
	return (array1);
}//close reset method




/*************************************************************************************************************************************/

}//close class

Would be very greatful if some1 can help me,, Thanks!!

Recommended Answers

All 7 Replies

This is because your method signatures are
static char bookseat(char array1[][])
static char reset(char array1[][])

i.e. the methods should return a variable of type 'char'
but you are returning array1 which is of type 'char[][]'

Oh right thanks,, nd how would i go about fixing it so it will run properly

You have been told how to fix it:
static char bookseat(char array1[][])

the methods should return a variable of type 'char'
but you are returning array1 which is of type 'char[][]'

Ye but I dont no how to fix it with the information given, im only a beginner!!
PLEASE HELP

You have declared the method to return a char, but you return a char array. That is the problem.
The method is declared to return a char.

Not to mention that when you call these methods you don't use what they return, so why do you have them to return anything?

Oh right ok, so how do i decleare the method to return the array1

Oh right ok, so how do i decleare the method to return the array1

Why return an array. Do you use that array that you return? To you pass it to a variable.

char [] method() {

}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.