How to avoid getting caught for plagiarism again?

I got a 0 for my first Java assignment (there's 4 for the course) cause I was caught plagiarizing. But the thing is the professor accused me of copying another student when I just got the solution from Chegg. I changed some of the variables to make it less obvious but she somehow still found out. I suspect it's cause the other guy used Chegg too and both of our code was similar enough while not fulfilling assignment guidelines properly. She told me in my feedback also I was supposed to import JavaFX and not swing, which probably also gave it away that I cheated.

I did try to go to her for help and initially was against cheating, though at the time I had a shit ton of other assignments and exams to do. She sucks at communicating and often just ignores what I ask or reply to her in person and online. At least this and all the other assignments are merely worth 5% of my final grade each, and I already did pretty well on the midterm exam (which was open book). The labs may be worth 3% each, but there's 10 in total so focusing more on those will improve my grades over the assignments.

Do you guys have any tips for me to do better in the course, hopefully without cheating again? My current Java assignment doesn't have a solution on Chegg, and also the professor generously provided some reference files anyways. My course average before getting the 0 was at 73%... now after it has dropped to 65% which sucks. I've been through worse though; I remember failing my statistics course after the midterms yet making a comeback and passing it with over 80%. If she wasn't so shit and provided more help, I wouldn't have felt to use Chegg.
Updates
1 y
Anyone who gives useless advice and is a rude little shit will be blocked and have their answers removed, like that feminazi bitch
Updates
1 y
The bitch ass professor refused to give me proof when I asked for it and insisted I shouldn't copy from another student when I didn't
How to avoid getting caught for plagiarism again?
Post Opinion