Question: Hi I need to answer the below questions based on the below code. var rnd = new Random(); var minValue = 0; var maxValue =

Hi I need to answer the below questions based on the below code.

var rnd = new Random(); var minValue = 0; var maxValue = 3; var num = rnd.Next(minValue, maxValue + 1); // you can assume num is a random number between 0 and 3

var list = new [] {"Worst day ever!", "Lay low", "Smooth sailing", "World domination"};

if (num == 0) Console.WriteLine(list[0]);

for (int i = 0; i <= 3; i++) { switch (num) {

case 1: if (i == num) Console.WriteLine(list[1]); break; case 2: if (i == num) Console.WriteLine(list[2]); break; case 3: if (i == num) Console.WriteLine(list[3]); break; } }

Question 1:

What would be output to the console if the random number generator sets num to 0

Lay low

Nothing

Smooth sailing

Worst day ever! Worst day ever! Worst day ever! Worst day ever!

World domination

Worst day ever!

Clear selection

Question 2:

What would be output to the console if the random number generator sets num to 2

Worst day ever!

Lay low

Smooth sailing

World domination

Nothing

Smooth sailing Smooth sailing Smooth sailing Smooth sailing

Question 3:

Re-write the code after the declaration of the variables num and list to be clearer and more concise.

Your answer

Question 4:

What do you call this kind of code simplification, code reorganization and code clutter removal?

Question 5:

Given you want to make the code enhancement you suggested above, what tests would you write to make sure you don't break the code?

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!