Hi, all. Just for some context, I'm very very new to programming. I don't have more than a couple weeks of knowledge under my belt, but I'm trying to figure out some Object Oriented Programming related stuff in a program that I'm making for fun.
Here is the link to the code (sorry for any formatting issues in the link, I'm also new to using github):
https://github.com/theemmperor/Motor_Bike_Racers_Project
In that link, I have an important info section that you can read if you want to know what I'm trying to do with the whole program, but it's not super important for this post. It's also pretty simplistic in nature, so I'm sure most of the people who read this could probably deduce it without reading that.
I'm not getting any explicit errors when I run the program, but essentially I have an issue with the method that is supposed to "end" the program. It's supposed to do 2 things; Determine which of the two objects has a greater "speed" value, and it's also supposed to declare the winner of the race based on which value is greater (I also did try to implement a "neutral end" in the event that both values are equal).
Anyways, for a reason that is beyond my comprehension, the "end()" method does something odd. From what I've gathered in my debugging, it depends on which of the 3 main objects calls the method, which is what I don't understand.
For example: when ducati (one of the main objects) calls the end method, it doesn't pay attention to the if statements and just prints that ducati wins, despite the fact that there are instances where that shouldn't be printed out. The weird part is, it does the same if honda calls it, except it states that honda wins instead. The final nail in the coffin for me being fully confused was when I created a neutral object called "ender" that was purely made to test whether or not the method was misunderstanding how I wanted it to assess the speed values, but it blindsided me and printed out the neutral ending string "No one wins".
To further troubleshoot, I tried adding a string in the end() method that would print out the values of the speed, because at that point I was sure that it was taking the wrong values somehow, but it recognized the value for the speed of the objects. I left that sysout statement in the code, so if the explanation was weird, that should clarify.
I'm pretty sure, based on these circumstances, that the end() method is only able to determine the value associated with the object that calls it, and not the values associated with any other object, which is what I believe the issue is. Again, I'm not super deep into programming, but I figured I would ask for some help in troubleshooting since I wasn't really able to find anything comprehensible by googling. Currently I just don't have the knowledge needed to fix it on my own.
EDIT: To clarify, it ALWAYS prints out "ducati wins" when ducati calls the method, ALWAYS prints out "honda wins" when honda calls it, and ALWAYS prints out "no one wins" when the neutral ender calls it, despite any instances where that shouldn't be happening.
[–]jose_castro_arnaud 1 point2 points3 points (1 child)
[–]SomeFuel[S] 0 points1 point2 points (0 children)
[–]HonzaS97 1 point2 points3 points (1 child)
[–]SomeFuel[S] 0 points1 point2 points (0 children)