I am using java to create a program that gives the user the option to either add two numbers multiply two numbers or see if the 2 numbers are equal this is what i have so far. I know hot to the menu option so that is ommitted. how can i do the equals>> like equals(x,y) or equals(x,plus(x,y)) am i on the right track? any feedback would be appreciated

equals(x,plus(x,y);
sum = plus(x,y);
product = times(x,y);
public int Plus(int x, int y)
{
return (x + y);
}
public int Times(int x, int y)
{
return (x * y);
}
public bool equals(int x, int y)
{
if(x==y)
return true

else
return false
}

Does the code compile and execute and give you the correct results?

One shortcut would be to return the boolean results of this expression: (x==y) directly vs using an if/else statement. (x==y) gives a boolean result of true or false. No need to test it, just return it. See what you did in the times() or plus() methods. (Note lowercase first letters are standard)

I can already tell that you didn't try to compile it since it does have errors

public bool equals(int x, int y)

There is no "bool" type. Should be...

public boolean equals(int x, int y)

thank you i know that iput that jsut so can see what i was saying but thanks you.

I can already tell that you didn't try to compile it since it does have errors

public bool equals(int x, int y)

There is no "bool" type. Should be...

public boolean equals(int x, int y)

that iput that jsut so can see what i was saying

Sort of a waste of time then for everyone.

um no it's not considering i still need to figure out how to determine if x and y is equal if i use other calls like equals(3,minus(3,5)).. I kindof confused myself.

Sort of a waste of time then for everyone.

try this. but i think your code is correct except you should replace bool by boolena.

public boolean equals(int x, int y){
   return (x == y);
}
commented: Thank you so very much!! i just wanted to make sure i was not doing it wrong. out of them all you were the most helpful!! +1

thank you!!

try this. but i think your code is correct except you should replace bool by boolena.

public boolean equals(int x, int y){
   return (x == y);
}

mark this as solved.. if that helps you

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.