Advertisement
simonradev

Test

Mar 18th, 2018
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.69 KB | None | 0 0
  1. namespace ConsoleApp1
  2. {
  3.     using System;
  4.     using System.Text;
  5.    
  6.     public class Startup
  7.     {
  8.         public static void Main()
  9.         {
  10.             string[] labelsForBars = new string[]
  11.             {
  12.                 "Health",
  13.                 "Energy"
  14.             };
  15.  
  16.             const char BarBoard = '|';
  17.             const char FullSymbol = '|';
  18.             const char EmptySymbol = '.';
  19.  
  20.             string name = Console.ReadLine();
  21.  
  22.             StringBuilder result = new StringBuilder();
  23.             result.AppendLine($"Name: {name}");
  24.             for (int indexOfBarLabel = 0; indexOfBarLabel < labelsForBars.Length; indexOfBarLabel++)
  25.             {
  26.                 string currentBarLabel = labelsForBars[indexOfBarLabel];
  27.  
  28.                 int currentValue = int.Parse(Console.ReadLine());
  29.                 int maxValue = int.Parse(Console.ReadLine());
  30.  
  31.                 string createdBar = CreateBar(currentBarLabel,
  32.                                               currentValue,
  33.                                               maxValue,
  34.                                               BarBoard,
  35.                                               FullSymbol,
  36.                                               EmptySymbol);
  37.                 result.AppendLine(createdBar);
  38.             }
  39.  
  40.             Console.WriteLine(result.ToString().Trim());
  41.         }
  42.  
  43.         private static string CreateBar(string label,
  44.                                         int currValue,
  45.                                         int maxValue,
  46.                                         char barBoard,
  47.                                         char fullSymbol,
  48.                                         char emptySymbol)
  49.         {
  50.             StringBuilder createdBar = new StringBuilder();
  51.             createdBar.Append($"{label}: {barBoard}");
  52.  
  53.             int countOfFull = Math.Min(currValue, maxValue);
  54.             int countOfEmpty = Math.Min(maxValue - currValue, maxValue);
  55.  
  56.             string repeatedFullSymbols = RepeatSymbol(fullSymbol, countOfFull);
  57.             string repeatedEmptySymbols = RepeatSymbol(emptySymbol, countOfEmpty);
  58.  
  59.             createdBar.Append(repeatedFullSymbols);
  60.             createdBar.Append(repeatedEmptySymbols);
  61.  
  62.             createdBar.Append(barBoard);
  63.             return createdBar.ToString();
  64.         }
  65.  
  66.         private static string RepeatSymbol(char symbolToRepeat, int timesToRepeat)
  67.         {
  68.             StringBuilder repeatedSymbol = new StringBuilder();
  69.             for (int i = 0; i < timesToRepeat; i++)
  70.             {
  71.                 repeatedSymbol.Append(symbolToRepeat);
  72.             }
  73.  
  74.             return repeatedSymbol.ToString();
  75.         }
  76.     }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement