+ 2

Can you please share the solution for the abstract classes practice in java?

Hello everyone! I think I found the solution but the console is declaring it incorrect. Can you please share the solution if you have?

24th Mar 2023, 6:14 PM
Saidazim
Saidazim - avatar
22 Antworten
+ 5
You are missing the semi-colon ";" after your print statement ("Kill the enemy king.")
25th Mar 2023, 7:01 AM
Ausgrindtube
Ausgrindtube - avatar
+ 5
Can we see your code first? Copy the task, add that here. Then, copy your code answer, create a code in the code playground, paste your code there, save it and attach it here.
24th Mar 2023, 6:59 PM
Ausgrindtube
Ausgrindtube - avatar
+ 3
Share your tried code with task description here..., if you want to know what went wrong in your code. Sharing solutions not helps you in learning...
24th Mar 2023, 8:11 PM
Jayakrishna 🇮🇳
+ 3
Show your attempt
24th Mar 2023, 10:41 PM
Hasnain [ACTIVE CHALLENGER]
Hasnain [ACTIVE CHALLENGER] - avatar
+ 2
Omg! I read this code more than 10 times but did not see this mistake. Thank you so much dear Ausgrindtube !
25th Mar 2023, 7:25 AM
Saidazim
Saidazim - avatar
+ 2
Yes. Missing semicolon. And you never using getName() method. .. !?! Is it used in next lesson?!?! Fine. Always share code link instead of copy paste code next time so it will easy you to find mistakes...
25th Mar 2023, 9:24 AM
Jayakrishna 🇮🇳
+ 2
Glad I could help Saidazim, it happens to us all . Happy coding!
25th Mar 2023, 10:58 AM
Ausgrindtube
Ausgrindtube - avatar
+ 2
Thanks all of you!
25th Mar 2023, 11:17 AM
Saidazim
Saidazim - avatar
+ 2
Ahh! Now I see it. King should be lower-case king.
11th Sep 2023, 1:24 PM
Ausgrindtube
Ausgrindtube - avatar
+ 1
class Main { public static void main(String[] args) { //do not touch this code Monopoly monopoly = new Monopoly(); Chess chess = new Chess(); Battleships battleships = new Battleships(); monopoly.play(); chess.play(); battleships.play(); } } abstract class Game { abstract String getName(); abstract void play(); } class Monopoly extends Game { //give "Monopoly" name to game String getName() { return "Monopoly"; } // play method should print "Buy all property." void play() { System.out.println("Buy all property."); } } class Chess extends Game { //give "Chess" name to game String getName() { return "Chess"; } // play method should print "Kill the enemy king." void play() { System.out.println("Kill the enemy king.") } } class Battleships extends Game { //give "Battleships" name to game String getName() { return "Battleships" ; }
25th Mar 2023, 2:51 AM
Saidazim
Saidazim - avatar
25th Mar 2023, 2:57 AM
Saidazim
Saidazim - avatar
+ 1
It looks fine and works for me. Did you copy and paste the text in the print statements? Maybe remove the spaces and full stops and add them in manually, see if that changes anything. Also check the task and make sure it matches everything exactly (which it looks like it does)
11th Sep 2023, 1:19 PM
Ausgrindtube
Ausgrindtube - avatar
+ 1
Thank you
11th Sep 2023, 1:26 PM
Nyivuru Resper
Nyivuru Resper - avatar
+ 1
Happy I could help you out! Enjoy your coding!
11th Sep 2023, 6:56 PM
Ausgrindtube
Ausgrindtube - avatar
+ 1
That's the working code Ausgrindtube thanks for spotting the error earlier about "king" being in uppercase yet it was supposed to be in lower case.
12th Sep 2023, 8:29 AM
Nyivuru Resper
Nyivuru Resper - avatar
0
// play method should print "Sink all ships." void play() { System.out.println("Sink all ships."); } }
25th Mar 2023, 2:53 AM
Saidazim
Saidazim - avatar
0
Hello, am also having issue running this code. Can anyone help. public class Main { public static void main(String[] args) { //do not touch this code Monopoly monopoly = new Monopoly(); Chess chess = new Chess(); Battleships battleships = new Battleships(); monopoly.play(); chess.play(); battleships.play(); } } abstract class Game { abstract String getName(); abstract void play(); } class Monopoly extends Game { //give "Monopoly" name to game public String getName() { return "Monopoly"; } // play method should print "Buy all property." public void play() { System.out.println("Buy all property."); } } class Chess extends Game { //give "Chess" name to game public String getName() { return "Chess"; } // play method should print "Kill the enemy king." public void play() { System.out.println("Kill the enemy King."); } } class Battleships extends Game { //give "Battleships" name to game public String getName() { return "Battleships"; } // play method should print "Sink all ships." public void play() { System.out.println("Sink all ships."); } }
11th Sep 2023, 12:36 PM
Nyivuru Resper
Nyivuru Resper - avatar
0
class Main { public static void main(String[] args) { //do not touch this code Monopoly monopoly = new Monopoly(); Chess chess = new Chess(); Battleships battleships = new Battleships(); monopoly.play(); chess.play(); battleships.play(); } } abstract class Game { abstract String getName(); abstract void play(); } class Monopoly extends Game { //give "Monopoly" name to game String getName() { return "Monopoly"; } // play method should print "Buy all property." void play() { System.out.println("Buy all property."); } } class Chess extends Game { //give "Chess" name to game String getName() { return "Chess"; } // play method should print "Kill the enemy king." void play() { System.out.println("Kill the enemy King."); } } class Battleships extends Game { //give "Battleships" name to game String getName() { return "Battleships"; } // play method should pr
11th Sep 2023, 1:19 PM
Nyivuru Resper
Nyivuru Resper - avatar
0
I write all code manually the ones that were missing.
11th Sep 2023, 1:23 PM
Nyivuru Resper
Nyivuru Resper - avatar
0
Ausgrindtube I even copied and pasted the code in both ChatGBT and an online java compiler to see whether errors exists, but none. They all ran the code without any errors returned.
11th Sep 2023, 1:25 PM
Nyivuru Resper
Nyivuru Resper - avatar