Guest User

C# ToWierdCase - Console Impl - Bad Code Challenge #13

a guest
Jun 18th, 2019
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.88 KB | None | 0 0
  1. using System;
  2. using System.Dynamic;
  3. using System.Collections.Generic;
  4. using System.Collections;
  5.                    
  6. public class Program
  7. {
  8.     public static readonly string[] UPPERCASE = new string[] { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" };
  9.    
  10.     public static readonly string[] LOWERCASE = new string[] { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z" };
  11.    
  12.     public static readonly int[] ODDNUMBERS = new int[] { 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39, 41, 43, 45, 47, 49, 51, 53, 55, 57, 59, 61, 63 };
  13.    
  14.     //is zero an even number?
  15.     public static readonly int[] EVENNUMBERS = new int[] { 0,2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58, 60, 62, 64 };
  16.    
  17.     public static void Main()
  18.     {
  19.         Console.WriteLine("Please enter a sentence to weirdcase");
  20.         string i = Console.ReadLine();
  21.         Console.WriteLine(ToWeirdCase(i));
  22.     }
  23.    
  24.     public static string ToWeirdCase(string userstring)
  25.     {
  26.         string weird = "";
  27.         int ustrpos = 0;
  28.         int size = 1;
  29.        
  30.         for(int i = 0; i < userstring.Length; i++)
  31.         {
  32.             char[] stringCharacters = userstring.ToCharArray();
  33.             weird = weird + ToCorrectCase(stringCharacters[ustrpos].ToString(), ustrpos);
  34.             ustrpos = ustrpos + 1;
  35.         }
  36.            
  37.         return weird;
  38.     }
  39.    
  40.     public static string ToCorrectCase(string l, int p)
  41.     {
  42.         string correctString = l;
  43.        
  44.         if(IsEvenNumber(p) && IsLowerCaseLetter(l)) {
  45.             correctString = l;
  46.             return correctString;
  47.         }
  48.         if(IsEvenNumber(p) && IsUpperCaseLetter(l)) {
  49.             //we need to find out which uppercase character and get it's lowercase equivalent
  50.             correctString = ToLowerCase(l);
  51.             return correctString;
  52.         }  
  53.         if(IsOddNumber(p) && IsLowerCaseLetter(l)) {
  54.             //we need to find out which lowercase character and get it's uppercase equivalent
  55.             correctString = ToUpperCase(l);
  56.             return correctString;
  57.         }
  58.         if(IsOddNumber(p) && IsUpperCaseLetter(l)) {
  59.             correctString = l;
  60.             return correctString;
  61.         }
  62.        
  63.         return correctString;
  64.     }
  65.    
  66.     public static bool IsEvenNumber(int n)
  67.     {
  68.         bool isEven = true;
  69.        
  70.         for(int i = 0; i < EVENNUMBERS.Length; i++)
  71.         {
  72.             if(EVENNUMBERS[i] == n){
  73.                 isEven = true;
  74.                 break;
  75.             }
  76.             else{
  77.                 isEven = false;;
  78.             }
  79.         }
  80.        
  81.         return isEven;
  82.     }
  83.    
  84.     public static bool IsOddNumber(int n)
  85.     {
  86.         bool isEven = true;
  87.        
  88.         for(int i = 0; i < ODDNUMBERS.Length; i++)
  89.         {
  90.             if(ODDNUMBERS[i] == n){
  91.                 isEven = false;
  92.                 break;
  93.             }
  94.             else{
  95.                 isEven = true;
  96.             }
  97.         }
  98.        
  99.         return !isEven;
  100.     }
  101.    
  102.     public static bool IsUpperCaseLetter(string letter)
  103.     {
  104.         bool isUpperCase = true;
  105.        
  106.         for(int i = 0; i < UPPERCASE.Length; i++)
  107.         {
  108.             if(UPPERCASE[i] == letter){
  109.                 isUpperCase = true;
  110.                 break;
  111.             }
  112.             else{
  113.                 isUpperCase = false;;
  114.             }
  115.         }
  116.        
  117.         return isUpperCase;
  118.     }
  119.    
  120.     public static bool IsLowerCaseLetter(string lietter)
  121.     {
  122.         bool isUpperCase = true;
  123.        
  124.         for(int i = 0; i < LOWERCASE.Length; i++)
  125.         {
  126.             if(LOWERCASE[i] == lietter){
  127.                 isUpperCase = true;
  128.                 break;
  129.             }else {
  130.                 isUpperCase = false;
  131.             }
  132.         }
  133.        
  134.         return isUpperCase;
  135.     }
  136.    
  137.     public static string ToUpperCase(string lttr)
  138.     {
  139.         //Which character is it?
  140.         int characterArryIndex = 0;
  141.         for(int i = 0; i < LOWERCASE.Length; i++)
  142.         {
  143.             if(LOWERCASE[i] == lttr)
  144.             {      
  145.                 characterArryIndex = i;
  146.                 break;
  147.             }
  148.         }
  149.        
  150.         //Now get the replacement
  151.         return UPPERCASE[characterArryIndex];
  152.     }
  153.    
  154.     public static string ToLowerCase(string lttr)
  155.     {
  156.         //Which character is it?
  157.         int characterArryIndex = 0;
  158.         for(int i = 0; i < UPPERCASE.Length; i++)
  159.         {
  160.             if(UPPERCASE[i] == lttr)
  161.             {      
  162.                 characterArryIndex = i;
  163.                 break;
  164.             }
  165.         }
  166.        
  167.         //Now get the replacement
  168.         return LOWERCASE[characterArryIndex];
  169.     }
  170. }
Advertisement
Add Comment
Please, Sign In to add comment