OOP Exercises For Slot 456
OOP Exercises For Slot 456
Use object-oriented programming method to create a C# program with the following requirements:
Users enter a number of sides of Dice
The program will generate a random number from 1 to the number of sides
Users will input a guessing number and get the results of the guessing.
What classes should we create?
- Class: Dice
o Fields: slides
o Methods: roll (generate a random number from 1 to sides)
- A class to run the program
Exercise 3
Define a class Song, which holds the following information about songs: Type List, Name and Time.
On the first line you will receive the number of songs - N.
On the next N-lines you will be receiving data in the following format:
"{typeList}_{name}_{time}".
On the last line you will receive Type List / "all". Print only the Names of the songs which are from
that Type List / All songs.
Examples
Input Output
3 DownTown
favourite_DownTown_3:14 Kiss
favourite_Kiss_4:16 Smooth Criminal
favourite_Smooth Criminal_4:01
favourite
4 Andalouse
favourite_DownTown_3:14
listenLater_Andalouse_3:24
favourite_In To The Night_3:58
favourite_Live It Up_3:48
listenLater
2 Replay
like_Replay_3:15 Photoshop
ban_Photoshop_3:48
all
Solution of Exercise 2
Define class Song with properties: Type List, Name and Time.
Read the input lines, make collection and store the data.