public void FibonacciPrintOfSequenceOfNumbers() { FibonacciNumbers fibonacci = new FibonacciNumbers(); int length = 8; string expected = "1 1 2 3 5 8 13 21"; string actual = fibonacci.ToString(fibonacci.GetSequence(length)); Assert.AreEqual(expected, actual); }
public void FibonacciPrintSequencenumbers() { FibonacciNumbers fib = new FibonacciNumbers(); int length = 7; string expected = "1 1 2 3 5 8 13"; string actual = fib.ToString(fib.GetSequence(length)); Assert.AreEqual(expected, actual); }
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.Equals("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 if (response.Equals("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!"); } } else if (response.Equals("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!"); } } else if (response.Equals("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!"); } } else if (response.Equals("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 primes = new PrimeNumbers(); Console.WriteLine(primes.ToString(primes.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 = "> "; // cw tab tab (console.writeline stub) Console.WriteLine("What do you want me to do?"); // WriteLine gets new line Console.Write(prompt); // Write keeps on same line string response = Console.ReadLine(); if (response == "natural numbers") { Console.WriteLine("How much you wan?"); 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 if (response == "odd numbers") { Console.WriteLine("How much you wan?"); Console.WriteLine(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!"); } } else if (response == "even numbers") { Console.WriteLine("How much you wan?"); Console.WriteLine(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!"); } } else if (response == "fibonacci sequence") { Console.WriteLine("How much you wan?"); Console.WriteLine(prompt); string response_length = Console.ReadLine(); int length; bool parsed = int.TryParse(response_length, out length); if (parsed) { FibonacciNumbers fib = new FibonacciNumbers(); Console.WriteLine(fib.ToString(fib.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(); }