+ 3

Need help with java abstract class lesson

Can't seem to get passed the java abstract lesson on java intermediate course. What it wants as output is unclear and also locked. I have looked at the solution it gives you. Still doesn't work. All the main seems to call is the play() method for each game. I have tested my code and it output'd exactly that. Also tested my code to make sure name is given to game class as it asks, that also worked. I there something I'm missing? This is my code... 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.getName(); chess.getName(); battleships.getName(); monopoly.play(); chess.play(); battleships.play(); } } abstract class Game { public String name; abstract String getName(); abstract void play(); } class Monopoly extends Game { //give "Monopoly" name to game String getName() { name = "Monopoly"; return name; } // 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() { name = "Chess"; return name; } // 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() { name = "Battleships"; return name; } // play method should print "Sink all ships." void play() { System.out.println("Sink all ships."); } }

5th Mar 2023, 10:10 AM
Crazy Okon
4 Antworten
+ 7
My first hint is to copy your code into the code playground and see what it does. I think you're missing something, that hopefully when you run your code, you'll see what it is.
5th Mar 2023, 10:21 AM
Ausgrindtube
Ausgrindtube - avatar
+ 4
Happy to hear the hint helped. Well done on figuring it out! Enjoy your coding!
5th Mar 2023, 11:02 AM
Ausgrindtube
Ausgrindtube - avatar
+ 3
Sorted thanks for help Ausgrindtube.
5th Mar 2023, 11:00 AM
Crazy Okon
+ 2
Is the thing I'm missing, printing the quote marks?
5th Mar 2023, 10:52 AM
Crazy Okon