-5

i want to help me with this.I should create a method equals that will check two objects.If the objects are equal then it will return true,if not it will return false. For me i have worked on this but with a different way i did a method in past with like that way

public static boolean trueorfalse(int cars,int bikes){
   boolean y;
   if(get.car==get.bikes)
   {
    System.out.println("are equal");
    y=true;
   }
    else
   {
    System.err.println("arent equal");
    y=false;
   }
 return y;
}

Now with the method equal :

public static boolean equal(int cars,int bikes){  //i change the name?
       if(get.car==get.bikes)   // may needs here equalsof() something like this? or is completely wrong i am.
       {
        System.out.println("are equal");
        y=true;
       }
        else
       {
        System.err.println("arent equal");
        y=false;
       }
     return y;
    }

if you could help me out with this i would be greatful because i think i have solve it but i am not sure.Thanks,i want to refer that it is my first visit here i dont know about if because is "begginer" level you not help.

  • 1
    why are you calling a getter method on an int? why not do bikes==cars? – RAZ_Muh_Taz Jun 13 '17 at 16:27
  • What is get? Where is y declared?? – ΦXocę 웃 Пepeúpa ツ Jun 13 '17 at 16:29
  • 1
    Why are you passing two int values `int cars,int bikes` as arguments but then do not use them? And what is this `get` thing that you are using? – OH GOD SPIDERS Jun 13 '17 at 16:29
  • Okay, first off you need to describe what you expect to happen. Then you need to describe what is actually happening. eg. This will not compile because it says `get` does not exist. – matt Jun 13 '17 at 16:33
  • how would u do it to check if this is equals? i think with = .If i am wrong help me –  Jun 13 '17 at 16:33
  • i have done out of the code objects with get and set.I have done and the constructor.I care only about this method.If get is false to check if an object is equal with other please if you know help me see it –  Jun 13 '17 at 16:35
  • 1
    Please provide compilable code. Then we can give you clear answer. As others mentioned, no one know what is the `get`. what are you expecting from passing two integers -`int cars,int bikes`. – Blasanka Jun 13 '17 at 16:39
  • 1
    "how would u do it to check if this is equals?" <- we don't even know what **this** is. What do you want to check for equality? Two Objects? Two primitive ints? – OH GOD SPIDERS Jun 13 '17 at 16:39
  • If you want to compare values of `bike` and `car` you can do `if(car == bike)` because of primitive(int). Do not need to use `get` – Blasanka Jun 13 '17 at 16:41
  • two objects i want –  Jun 13 '17 at 16:53
  • 1
    Your method takes in two arguments, `car` and `bike`, both of which are integers, type `int`. Do you want to check if `car` = `bike`? Or, are you trying to do something else entirely? What are "the two objects"? In Java, the word 'object' means something specific, do not use the term unless you mean that. If you're referring to `car` and `bike` as objects, don't; refer to them as 'arguments' or 'parameters'. – Ishnark Jun 13 '17 at 16:57
  • My mind now stuck.Car and bikes are objects(i create them before method with get and set).I do parameters on this method to pass and after i want to see if this objects are equals...There is equalsof i think that checks if two objects are equal or not? –  Jun 13 '17 at 17:04
  • Have a look at [this](https://stackoverflow.com/questions/16069106/how-to-compare-two-java-objects). You can get some idea. – Blasanka Jun 13 '17 at 17:07

1 Answers1

1

I would like to say,you were too close to correct.
Now, it's fixed !

public static boolean equal(int cars,int bikes{
if(car==bikes)
//since you are comparing two ints, you don't require any !
{
System.out.println("are equal");
y=true;
}
else
{
System.err.println("arent equal");
/*Preferably use System.out.println().Having an inequality as this cannot be 
attributed to error. It's okay if you stick to your view.There is no hard and fast rule either !*/ 
y=false;
}
return y;
}
Imacoder
  • 511
  • 5
  • 7