Advertisement
Guest User

Alexandr_Cosov_OOP_17.10.19

a guest
Oct 17th, 2019
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.91 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace OOP_second_class
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             firstTask();
  14.         }
  15.  
  16.         public static void firstTask()
  17.         {
  18.             while (true)
  19.             {
  20.                 colours userInput = drawMenuAndAskForInput();
  21.                 switch (userInput)
  22.                 {
  23.                     case colours.Black:
  24.                         Console.BackgroundColor = ConsoleColor.Black;
  25.                         Console.ForegroundColor = ConsoleColor.White;
  26.                         Console.Clear();
  27.                         break;
  28.                     case colours.White:
  29.                         Console.BackgroundColor = ConsoleColor.White;
  30.                         Console.ForegroundColor = ConsoleColor.Black;
  31.                         Console.Clear();
  32.                         break;
  33.                     default:
  34.                         Console.WriteLine("Not supported");
  35.                         break;
  36.  
  37.                 }
  38.  
  39.             }
  40.         }
  41.  
  42.         public static colours drawMenuAndAskForInput()
  43.         {
  44.             Console.WriteLine("Choose a colour for the background");
  45.             Console.WriteLine(colours.Black + ": " + (int)colours.Black);
  46.             Console.WriteLine(colours.White + ": " + (int)colours.White);
  47.             Console.WriteLine(colours.Red + ": " + (int)colours.Red);
  48.             Console.WriteLine(colours.Blue + ": " + (int)colours.Blue);
  49.             Console.WriteLine(colours.Yellow + ": " + (int)colours.Yellow);
  50.             return (colours)Enum.Parse(typeof(colours),Console.ReadLine());
  51.         }
  52.  
  53.         public enum colours
  54.         {
  55.             Black = 1,
  56.             White,
  57.             Red,
  58.             Blue,
  59.             Yellow
  60.  
  61.         }
  62.  
  63.         public static void secondTask()
  64.         {
  65.             Console.WriteLine("Insert a sentence");
  66.  
  67.             string sentence = Console.ReadLine();
  68.             Console.WriteLine("Number of words: " + sentence.Split(' ').Length);
  69.  
  70.             string[] words = sentence.Split(' ');
  71.             for (int counter = 0; counter < words.Length; counter++)
  72.             {
  73.                 if (counter % 2 != 0)
  74.                 {
  75.                     Console.WriteLine(words[counter].ToLower());
  76.                 }
  77.                 else
  78.                 {
  79.                     Console.WriteLine(words[counter].ToUpper());
  80.                 }
  81.             }
  82.         }
  83.  
  84.         public static void thirdTask()
  85.         {
  86.             Console.WriteLine("Insert a sentence");
  87.             string sentence = Console.ReadLine();
  88.  
  89.             sentence = sentence
  90.                 .TrimStart('!','-','/')
  91.                 .Substring(0,20)
  92.                 .Replace('a', 'A')
  93.                 .Replace('e', 'E')
  94.                 .Replace('i', 'I')
  95.                 .Replace('o', 'O')
  96.                 .Replace('u', 'U');
  97.  
  98.             Console.WriteLine(sentence);
  99.         }
  100.  
  101.         public static void fourthTask()
  102.         {
  103.             while (true)
  104.             {
  105.                 try
  106.                 {
  107.                     Console.WriteLine("Insert first int to divide");
  108.                     int firstInt = int.Parse(Console.ReadLine());
  109.  
  110.                     Console.WriteLine("Insert second int to divide");
  111.                     int secondInt = int.Parse(Console.ReadLine());
  112.  
  113.                     var result = firstInt / secondInt;
  114.                     Console.WriteLine(result);
  115.                    
  116.                 }
  117.                 catch(FormatException)
  118.                 {
  119.                     Console.WriteLine("Numbers have to be integers!");
  120.                 }
  121.                 catch(DivideByZeroException)
  122.                 {
  123.                     Console.WriteLine("It's not possible to divide by 0!");
  124.                 }
  125.             }
  126.         }
  127.     }
  128. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement