Answer to Question #285854 in Java | JSP | JSF for Saphira

Question #285854

Create a simple text-based console game that implements at least three (3) interfaces. Below is the initial part of a sample program.

Enter your name: Nika

Press 1 or 2 to select your game mode.

1- Story

2 - Survival

Press P to start playing, Nika.


1
Expert's answer
2022-01-09T02:20:49-0500
import java.util.Scanner;

public class Main implements Runnable, Comparable<Main>, AutoCloseable {

    @Override
    public void close() throws Exception {
        System.out.println("Gotcha!");
    }

    @Override
    public int compareTo(Main o) {
        return 0;
    }

    @Override
    public void run() {
        while (true) {
            System.out.println("Doing something.");
        }
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        System.out.print("Enter your name: ");
        String name = in.nextLine();
        System.out.println("Press 1 or 2 to select your game mode.\n1-Story\n2-Survival");
        String choice = in.nextLine();
        System.out.println("Press P to start playing Nika.");
        String play = in.nextLine();
        if (play.equalsIgnoreCase("n")) {
            if (choice.equalsIgnoreCase("1")) {
                System.out.println("Long story short, " + name + ", you lost.");
            } else if (choice.equalsIgnoreCase("2")) {
                System.out.println(name + ", you didn't survive. ");
            }
        }
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog