Java eclipse | Computer Science homework help

     

Java eclipse 

Assignment   5: If statements

Description                                                                                                                

In this assignment you will create a short text-based adventure game. The   user is presented with a short text description of the state of the game and   a small set of alternative actions to take. Based on the user’s response your   program will present a different game state. This continues until the game   ends; there may be several possible endings with different degrees of   success. The text of the game state and the alternatives are provided in a   table below. In each case   where an input is given by the user, “other” denotes any number   other than those explicitly listed in that action.

Functional   requirements:

1.  The   results of the user’s actions should be clear; make sure you use whitespace to separate the list of alternative   actions from the description of the next game state.

2.  Each time the user acquires   or loses an object, (such as the purse) you must print a message about the   object before describing the next game state.

Non-functional   requirements:

1.  You need not handle non-numeric data   (it’s ok if the program crashes for an input of “a”).

Grading rubric (described here):

  

Performance Indicator

[1]

[2]

[3]

 

Readability and documentation

1

2

2

 

Use of conditional operators

1

2

3

 

Functional requirements

2

3

5

 

Non-functional requirements

0

0

0

Sample   Run                                                                                                               

Sir Hero,   you have just left your castle gate in search of adventure. You begin the   journey with a horse, a sword, and a purse of coins. Along the road you meet   a decrepit old man who offers you a gold coin. What do you do?

1: Accept   the coin, add it to your purse
2: Decline the coin, but give the generous old man all of your money
Other: Ignore the man and ride on

Enter an   integer: 2

Decline the   coin, but give the generous old man all of your money
You have lost the purse.

A mile   past the old man a wandering grue menaces you with its fearsome claws. Grue are well known to be immune to the cut of a sword.   What do you do?

1: Attack   the grue with your something other than your sword
2: Attack the grue with   your sword
3: Ride past the grue
other: Turn back to your castle

Enter an   integer: 3

You ride   past the grue.

The grue leaps after you, taking down your noble steed from   behind. You sneak away while it eats your horse.
You have lost the horse.

Escaping   the fearsome grue, you finally have the good fortune to encounter a   proper opponent, a dragon, which you defeat with your mighty sword. Its head   would make a wondrous trophy hanging in your hall, but the treasure it hordes   would also be most welcome. Which is more important?

1:   treasure is most important
other: trophy is most important

Enter an   integer: 7

You think   the trophy is more important.

While   impressed with your dragon-head trophy, the serfs at your castle are   disappointed that not only did you fail to bring back any treasure; you lost   what you had when you set out. They kick you out of the castle and install a   new knight in your place. You turn to turnip farming.

Your tale has ended.

  

 
 

State Table

  

State

Description

   

User input

Outcome of each       input

 

1
    (start)

“Sir     Hero, you have just left your castle gate in search of adventure. You begin     the journey with a horse, a sword, and a purse of coins. Along the road you     meet a decrepit old man who offers you a gold coin. What do you do?”

   

1: accept the       coin, add it to your purse

go to state 3   
      coin=true

 

2: decline the       coin, give the old man all of your money

go to state 2
      purse = false

 

other: ride on

go to state 2

 

2

“A mile past     the old man a wandering grue menaces     you with its fearsome claws. Grue are     well known to be immune to the cut of a sword. What do you do?”

   

1: attack the grue with your something other than       your sword 

if purse ==       true go to state 4
      else go to state 5

 

2: attack the grue with your sword

go to state 8

 

3: ride on,       avoid the grue

go to state 6

 

other: return       to your castle

if purse ==       true go to state 9
      else go to state 3

 

3

“When you     return to your castle you find that your serfs are very disappointed in     your lack of heroism; they kick you out of the castle and install a new     knight in your place. You turn to turnip farming.”

End program

 

4

“You rush to     attack the grue, grabbing the only other weapon at hand, your coin     purse. Your blows have no effect. The grue slashes     at you but hits the coin purse, spilling gold coins everywhere. The grue gathers the coins and ignores     you.”

   

other: ride on 

purse = false
      go to state 7

 

5

“You rush to     attack the grue with     you bare hands, and it swallows you whole.”

End program

 

6

“The grue leaps after you, taking down your     noble steed from behind. You sneak away while it eats your horse.”

   

other: walk on 

horse = false
      go to state 7

 

7

“Escaping     the fearsome grue, you finally have the good fortune to encounter a     proper opponent, a dragon, which you defeat with your mighty sword. Its     head would make a wondrous trophy hanging in your hall, but the treasure it     hordes would also be most welcome. Which is more important?”

   

1: treasure is       most important
 

if horse==true       go to state 10  
      else go to state 11

 

other: trophy       is most important

if purse==true       go to state 10
      else go to state 12

 

8

“The grue swallows you, sword and all.

End program

 

9

“When you     return to your castle you find that your serfs are very disappointed in your     lack of heroism, but you pay for a lavish feast with your purse of gold and     all is well.”

End program

 

10

“You return     to your castle in triumph. Huzzah!”

End program

 

11

“Without a     horse, the burden of the treasure proves too much for you; you perish on     the road from fatigue.”

End program

 

12

“While     impressed with your dragon-head trophy, the serfs at your castle are     disappointed that not only did you fail to bring back any treasure, you     lost what you had when you set out. They kick you out of the castle and     install a new knight in your place. You turn to turnip farming.”

End program