Java

TOPIC 16 – IF STATEMENTS – PART 3

 

LESSON WORK

 

 

QUESTION 1

 

You work for Blizzard and you have been working on the latest release version of StarCraft.  You have created five different AI behaviours for the computer named as follows:

 

1.    Normal

2.    Aggressive

3.    Expander

4.    Defensive

5.    Destroyer

 

You have a simple job.  You must write the program that will randomly select one of the above AIs.  However, the odds that a specific AI is chosen need to be as follows:

 

·         Normal – 50%

·         Aggressive – 10%

·         Expander – 20%

·         Defensive – 15%

·         Destroyer – 5%

 

Before incorporating your program into StarCraft, you need to write the program that outputs results like shown below.

 

SAMPLE OUTPUT I

 

Random number: 0.5503532659
AI: Aggressive

SAMPLE OUTPUT II

 

Random number: 0.39405697593

AI: Normal

SAMPLE OUTPUT III

Random number: 0.965403054311
AI: Destroyer

QUESTION 2

Consider the following class:

 

public class SportsTeamName

{

    public String adjective;

    public String nickname;

    public String city;

}

You will write a program that will randomly create a SportsTeamName from a list of adjectives, nicknames and cities of your choosing.

Here are some examples:

 

Adjectives: Happy, Glorious, Totally Angry, Green, …

Nicknames: Hammers, Clowns, Maples, Sea Lions, …
Cities: Toronto, Sudbury, Montreal, Vancouver, …

 

Here is some sample output with the examples above:

 

SAMPLE OUTPUT 1
Team name:
Vancouver Glorious Maples


SAMPLE OUTPUT 2

Team name:
Toronto Totally Angry Sea Lions

Note: You must make use of the class above.  You must create the object.  Then you are to output the content of the object like in the sample output.