public void PrimePrintSequenceOfNumbers() { PrimeNumbers Prime = new PrimeNumbers(); int length = 7; string expected = "2 3 5 7 11 13 17"; string actual = Prime.ToString(Prime.GetSequence(length)); Assert.AreEqual(expected, actual); }
public void PrimePrintOfSequenceOfNumbers() { PrimeNumbers primes = new PrimeNumbers(); int length = 8; string expected = "2 3 5 7 11 13 17 19"; string actual = primes.ToString(primes.GetSequence(length)); Assert.AreEqual(expected, actual); }
static void Main(string[] args) { string prompt = "> "; Console.WriteLine("What do you want me to do?"); Console.Write(prompt); string response = Console.ReadLine(); if (response.ToLower().Contains("numbers")) { Console.WriteLine("How many?"); Console.Write(prompt); int length; string response_length = Console.ReadLine(); bool parsed = int.TryParse(response_length, out length); if (parsed && Convert.ToInt32(response_length) < 1000) { if (response.ToLower().Equals("natural numbers")) { NaturalNumbers nats = new NaturalNumbers(); Console.WriteLine(nats.ToString(nats.GetSequence(length))); } else if (response.ToLower().Equals("even numbers")) { EvenNumbers even = new EvenNumbers(); Console.WriteLine(even.ToString(even.GetSequence(length))); } else if (response.ToLower().Equals("odd numbers")) { OddNumbers odd = new OddNumbers(); Console.WriteLine(odd.ToString(odd.GetSequence(length))); } else if (response.ToLower().Equals("fibonacci numbers")) { Fibonacci fib = new Fibonacci(); Console.WriteLine(fib.ToString(fib.GetSequence(length))); } else if (response.ToLower().Equals("prime numbers")) { PrimeNumbers prime = new PrimeNumbers(); Console.WriteLine(prime.ToString(prime.GetSequence(length))); } else { Console.WriteLine("Whoops!"); } } else { Console.WriteLine("Whoops!"); } } else { Console.WriteLine("Nope! Do better next time."); } Console.WriteLine("Press any key to exit."); Console.ReadKey(); }
static void Main(string[] args) { string prompt = "> "; string splash = @" ,/ * _,'/_ | `("")' ,'/ _ _,-M-./ / \_\_\. / __ __ _ _ _ _ )"" | ( | \/ | __ _| |_| |__ _ __ ___ __ _ __ _(_) ___(_) __ _ _ __ __/ M \__ | |\/| |/ _` | __| '_ \| '_ ` _ \ / _` |/ _` | |/ __| |/ _` | '_ \ \ /|\ / | | | | (_| | |_| | | | | | | | | (_| | (_| | | (__| | (_| | | | | `--'|||`--' |_| |_|\__,_|\__|_| |_|_| |_| |_|\__,_|\__, |_|\___|_|\__,_|_| |_| ==^== |___/"; Console.WriteLine(splash); Console.WriteLine("What do you want me to do?"); Console.Write(prompt); string[] valid_responses = new string[] { "natural numbers", "even numbers", "odd numbers", "fibonacci numbers", "prime numbers"}; string response = Console.ReadLine().ToLower(); if (valid_responses.Contains(response)) { Console.WriteLine("How many?"); Console.Write(prompt); string response_length = Console.ReadLine(); int length; bool parsed = int.TryParse(response_length, out length); if (parsed) { if (response == "natural numbers") { NaturalNumbers nats = new NaturalNumbers(); Console.WriteLine(nats.ToString(nats.GetSequence(length))); } if (response == "even numbers") { EvenNumbers even = new EvenNumbers(); Console.WriteLine(even.ToString(even.GetSequence(length))); } if (response == "odd numbers") { OddNumbers odd = new OddNumbers(); Console.WriteLine(odd.ToString(odd.GetSequence(length))); } if (response == "fibonacci numbers") { FibonacciNumbers fibonacci = new FibonacciNumbers(); Console.WriteLine(fibonacci.ToString(fibonacci.GetSequence(length))); } if (response == "prime numbers") { PrimeNumbers prime = new PrimeNumbers(); Console.WriteLine(prime.ToString(prime.GetSequence(length))); } } else { Console.WriteLine("Whoops!"); } } else { Console.WriteLine("Nope! Do better next time."); } Console.Write("Press any key to exit..."); Console.ReadKey(); }
static void Main(string[] args) { string prompt = "> "; Console.WriteLine("What do you want me to do?"); Console.Write(prompt); string response = Console.ReadLine(); if (response == "natural numbers") { Console.WriteLine("How many?"); Console.Write(prompt); string response_length = Console.ReadLine(); int length; bool parsed = int.TryParse(response_length, out length); if (parsed) { NaturalNumbers nats = new NaturalNumbers(); Console.WriteLine(nats.ToString(nats.GetSequence(length))); } else { Console.WriteLine("Whoops!"); } } if (response == "even numbers") { Console.WriteLine("How many?"); Console.Write(prompt); string response_length = Console.ReadLine(); int length; bool parsed = int.TryParse(response_length, out length); if (parsed) { EvenNumbers even = new EvenNumbers(); Console.WriteLine(even.ToString(even.GetSequence(length))); } else { Console.WriteLine("Whoops!"); } } if (response == "odd numbers") { Console.WriteLine("How many?"); Console.Write(prompt); string response_length = Console.ReadLine(); int length; bool parsed = int.TryParse(response_length, out length); if (parsed) { OddNumbers odd = new OddNumbers(); Console.WriteLine(odd.ToString(odd.GetSequence(length))); } else { Console.WriteLine("Whoops!"); } } if (response == "fibonacci numbers") { Console.WriteLine("How many?"); Console.Write(prompt); string response_length = Console.ReadLine(); int length; bool parsed = int.TryParse(response_length, out length); if (parsed) { FibonacciNumbers fibonacci = new FibonacciNumbers(); Console.WriteLine(fibonacci.ToString(fibonacci.GetSequence(length))); } else { Console.WriteLine("Whoops!"); } } if (response == "prime numbers") { Console.WriteLine("How many?"); Console.Write(prompt); string response_length = Console.ReadLine(); int length; bool parsed = int.TryParse(response_length, out length); if (parsed) { PrimeNumbers prime = new PrimeNumbers(); Console.WriteLine(prime.ToString(prime.GetSequence(length))); } else { Console.WriteLine("Whoops!"); } } else { Console.WriteLine("Nope! Do better next time."); } Console.WriteLine("Press any key to exit..."); Console.ReadKey(); }
static void Main(string[] args) { string prompt = "> "; Console.WriteLine(@"What do you want me to do? Natural Numers Even Numbers Odd Numbers Fibonacci Numbers Prime Numbers"); Console.Write(prompt); string input = getValidstring(); Console.WriteLine("How many?"); int inputInt = getValidInt(); //if (response.ToLower() == "natural numbers") //{ // Console.WriteLine("How many?"); // Console.Write(prompt); // string response_length = Console.ReadLine(); // int length; // bool parsed = int.TryParse(response_length, out length); // if (parsed) // { // NaturalNumbers nats = new NaturalNumbers(); // Console.WriteLine(nats.ToString(nats.GetSequence(length))); // } // else // { // Console.WriteLine("Whoops!"); // } //} //else //{ // Console.WriteLine("Nope! Do better next time."); //} switch (input.ToLower()) { case "natural numbers": NaturalNumbers nats = new NaturalNumbers(); Console.WriteLine(nats.ToString(nats.GetSequence(inputInt))); break; case "even numbers": EvenNumbers evens = new EvenNumbers(); Console.WriteLine(evens.ToString(evens.GetSequence(inputInt))); break; case "odd numbers": OddNumbers odds = new OddNumbers(); Console.WriteLine(odds.ToString(odds.GetSequence(inputInt))); break; case "fibonacci numbers": FibonacciNumbers fibs = new FibonacciNumbers(); Console.WriteLine(fibs.ToString(fibs.GetSequence(inputInt))); break; case "prime numbers": PrimeNumbers primes = new PrimeNumbers(); Console.WriteLine(primes.ToString(primes.GetSequence(inputInt))); break; default: Console.WriteLine("Whoops!"); break; } Console.WriteLine("Press any key to finish . . ."); Console.ReadKey(); }