Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Project 2: Text Based Game (java) 1. Use the following starter code for your TextBasedGame class: class TextBasedGame { public void intro() { System.out.println(You are

Project 2: Text Based Game (java)

1. Use the following starter code for your TextBasedGame class:

class TextBasedGame { public void intro() { System.out.println("You are standing in an open field west of a white house, with a boarded front door. There is a small mailbox here"); } } 

Important Note: The TextBasedGame class cannot hold the main method. You will need a separate class to hold the main method. The other class may be named Main or Application or your project name.

2. Create a method for the TextBasedGame class that will take a command as input from the user. In the input method, use conditional statements to handle these commands-

  • about - if the user inputs this command, run the intro method
  • help - if the user inputs this command, run a help method that will display a list of commands
  • open - if the user inputs this command, ask the user which item to open, then run the open method (see below).
  • quit - if the user inputs this command, end the game
  • One additional command. Select it from the Text Based Game Cheat Sheet. (Links to an external site.) Create a method for the command and call that method if the user inputs the command.

Hint: For your conditional statements, read this Module topic on how to compare two String instances in an if clause and pay close attention to the last section on Scanner: Comparing Strings

3. Create an open method with the following header:

public void open(String item)

The parameter item will hold the item being opened.

This method should display a message indicating which item has been opened. For example, depending on the argument provided when the method is called, the open method might display:

mailbox is open.

Optionally, display a message indicating what is found inside. You decide what is found in the item. For example, this might be displayed (not required):

key is found inside

4. In the main method of your other class (which may be called Main, Application or project name), create an instance of the TextBasedGame class and call the input method for testing. Be sure to test all commands.

5. Copy and paste the output of your program into a multi-line comment at the bottom of your .java file or paste it into the submission window (2 points)

/* This is a multi-line comment in Java */

Final Check Before Submitting:

  1. You should have these six (6) methods in the TextBasedGame class:
    1. input
    2. intro
    3. about
    4. help
    5. open
    6. quit
    7. one additional method for a command from the Text Based Game Cheat Sheet. (Links to an external site.)
  2. The main method in the other class (Main, Application or project name) should create an instance of the TextBasedGame class and use that instance to call the input method.
  3. Test each command.
  4. Paste your output for all test runs into a multi-line comment at the bottom of your .java file or in the assignment submission window.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Spatial Database Systems Design Implementation And Project Management

Authors: Albert K.W. Yeung, G. Brent Hall

1st Edition

1402053932, 978-1402053931

More Books

Students also viewed these Databases questions

Question

Find the derivative. f(x) 8 3 4 mix X O 4 x32 4 x32 3 -4x - x2

Answered: 1 week ago