javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

In the code I posted I already showed where to put that code. In the same way you define the String array emp, that you have, you will replace it with the array of EmpleoyeeRecord.

It doesn't need a main method to use it. The String is also a class. It doesn't have a main. But you created, called it and used it.

You can create and call any class from anywhere. The main method is only when you want to run the .class file. Apart from that any class can be called and used like any other (example: String).

So just replace that array with the new array of type EmployeeRecord. wherever you have the emp you will put the EmployeeRecord

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Your second class is ok. But it doesn't need a count variable.

But you do not use it at the first class, the main.
Since you want a class that has all the attributes of an employee, you need to create an array of EmployeeRecord. In your code you have an array of strings: String emp[] . Now you will have an array of EmployeeRecord. You will replace that array: emp, with an array of type EmployeeRecord. Wherever you have the emp you will put the new array. Then you will make the necessary changes:

// defining an array
EmployeeRecord [] records = null;

// initializing the array
records = new EmployeeRecord[size];

'records' is an array. Use it like any other array: records.length will get you the length. records[0] will get you the first element.

When you initialize the array you create only the array. Its elements are null. If you want to use them you need to create those as well:

records = new EmployeeRecord[size];



// records is an array
// records[0] is a EmployeeRecord. Meaning that you can do these:

records[0] = new EmployeeRecord();
records[0].setName("name");
records[0].setAge(10);

//OR 
EmployeeRecord er = new EmployeeRecord();
er.setName("name");
er.setAge(12);
records[1] = er;

//OR 
EmployeeRecord er = records[1];

So replace everywhere the String array emp with the EmployeeRecord array and do exactly what you already do, with some changes. For example, when you want to add, you will ask the user the name, the age and whatever you need …

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

ok but what im askin is..is that ok creating 2 or more arrays in one a class

private String emp[];
private String empc[];

private int count;

Why? Is there a limit on how many arrays you can declare? You can use as many as you want.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

churva_churva , if the attribute
private int count;
in the definition of the class EmployeeNames represents a class-wide information, showing how many Employees in the list, it should be static.

Actually in this case and with the way the class is declared, I believe that it shouldn't be static:

private String emp[];
private String empc[];

private int count;

If it was static and the user had 2 class instances then the count would apply to both instances which would be wrong. It should be static only if the arrays were static and were declared for use in the main method. If you had seen all the code, you would have seen that this class gets instantiated in a main method, therefor the count is part of the instance class so it doesn't need to be static.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Yes it is correct to have as many arrays as you want. Just use them in the way you use the two arrays you have in the latest code you posted. I don't see any errors to that code.

I would suggest the search method to return the position the name was found:

public int search(String x){
        boolean flag = false;
          int position= -1;
        for(int i = 0; i < this.count; i++){
            if(this.emp[i].equals(x)){
                flag = true;
                System.out.println(x + " is found at the position " + i + ".");
position = i;
                break;
            }
    }
   return position;
}

If the position returned is -1 then the name was not found. Else it return the position of the array the name was found.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

What kind of code did you find that didn't work. just have a method where you open the connection and call the query. There are codes for that. Whether it is Applet or not it is irrelevant. Create that method based on the examples you found and then call it in your Applet. The connection and running the query part should not depend on the application you are using to run it (Applet).

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

hello..
please help me..
how to write java program to count total of money after we make a transaction?

this is what must we have in java program :

- program to count balance money in account bank.
-we must set default value for the total money in account bank

what we must have in a program is :

1) method for deposit
2)metod for take a money from account
3) method for show balance money after transaction

Do some studying, read your notes and post code in a NEW thread.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Already explained in previous post how to declare methods. Have the body separately and then call that method in the case body. I have seen this error, with the same code in one of your previous posts which has been corrected.

And also from a previous post it has been explained that the code is correct. The only error was that you didn't have closing brackets anywhere. Code with closing brackets has been provided. Look at previous posts:

public void clear() {
  // your code
}

Put the code that you have. The logic has been explained. Don't randomly write stuff you don't understand


And try to study a bit. don't just copy the code.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Why the code seems correct. Apart from some missing brackets, that is the logic. Surely you can add those on your own. You should know by now how to declare methods:

public void clear() {
  // your code
}

You also need to put null values to the civil status array.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Valid point - Funny thing was I actually run into the error you have mentioned just this morning. Date.Now returns the current date and time with / and : symbols which throws an error with SQL.

I am not quite sure why the "&" wouldn't work like you have mentioned? - Although I do code in VB.net and not C# so that could have something to do with it.

This is a java forum. When you post code, try to make sure it runs in java.
Or if you want to help, try to post pseudo code

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

i want code for my project on Online Voting System in Java

Then write it. Don't expect anyone here to give you the code. Especially when the project is that big. You expect that someone else will spend all that time to write tons of pages of code?

Post your code and ask specific question.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Are you saying you want to delete all the names and civil status entered to the arrays?
Then loop the arrays and give to all the elements null as value. Also you must reset the count variable to 0.

loop
  emp[i] = null;

count = 0;
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

ok. if u have related code. please send me....

You already have the code. The problem is that the st is null. You don't initialize it. Check some tutorials or the java API of the Connection class. There is a method that creates a Statement object.

Also since you already have the code, just create a class and put the validation code inside it as instructed. With the code that you have surely you can put it into a method and call that method.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

First of all you don't initialize the Statement object. You have your connection and then you call the execute, but you didn't create the st.

Also everything you are doing is wrong. And don't tell me that it is correct because it executes. Don't open connection or run queries in a jsp. Have a separate method that returns true or false in a separate class. In the method you will open the connection, run the query, close the connection, which you don't, end return the result.
Then you will call that in the jsp.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Can you re-post your code in code tags? Just click the (code) button when making a new post and put your code in there.
Also give more explanations about your problem

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I appreciate that this is an old thread but why on earth would you post a reply still with errors and with a pointless fix!.

First of all you are using a reserved word in your SQL statement "from" cannot be used as a parameter as its reserved by SQL.

Secondly whats the point in specifying a date when the Original Poster wanted to get the current date - All that needed to be dones was "& System.DateTime.Now() &"

Please see the amended code below:

Java Syntax (Toggle Plain Text)

   String sql="";
   DateTime dt = DateTime.Now;

   for(int i=0;i<numbers.length;i++) {
      sql="INSERT INTO smsmsg (to,msg,numFrom,timesent) VALUES ("
      & numbers[i] & ",'text','from', " & dt & ")";
      access.insert(sql);
    }

Your code isn't quite spotless as well. Not to mention that it will not compile.
Apart from using the '&' which is the reason why this is wrong, you go on saying that in order to get the current yo use this: DateTime.Now. And that you should put that into the column the String representation of the DateTime object!
Shouldn't be asking yourself what type is the timesent because in case it is Date and not Varchar (if it is Date your query will not run) you can use an sql function that returns the current date.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

As I said before but you ignored me, the code does what you say it to do. If you read the name, then you need to update the array with the names with that value. You are calling the update method and what you pass as arguments are saved to the arrays. When you put the name to one of those arguments, you need to save that argument into the array of the names. If you enter the name of the employee and take that argument and put it into the array of civil statuses of course that is wrong.
So look what arguments you pass to the update method when you call it and what you do with those arguments in the method.

Probably because you don't assign the values correctly. When you read the name into a variable you must put that variable in the array that holds the names, not the civil status

As for the nextLine. Read my previous posts, which you keep ignoring. I give you solutions and suggestions and you ignore the explanations and copy only the code. I will not repeat my self. Read the explanation already given.

Why must I keep posting the same things over and over again, if you don't read them.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

a java application that asks an INTEGER number from the user.Then output each digit in a newline.

Haven't you read my previous reply? Your initial question has been answered in this thread. For new questions start an new thread. What do you think this is? A thread were you can throw your homework and disregard the forum rules? If you want help start a new thread and read the forum rules, which you agreed when you signed in.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Create an application that reads in a five-digit integers and determines whether it is a palindrome.If the number is not five digits long,display an error messsage and allow the user to enter a new value.

Read the forum's rules. Also, read whatever has been written in this thread. Since you found it, you should know that it answers your question.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

When the variables are like that:
String emp[]
String empc[]

And you ask someone, what are those, they won't know. Even you wouldn't remember them after a week, or when you want to study your code after a while.

Like this: empname, empcivil, is very clear.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

If look at the previous post I explain what you asked. Do you want me to sit and write exactly the same things that I explained or copy paste the exact same explanation to a new post?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Already explained

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

You will not add anything. I told you what to do. If you read the name, then put it into the array that you store the names, not the civil statuses.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Probably because you don't assign the values correctly. When you read the name into a variable you must put that variable in the array that holds the names, not the civil status

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

First of all you are mixing the if in the method with the else at the switch. You do this:

public method () {

  if () {

  }

}


else {

}

which is wrong. The if closes in the method and the else that you have has no if. Also the delete is also wrong. It is outside the method and it belongs to another case.

Have one method:

public void update(int pos,String x,String y){
  if(!isEmpty()){
    emp[pos]=x;
    empc[pos]=y;
    System.out.println("done");
  } else {
    System.out.println("Array is empty");
  }
}

And then call it:

case 5: System.out.println("\nEnter Employee Pos: ");
                        pos1=s.nextInt();
						 
				System.out.println(" Enter Employee Name: \n");
                     place1  =s.nextLine();
							 
				System.out.println(" Enter Employee Civil:\n ");
                        num1    =s.nextLine();
                        e.update(pos1,num1,place1); 
          break;

Also the nextInt will not work.
When you call the nextInt it reads the number you enter, but when you call the nextLine, it reads whatever you enter and the new line character.
So if you enter a numnber : 12 and press enter: <enter>

Enter Employee Pos
12<enter>

The next int will read only the 12. The enter will not be taken into account.Then when you call the nextLine to read the name, if you give a name and press <enter> it will not read the name, but the previous enter. Because when you entered the number previously you only read the number, and didn't change lines.

So the right code would be:

case 5: System.out.println("\nEnter Employee Pos: ");
                        pos1=s.nextInt();
                        s.nextLine();
						 
				System.out.println(" Enter …
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

When you were adding elements to the array you were doing this: employees[count++]=new EmployeeDet(name, civilSt); where the name and civilSt were read from the keyboard.

You will do the same, read the new name, civilSt from the keyboard. The only difference is that this time you will not add the EmployeeDet to that array after the previous one entered but you will change the value of one already been inserted.

Assuming that you have the name to be unique and since you use that for searching then.
Ask the user to enter the name whose employee you want to update.
Loop the array and find the position in the array of the employee with that name.

But wait you already have that. You have the method search, which takes as argument the name and returns the position that the employee with that name has in the array. int index = search(name); Where name is the name you want to search (entered from keyboard) and index is the position of the array

Anyway regardless how you find where the employee with that name is,

After you have entered the name of the employee
Found where that employee is (position index)
Ask for the user the new values.
Then change the value of that array's element employees[index]=new EmployeeDet(newName, newCivilSt);

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Here is the code:

<html>
 <head>
  <title>This is a title</title>
 </head>
 <body>
   Hello Nurse
 </body>
</html>

Given the thousands of internet sites out there can you understand how unintelligent your question is?

If you have been to told to build a site for an assignment come up with an idea and do some studying.

First learn these:
1) Java
2) HTML
3) Database connectivity with java
4) JSP - Servlets

Then after you have learned those come back with a question

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster
<a href="page.jsp?id=5">Text</a>

Or for a dynamic link jsp:

<a href="page.jsp?id=<%=id%>">Text</a>

Where 'id' is a java variable

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I am not going to read that! And it is clear that you don't know how to write proper HTML as well. Try to learn first HTML and post some code that can read. Use the button (code) when creating a new post.

And this:

<tr></tr><tr></tr><tr></tr><tr></tr>

Is not proper html

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

As explained before create a separate class, EmployeeDet for example.

class EmployeeDet  {
   private String name = null;
   private String civilStatus = null;
   // add more if you want.

   public EmployeeDet() {
   }

   public EmployeeDet(String na, String civSt) {
     // give the values of the arguments to the attributes of the class (name)
   }

   // write get, set methods to get/set the values of the attributes of the class
}

For more information about creating classes with constructors and get/set methods read some tutorials.

Now that you have your class just instantiate it. You don't need a main method to run it. Just use it in any other method or class like you do with the java classes. EmployeeDet doesn't need a main method. You will call the constructor and its methods in the one main method you have created, like you call any other method.
In your code, you do this: at the main: EmployeeNames e= new EmployeeNames(); You could have done that even if the EmployeeNames class didn't have a name. If EmployeeNames was in another class and the main to a different one you still could call it.

So in your case, you have in the EmployeeNames class this: private String EmpYee []; That is an array of Strings and you save the name inside. Now you will use an array of EmployeeDet:

private EmployeeDet [] employees = null;

....

// and in the constructor:
employees = new EmployeeDet[size];

employees is an …

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Your question doesn't make any sense. Post an example, read about javascript

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

In the other thread you asked the same thing and received answers.

You said once that can not use 2 different classes as your teacher has instructed, but at your PM you asked how to use 2 classes. One that has those attributes that you want and the other the main.

Now which one is it?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

In this link:
http://www.daniweb.com/forums/thread310512.html
you asked the same thing. You got the answer for the question you posted here and said you understood it and then asked other questions. After all of my suggestions which you claimed you figured them out and have fixed your code, now you post the same initial code, without implementing any of my suggestions.

I see the same errors that I told you to fix and you said that you fixed them. What was all that about?


Here another time what you need to do:
You already have this code:

public int search(int x){
		 
		  boolean flag=false;
		     for(int i=0;i<this.count;i++)
			      if(names.equals(EmpYee[i])){
					   namesWasFound=true;
						 x=i;
						}
					}
				if(flag=false)
					x=-1;
					
				 
					return x;
				}
					}

If you want the name, why don't you pass that as argument? Where is names defined? Just pass the name as argument, loop the array until you find it. Then return the index that it was found. The place the name was found in the array. If it is not found then return -1. You already do most of those parts in your code.

And look back at the answers given to you. You still don't initialize the right EmpYee array variable.
And every time you have a new question post your updated code.


As for your PM:

If you want to add a "Civil Status" attribute or an "Age" attribute for the employee, start a new thread, because you still have …

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Then write a 2D array of size 20x20. Have variables to save the position of the turtle and its current direction. When the user enters an input, use if statements to determine the position that it needs to move. If it is a valid position within the limits of the array then change the values of the variables that store the position and the direction.

After each move print the array and display a special character at the position of the turtle

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Without even looking at the code since it is not in code tags - Press the button (Code) and put your code inside the tags that will appear - I took a look at the error:

java.lang.NullPointerException
ServletOne.doPost(ServletOne.java:46)
ServletOne.doGet(ServletOne.java:15)

Try to read them from the begining. As soon as you reach a file that you created you found the source of the problem. At the file ServletOne, inside the doPost method at line 46 of the ServletOne.java file, you are trying to use an object which is null. Hence the NullPointerException. Go to that line and find what is null.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

and clearly did not write that code himself.

That was my thought. That is why I mentioning all those hints, why he wrote all that code and couldn't understand those simple advices. I am with a friend now and he has a degree in Theological studies and he could figure out the solution and how to fix the errors!

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

You have sent me so many PMs I have lost count. They all ask the same thing and I have given to all the same answer. How many negatives replies must I send in order for you to understand that I will not send you code by PM? You think that by asking the same thing over and over again, it will make me change my mind and send you the code. Why?

Also I find very hard to believe that someone that has written that good initial code such as yourself, can't understand those simple suggestions I gave?

You have in your code an array to store the names. It is strange that you cannot add more arrays to store whatever you want, as I suggested.

No one here is going to give you the complete code. You already have that. And you have the solution, which I gave. Make the necessary changes that you can make, and post the updated code with your new questions.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

If you want only one class, then add more arrays. You have one for the name. Add one more for the age or the civil status

I already added it to your code. Check my example. And the suggestion is pretty clear to me (You have one for the name. Add one more for the civil status). The solution has already been given to you. Implement it.

If you wrote the code with the String array for the name, surely you can do the same for the rest.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

If you want only one class, then add more arrays. You have one for the name. Add one more for the age or the civil status. All the arrays must have the same length and when you add something to one of the arrays you must do the same to the others in order to make sure that all of them will have the same amount of data.

So you probably don't want to do this:
emplo[count++]=x

But this:

name[count]=na;
age[count]=ag;
count++;

Where na, ag are the arguments that the user enters. For updating just ask the user the name of the employee, search for that name, find at which position it is, and change the value of the elements of the array at that index.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

You should create a separate Employee class in which you will hold all the information of the employee. Since you already hava an Employee class, I would suggest a different name.
Let's say you have this:

public class Emp {
  private String name = null;
  private int age = 0;

  public Emp() {

  }

  // Add an initializer constructor that takes as arguments the name and age

 // Add get,set methods for the name and age
}

Now that you have this you can replace in your code the array of String names with this:

public class Employee{
 
 private Emp emplo [];
 private int count;
 private int size=10;

....

 public Employee(int size){
	emplo=new Emp[10];
	 count=0;
	}
 
	 	public Employee(){
		 this(10);
        	}

....
}

Remember that emplo is an array and emplo is an Emp class. So now when you add elements to the array add Emp instances. Ask for the user to enter the name and the age, create an Emp instance and add that to the array.
The same for printing. Loop the array and print the attributes of each Emp element
For the search loop the array and compare the name of each Emp element with the name argument

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Read the input. Convert it to a String. Loop the String using its charAt(int) method to take each digit as a character. Convert that to an int and add it to the sum.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

As explained, what you do here is this:

if(isFull())
emplo[count++]=x;

If the array is full you go and add the element x. Now since you wrote those methods I find it strange that you can't understand what needs to be done.


----
return x;// this part is also the error
----
As explained look at the compile errors. You have declared the method to be of type String and the x that you return is of type int. Those need to mach. Check the requirements what that method needs to return.


Post the new code. Look at the errors and use them to correct the code. Since you wrote all that code, I am surprised that you can't fix those little mistakes because they are very simple compare the complexity of the rest of your code.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

have you added the jar to the classpath ?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I would suggest to save in a table, the question, the options and the correct answer as columns.
Then query the table into an ArrayList for example and randomly select an element. Use Math.random()*list.size()

Were exactly are you having problems?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

The suggestion you said to me makes my program more complicated....why don't you just help me how to solve it by editing my code...I also made an effort its just that i cannot figured it out...I want a help can...is that for you to answer thats a big favor im asking you I do an effort to that..so help me...

I told you exactly what you needed to do. It will not make the code more complex. For example in the add method I told you:
"
In the code when adding elements you add an element when the array is full which is wrong.
"
You have in the code:
if(isFull())
emplo[count++]=x;

I told you that you add the element when the list is full, which is wrong. How complicated would make the code correcting that?

In the search I told you to return the index not the element you search. All the changes are 1 line, ONE line.
You didn't bother to read them or try them.

The compile errors, which you didn't post, and you get, are very simple. Just read them and then read what you have written. When you declare a method to return a certain type, your return statement must return a variable of that type.

You made no attempt to fix your code with what I told you. It is as if you don't listen what I say.

tux4life commented: You've done enough effort. His lazyness is the bottleneck :P +8
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

No I cannot edit your code. You have been told what you need to know in order to correct your program. And when you are done with my suggestions post your latest code.

And how many times do I have to tell you. You have sent me 4 or 5 PMs asking for the code. How many times do I have to tell you? Post your question at the forum. Can't you figure that out on your own? I was repeatedly telling you "start a new thread", "post your code at the forum" and you kept sending me PMs which I was doing you a favor to reply instead of ignoring you.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

arrayinput1, arrayinput2 are arrays. You need to loop the arrays and compare their values individually.

Also do you need to compare only 2 character variables or arrays that have many characters?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

No it is not inside it. What is done you call FindPiece. You can call it from wherever you want. So you are calling it from inside the method. You can call methods inside other methods:

public void p1() {

}
public void p2() {
  
}
public void p3() {
  p1();
  p2();
}

What is done, the ChessPiece [][] pieces is an array, the pieces[][] is a ChessPiece. So you can call its method:
pieces[row][col].FindPiece(chessPiece)
And since it returns a String then this is a String:
pieces[row][col].FindPiece(chessPiece)
So you can do this:
pieces[row][col].FindPiece(chessPiece).charAt(0)

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

@tux4life, uhmm.. right..
can i do that?

ok ok, lack of information, sorry for that...

i'll have to input characters and store it to the character arrays.
i'll have 2 char arrays, so, i will also have 2 input characters...

for example,
the program will ask me to enter the first set of Variables, and the inputs will be stored inside the array. then will ask me to input second set of variables..

Will you know how many characters to enter? If not, you need to have a while loop where the user enters input. When the users enters "quit" for example break from the while.
You can have the Scanner to read the input as a String and if it is not "quit" or if its length is 1 (characters have length 1), concatenate it to a String. Then convert that String to a character array.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

In the constructor you are initializing locally a new String. You need to initialize the one declared globally as a class attribute. The String emplo []; declared at the beginning of your class.

In the code when adding elements you add an element when the array is full which is wrong.

And don't use the equals method to compare primitive ints. Use '=='. What you do in the search method is return the argument. But if it is not found you return -1. But what if you have -1 in the array. That would be confusing. You need to return the index of the array and if it is not found return -1. You can also add a return statement in the for. Once you found it return the index. If you go outside the for-loop meands you have found it so return -1.

For the last errors I mentioned, as well as others you need to read the compile errors. They are very self explanatory. Read them and follow the instructions. Also do some studying on how to declare methods and classes.

Don't post code without explaining what is wrong, what the errors are and without having read them