#Help with if and booleans/ ball in x/y axis problem

1 messages ยท Page 1 of 1 (latest)

eternal hollowBOT
#

<@&987246399047479336> please have a look, thanks.

#

Here is an AI assisted attempt to answer your question ๐Ÿค–. Maybe it helps! In any case, a human is on the way ๐Ÿ‘. To continue talking to the AI, you can use </chatgpt:1108714622413963314>.

#

Sure, I'd be happy to help you with your logic problems. Could you please provide more details about the assignment and the specific problem you are facing?

ivory flax
#

I hope i am going the right direction with my logic

#

please note that i am a beginner, and my knowledge is limited, and i am also limited to what i learned in class.

#
    public static void main(String[] args) {
        double xLoc=30;
        double yLoc=20;
        double xVel=5;
        double yVel=-5;
        final int rightWall=100;
        final int ceiling=100;
        final double diameter=4;

        for (int v = 0; v<Math.abs(yVel) ; v++) {
            boolean bounced = false;
            // if Velocity is downwards
            if (0 > yVel) {
                //if hits wall
                if (yLoc - v < (diameter / 2)) {
                    //bounce on y axis
                    bounced = true;
                }
                if (bounced) {
                    yLoc++;
                } else {
                    yLoc--;
                }
            }
            if ((yLoc + v) > ceiling - (diameter / 2)) {
                bounced = true;
            }
            if (bounced) {
                yLoc--;
            } else {
                yLoc++;
            }



            }
            }

        }


    }
}```
eternal hollowBOT
# ivory flax ```public class Main { public static void main(String[] args) { doub...

Detected code, here are some useful tools:

Formatted code
public class Main {
  public static void main(String[] args) {
    double xLoc = 30;
    double yLoc = 20;
    double xVel = 5;
    double yVel =  - 5;
    final int rightWall = 100;
    final int ceiling = 100;
    final double diameter = 4;
    for (int v = 0; v < Math.abs(yVel); v++) {
      boolean bounced = false;
      // if Velocity is downwards
      if (0 > yVel) {
        //if hits wall
        if (yLoc - v < (diameter / 2)) {
          //bounce on y axis
          bounced = true;
        }
        if (bounced) {
          yLoc++;
        }
        else {
          yLoc--;
        }
      }
      if ((yLoc + v) > ceiling - (diameter / 2)) {
        bounced = true;
      }
      if (bounced) {
        yLoc--;
      }
      else {
        yLoc++;
      }
    }
  }
}
}
}
ivory flax
#

This is currently what i got, working on the Y axis, i have a problem with my logic on the bounce mechanic of the problem, but not sure how to improve it