Something is wrong with this code. Can someone help? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Something is wrong with this code. Can someone help?

Hi GUYS. TODAY I CREATED A CODE USING JAVA. I STARTED THE JAVA COURSE JUST 3 DAYS AGO. I MADE MY FIRST CODE AND THIS WAS GOING TO BE MY SECOND CODE. BUT UNFORTUNATELY, I GOT 26 ERRORS!!! I RALLY WANT TO FIX THIS THE IDEA JUST SEEMES SO GREAT. CAN SOMEONE PLEASE HELP. HERE IS THE CODE: public class Ninja { void attack(){ System.out.println("Attack!"); } void defend(){ System.out.println("Enemy is attacking. Initiate all shields!"); } void win(){ System.out.println("We won"); } void lose(){ System.out.println("We lost"); } } public class Enemy{ void attack(){ System.out.println("Enemy is attacking us"); } void retreat(){ System.out.println("Enemy is retreating!"); } void defend(){ System.out.println("Enemy is blocking our attack"); } } public static void main(String[] args) { Ninja ninja = new Ninja(); Enemy enemy = new Enemy(); int x = 2; switch(x){ case 1: ninja.attack(); enemy.defend(); ninja.attack(); ninja.win(); break; case 2: enemy.attack(); ninja.defend(); ninja.lose(); break; case 3: ninja.attack(); ninja.attack(); enemy.defend(); enemy.retreat(); ninja.win(); break; case 4: enemy.attack(); ninja.defend(); enemy.attack(); ninja.lose(); break; case 5: ninja.attack(); enemy.defend(); enemy.defend(); ninja.attack(); enemy.retreat(); ninja.win(); break; } } } I WOULD REALLY APPRICIATE IF YOU HELPED. THANKS 😊

11th Jul 2020, 4:39 PM
エLoVョやy十hon
エLoVョやy十hon - avatar
2 Answers
11th Jul 2020, 5:10 PM
Vadivelan
0
Here is the code in the code playground: https://code.sololearn.com/czW576sc6zMu/?ref=app
11th Jul 2020, 5:07 PM
エLoVョやy十hon
エLoVョやy十hon - avatar