Enums - help with this exercise | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Enums - help with this exercise

I need help with this exercise, I have done it with the Switch statement, however something seems to be wrong or something is missing. The exercise mentions the following: A racing video game has 3 levels of difficulty: Easy, Medium, and Hard. Each difficulty level is assigned a maximum time to complete the track: the higher the difficulty, the shorter the time. The program you are given defines the Player class and the Difficulty enumeration, and creates 3 Player objects with different difficulties as parameters for the constructor. Complete the Player constructor, which takes the enumeration as a parameter to verify the time of each difficulty option and emits the corresponding message: Easy => "You have 3 minutes 45 seconds" Medium => "You have 3 minutes 20 seconds" Hard => "You have 3 minutes" Use a switch statement to check each option in the enum and execute the output. This is my code: https://code.sololearn.com/czIpdSXDNxXG/?ref=app

8th Jul 2021, 11:26 PM
Alex Narváez
Alex Narváez - avatar
10 Answers
- 1
as x is given as argument of constructor, you do not have to initialize it... comment the line: //Difficulty x = Difficulty.Hard
8th Jul 2021, 11:29 PM
visph
visph - avatar
+ 4
using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; namespace SoloLearn { class Program { static void Main(string[] args) { Player player1 = new Player(Difficulty.Easy); Player player2 = new Player(Difficulty.Medium); Player player3 = new Player(Difficulty.Hard); } } /* Easy => "You have 3 minutes 45 seconds" Medium = > "You have 3 minutes 20 seconds" Hard => "You have 3 minutes" */ class Player { public Player(Difficulty x) { switch (x) { case Difficulty.Easy: Console.WriteLine("You have 3 minutes 45 seconds"); break; case Difficulty.Medium : Console.WriteLine("You have 3 minutes 20 seconds"); break; case Difficulty.Hard: Console.WriteLine("You have 3 minutes"); break; } } } enum Difficulty { Easy, Medium, Hard }; }
21st May 2022, 1:34 PM
Gelbert Millones
+ 1
using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; namespace SoloLearn { class Program { static void Main(string[] args) { int num = Convert.ToInt32(Console.ReadLine()); switch (num) { case 1: Console.WriteLine("Easy"); break; case 2 : Console.WriteLine("Medium"); break; case 3: Console.WriteLine("Hard"); break; default: Console.WriteLine ("Invalid option"); break; } } } } // Try not to follow me
22nd Aug 2022, 3:07 AM
Abdul Bari Rahmani
Abdul Bari Rahmani - avatar
+ 1
You only need to copy the outputs from outcommend code. Sololearn sucks with spaces ore taps
29th Nov 2022, 10:29 AM
Luca Nürenberg
Luca Nürenberg - avatar
0
Found out what was wrong had to do with spaces and tabs :-(
25th Sep 2022, 4:59 PM
Christopher Egan
Christopher Egan - avatar
0
JcB
13th Feb 2023, 2:33 PM
Muneesh Rayal
Muneesh Rayal - avatar
0
Bhbhh
13th Feb 2023, 2:34 PM
Muneesh Rayal
Muneesh Rayal - avatar
0
Fggg
13th Feb 2023, 2:34 PM
Muneesh Rayal
Muneesh Rayal - avatar
- 1
Excellent! visph thank you very much for your help. You're the best
8th Jul 2021, 11:35 PM
Alex Narváez
Alex Narváez - avatar
- 1
Hi Everybody I am a bit stuck on this one. it looks like it works i get the three messages but the test says its wrong. not sure what i am doing wrong. can somebody help me in the right direction using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; namespace SoloLearn { class Program { static void Main(string[] args) { Player player1 = new Player(Difficulty.Easy); Player player2 = new Player(Difficulty.Medium); Player player3 = new Player(Difficulty.Hard); } } /* Easy => "You have 3 minutes 45 seconds" Medium => "You have 3 minutes 20 seconds" Hard => "You have 3 minutes" */ class Player { public Player(Difficulty x) { //your code goes here switch (x){ case Difficulty.Easy: Console.WriteLine("Easy => "+"You have 3 minutes 45 seconds"); break; case Difficulty.Medium: Console.WriteLine("Medium => "+"You have 3 minutes 20 seconds"); break; case Difficulty.Hard: Console.WriteLine("Hard => "+"You Have 3 minutes"); break; } } } enum Difficulty { Easy, Medium, Hard }; } Thanks
24th Sep 2022, 11:43 PM
Christopher Egan
Christopher Egan - avatar