-1

How is it possible to set an object and method in a condition? I understand that, if the animal is over 50kg it weighs too much. But how about if an animal is hangry, need Love and feel boring return the method feelingNegative()? I don't know how to set it. But after an animal sleeps, it is hangry. A thought would be:

Animal {
if (hangry == false && needLove == false && boring == false) {
  return feelingNegative();
}
}

still don't know how to set it.

public class Animal {

private boolean needLove;
private boolean hangry;
private boolean boring;
private int kg;

public boolean sleep() {
    return hangry = true;
}

public boolean watchTv() {
    return needLove = true;
}

public void feelingPositive() {
    System.out.println("I feel good");  
}

public void feelingNeutral() {
    System.out.println("Someting is missing...");
}

public void feelingNegative() {
    System.out.println("I need love, food and fun!");
}

public void weight(int kg) {
    if(50 < kg) {
        System.out.println("You ate way too much");
    }else {
        System.out.println("You need to eat more");
    }
}
}
mkrieger1
  • 19,194
  • 5
  • 54
  • 65
Jaybo
  • 1
  • 2
    Possible duplicate of [How do getters and setters work?](https://stackoverflow.com/questions/2036970/how-do-getters-and-setters-work) – Logan Jun 10 '18 at 19:50

2 Answers2

1

The methods you are calling don't return anything (they are void). Just remove the return. And use boolean negation (!) instead of == false. Like,

if (!hangry && !needLove && !boring) {
    feelingNegative();
}
Elliott Frisch
  • 198,278
  • 20
  • 158
  • 249
0

The Method feelingNegative() doesn't return anything (Void). So you just have to define a method that call feelingNegative() when all the conditions are satisfied.

public void myMethod ()
{
    if(!hangry && !needLove && !boring)
         feelingNegative();
}
DerMann
  • 223
  • 1
  • 2
  • 13