Can some one help me with my programming project, it is supposed to loop. If the number is even output comes out even and vise-versa. Can someone please tell me what is wrong with my code.

Errors
"3 errors found:
File: C:\Users\Kaamil\evenodd test.java [line: 1]
Error: The public type NumberEvaluator must be defined in its own file
File: C:\Users\Kaamil\evenodd test.java [line: 3]
Error: Duplicate method evenOdd(int) in type NumberEvaluator
File: C:\Users\Kaamil\evenodd test.java [line: 8]
Error: Duplicate method evenOdd(int) in type NumberEvaluator"

Code.

public class NumberEvaluator
{
 public void evenOdd(int num)
 {

 }

 public void evenOdd(int num)
 {
  if (num % 2 == 0)
  {
    System.out.println ("even");
  }
  else
  {
    {
     System.out.println ("odd"); 
    }
  }
 }
 public static void main(String [] args)
 {
   int number;
   NumberEvaluator nE = new NumberEvaluator();
   nE.evenOdd(-5);
   nE.evenOdd(0);
   nE.evenOdd(7);
 }
}

The filename of the .java file should be the same as the name of the public class it contains.

You need to add a println that shows what number is being tested as well as the results of the test.

sorry, somewhat hard to understand (im completly new at this) can you please show me the proper coding, and does that mean i save the file as NumberEvaluater or as evenOdd?

save the file as NumberEvaluater.java

Yes, the file should be named the same as the class name. Not the method name

so which one is that? and is that the only change i have to make?

ok so i saved it as NumberEvaluater but now the error has changed. It now says
"File: C:\Users\Kaamil\NumberEvaluator.java [line: 3]
Error: Duplicate method evenOdd(int) in type NumberEvaluator"

does this mean i should just delete line 3?

I just deleted line 3 and now the error is
"File: C:\Users\Kaamil\NumberEvaluator.java [line: 22]
Warning: The local variable number is never read"

Please help!?!?

Rename one of the methods so its name is not the same as the other one's name.

Delete the definition of number if you do not use it.

change the
" nE.evenOdd(-5);
nE.evenOdd(0);
nE.evenOdd(7);"

change each of those?

You must not define the method twice, and usually it is better practice to return value or set attribute of class, than print in function.

commented: Might be too advanced for OP +13

What is the reason to change those?

what do i do to make this work?
and i have to use print as this is for school

Does it compile without errors?
What happens when you execute it?

it says

"File: C:\Users\Kaamil\NumberEvaluator.java [line: 22]
Warning: The local variable number is never read"

Remove line 22 where number is.

The message is a warning so the code should execute anyways if you were to try.

i tried that, the compile completes without error but it dosent tell me wether the numbers (-5, 0, 7) are even or odd which is the main part of the whole code

How are you executing the class after you compile it?
Some details here: Click Here

could my compiler be the problem? i am using eclipse 0.A48

I did the changes I mentioned and it compiles fine

I:\Java\code>javac NumberEvaluator.java

I:\Java\code>java NumberEvaluator
odd
even
odd

I:\Java\code>
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.