'F' → Fullscreen
Today you inherit someone else's program, named 2-6-monster-cards. It prints trading cards for a monster game, and whoever wrote it built every card by copying the one above. Your job is to turn it into a method without changing a single character of what it prints — and then to find out whether the program was right in the first place.
How to read the code blocks. Each task's code block shows your whole program, from line 1, as it should look when that task is finished.
The green lines marked with a + are the ones you add or change for that task — everything else is already in your file. Do not type the + sign. Your Task 1 comment sits below the last line shown and is not repeated.
power that adds them, and a rarity: RARE at 10 or more./* and */, the way the deck showed. You will compare against it in Task 2.string name1 = "Glimmerfang";int attack1 = 7;int defense1 = 3;int power1 = attack1 + defense1;Console.WriteLine($"=== {name1} ===");Console.WriteLine($" ATK {attack1} DEF {defense1} POWER {power1}");if (power1 >= 10){ Console.WriteLine(" Rarity: RARE");}else{ Console.WriteLine(" Rarity: common");}
string name2 = "Mossback";int attack2 = 2;int defense2 = 6;int power2 = attack2 + defense2;Console.WriteLine($"=== {name2} ===");Console.WriteLine($" ATK {attack2} DEF {defense2} POWER {power2}");if (power2 >= 10){ Console.WriteLine(" Rarity: RARE");}else{ Console.WriteLine(" Rarity: common");}
string name3 = "Emberwyrm";int attack3 = 9;int defense3 = 4;int power3 = attack3 + defense2;Console.WriteLine($"=== {name3} ===");Console.WriteLine($" ATK {attack3} DEF {defense3} POWER {power3}");if (power3 >= 10){ Console.WriteLine(" Rarity: RARE");}else{ Console.WriteLine(" Rarity: common");}PrintCard method and three calls. Keep your comment.PrintCard("Glimmerfang", 7, 3);PrintCard("Mossback", 2, 6);PrintCard("Emberwyrm", 9, 4);
void PrintCard(string name, int attack, int defense){ int power = attack + defense; Console.WriteLine($"=== {name} ==="); Console.WriteLine($" ATK {attack} DEF {defense} POWER {power}");
if (power >= 10) { Console.WriteLine(" Rarity: RARE"); } else { Console.WriteLine(" Rarity: common"); }}Status did. Count how many places you had to change.PrintCard("Glimmerfang", 7, 3);PrintCard("Mossback", 2, 6);PrintCard("Emberwyrm", 9, 4);PrintCard("Voltlynx", 8, 8);PrintCard("Pebblet", 1, 1);
void PrintCard(string name, int attack, int defense){ int power = attack + defense; Console.WriteLine($"=== {name} ==="); Console.WriteLine($" ATK {attack} DEF {defense} POWER {power}");
if (power >= 15) { Console.WriteLine(" Rarity: LEGENDARY"); } else if (power >= 10) { Console.WriteLine(" Rarity: RARE"); } else { Console.WriteLine(" Rarity: common"); }}Two classmates each “tidied” the LEGENDARY check and swear nothing changed. Try each one in your program, one at a time, and record the output.
power >= 15 to power > 14.power >= 15 to power > 15.With the five cards you have, both match your Task 3 output exactly. Now add one more monster, PrintCard("Tidecrown", 10, 5);, and run all three versions again: yours, Riley's, and Sam's.
Say which tidy-up is a true refactor and which is not, and explain why the five original cards could not tell them apart. Is there any whole number of power where Riley's version would give a different rarity from yours?
There is no code block for this task. When it is over, put power >= 15 back and keep Tidecrown: your program is Task 3 with a sixth card.
Your finished program, with Tidecrown added, prints exactly this.
=== Glimmerfang === ATK 7 DEF 3 POWER 10 Rarity: RARE=== Mossback === ATK 2 DEF 6 POWER 8 Rarity: common=== Emberwyrm === ATK 9 DEF 4 POWER 13 Rarity: RARE=== Voltlynx === ATK 8 DEF 8 POWER 16 Rarity: LEGENDARY=== Pebblet === ATK 1 DEF 1 POWER 2 Rarity: common=== Tidecrown === ATK 10 DEF 5 POWER 15 Rarity: LEGENDARYPrintCard method prints every card, and it is below the main programAnswer the following questions before submitting your work.
PrintCard cannot make that mistake.Submit four things to the dropbox: