diff --git a/HelloWorld/.vscode/launch.json b/HelloWorld/.vscode/launch.json new file mode 100644 index 00000000..034b33c0 --- /dev/null +++ b/HelloWorld/.vscode/launch.json @@ -0,0 +1,28 @@ +{ + // Use IntelliSense to find out which attributes exist for C# debugging + // Use hover for the description of the existing attributes + // For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md + "version": "0.2.0", + "configurations": [ + { + "name": ".NET Core Launch (console)", + "type": "coreclr", + "request": "launch", + "preLaunchTask": "build", + // If you have changed target frameworks, make sure to update the program path. + "program": "${workspaceFolder}/bin/Debug/netcoreapp2.0/HelloWorld.dll", + "args": [], + "cwd": "${workspaceFolder}", + // For more information about the 'console' field, see https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md#console-terminal-window + "console": "internalConsole", + "stopAtEntry": false, + "internalConsoleOptions": "openOnSessionStart" + }, + { + "name": ".NET Core Attach", + "type": "coreclr", + "request": "attach", + "processId": "${command:pickProcess}" + } + ,] +} \ No newline at end of file diff --git a/HelloWorld/.vscode/tasks.json b/HelloWorld/.vscode/tasks.json new file mode 100644 index 00000000..7cf275a8 --- /dev/null +++ b/HelloWorld/.vscode/tasks.json @@ -0,0 +1,15 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "label": "build", + "command": "dotnet", + "type": "process", + "args": [ + "build", + "${workspaceFolder}/HelloWorld.csproj" + ], + "problemMatcher": "$msCompile" + } + ] +} \ No newline at end of file diff --git a/HelloWorld/HelloWorld.cs b/HelloWorld/HelloWorld.cs index 8168c805..3bf58342 100644 --- a/HelloWorld/HelloWorld.cs +++ b/HelloWorld/HelloWorld.cs @@ -6,7 +6,118 @@ class Program { static void Main(string[] args) { - Console.WriteLine("Hello World!"); + +//Hello Wrorld Assignment + //Write a C# program that prints to screen "Hello my name is Andy" then + Console.WriteLine("Hello my name is Andy!"); + //Ask user for name "user name" + Console.WriteLine("What is your name?"); + //Get "user name" + string userName = Console.ReadLine(); + //Print to screen "Nice to meet you" "user name" + Console.WriteLine("Nice to meet you "+userName); + +//Day 1 Lesson + //Write a C# program that takes two numbers as input, adds them together, and displays the result of that operation + int number1 = 0; + int number2 = 0; + int total = 0; + + //note: the Parse method converts a string to a number - you define the number type (int, float, long, double, etc) + Console.WriteLine("Please enter a whole number greater than 0: "); + number1 = int.Parse(Console.ReadLine()); + + Console.WriteLine("Please enter another whole number greater than 0: "); + number2 = int.Parse(Console.ReadLine()); + + total = number1 + number2; + Console.WriteLine("Sum of two whole numbers, result = "+ total); + + //Write a C# program that converts yards to inches. + int yards = 0; + int inches = 32; + + Console.WriteLine("Enter a whole number of yards to convert: "); + yards = int.Parse(Console.ReadLine()); + + inches = yards * inches; + Console.WriteLine("Number of inches = "+ inches); + + //Create and define the variable people as true. + bool people = true; + + // Create and define the variable f as false. + bool f = false; + + // Create and define the variable num to be a decimal. + double num = 0; + + // Display the product of num multiplied by itself. + Console.WriteLine("Enter a whole number to be squared: "); + num = int.Parse(Console.ReadLine()); + + num = Math.Pow(num,2); + Console.WriteLine("Number squared = "+ num); + + // Create the following variables with your personal information: + // firstName + string firstName = "Andy"; + + // lastName + string lastName = "Fogarasi"; + + // age + int age = 55; + + // job + string job = "entrepreneur"; + + // favoriteBand + string favoriteBand = "Zac Brown"; + + // favoriteSportsTeam + string favoriteSportsTeam = "Hoonigan Racing"; + + // Experiment with Console.WriteLine(); to print out different pieces of your personal information. + Console.WriteLine("My name is "+ firstName + ' '+lastName); + Console.WriteLine("I am "+ age + " years old"); + Console.WriteLine("I am an "+ job); + Console.WriteLine("My favorite band is "+ favoriteBand); + Console.WriteLine("My favorite sports team is "+ favoriteSportsTeam); + + // Convert the variable num to an int. + num = (double) 6.89; + // Explicit cast double to int. + num = (int) num; + Console.WriteLine("Explict cast of double to int. Any decimals are truncated: "+ num); + + // Print to the console the sum, product, difference, and quotient of 100 and 10. + int num1 = 100; + int num2 = 10; + int sum = num1 + num2; + int prod = num1 * num2; + int dif = num1 - num2; + int quo = num1 / num2; + + Console.WriteLine("The sum, product, difference and quotient of 100 and 10 are:"); + Console.WriteLine("Sum: " + sum); + Console.WriteLine("Product: " + prod); + Console.WriteLine("Difference: " + dif); + Console.WriteLine("Quotient: " + quo); + + //1. Ask a user for a number + Console.WriteLine("Enter a whole and non-decimal number, either positive or negative: "); + string numberSign = Console.ReadLine(); + int Sign = int.Parse(numberSign); + + //2. Return if number is positive or negative + if (Sign >= 0) { + Console.WriteLine("Number is positive"); } + else { + Console.WriteLine("Number is negative"); + } + + } } } diff --git a/PigLatin/.vscode/launch.json b/PigLatin/.vscode/launch.json new file mode 100644 index 00000000..dbee6e56 --- /dev/null +++ b/PigLatin/.vscode/launch.json @@ -0,0 +1,28 @@ +{ + // Use IntelliSense to find out which attributes exist for C# debugging + // Use hover for the description of the existing attributes + // For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md + "version": "0.2.0", + "configurations": [ + { + "name": ".NET Core Launch (console)", + "type": "coreclr", + "request": "launch", + "preLaunchTask": "build", + // If you have changed target frameworks, make sure to update the program path. + "program": "${workspaceFolder}/bin/Debug/netcoreapp2.0/PigLatin.dll", + "args": [], + "cwd": "${workspaceFolder}", + // For more information about the 'console' field, see https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md#console-terminal-window + "console": "internalConsole", + "stopAtEntry": false, + "internalConsoleOptions": "openOnSessionStart" + }, + { + "name": ".NET Core Attach", + "type": "coreclr", + "request": "attach", + "processId": "${command:pickProcess}" + } + ,] +} \ No newline at end of file diff --git a/PigLatin/.vscode/tasks.json b/PigLatin/.vscode/tasks.json new file mode 100644 index 00000000..a705ed07 --- /dev/null +++ b/PigLatin/.vscode/tasks.json @@ -0,0 +1,15 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "label": "build", + "command": "dotnet", + "type": "process", + "args": [ + "build", + "${workspaceFolder}/PigLatin.csproj" + ], + "problemMatcher": "$msCompile" + } + ] +} \ No newline at end of file diff --git a/PigLatin/PigLatin.cs b/PigLatin/PigLatin.cs index 702647dd..52a5cfe9 100644 --- a/PigLatin/PigLatin.cs +++ b/PigLatin/PigLatin.cs @@ -6,16 +6,54 @@ class Program { public static void Main() { - // your code goes here + // your code goes here - // leave this command at the end so your program does not close automatically - Console.ReadLine(); + // Enter one word, translate it to Piglatin and print the translation to the screen + // Rules: + // 1) any letters before the first vowel get moved to the end of the word + // 2) if the updated word ends in a vowel add "yay" to the end + // 3) if the updated word ends in a consonant add "ay" to the end + // 4) Translator must pass the following tests: + // - elephant -> elephantay + // - fox -> oxfay + // - tsk -> tskay + // - are -> areyay + // - mine -> inemay + // - thing -> ingthay + + // Enter a word and assign it to a variable + Console.WriteLine("Please enter a word to translate to Pig Latin: "); + string englishWord = Console.ReadLine(); + + // Search word for the first vowel and identify its index + char[] vowels = { 'a', 'e', 'i', 'o', 'u' }; + + int letterIdx = englishWord.IndexOfAny(vowels); + // exception if there are no vowels + if (letterIdx < 0) { + letterIdx = 0; + } + + // Assign beginning of new Pigword to a variable, assign letters before first vowel to a different variable, and join them. + string pigWord = englishWord.Substring(letterIdx); + string firstHalf = englishWord.Substring(0,letterIdx); + pigWord = pigWord + firstHalf; + + // If last letter in pigWord assembly is a vowel add "yay". If not add "ay". Then Print. + char lastLetter = pigWord[pigWord.Length - 1]; + string last = char.ToString(lastLetter); + int lastIdx = last.IndexOfAny(vowels); + + // if pigWord ends in a consonant + if (lastIdx < 0) { + pigWord = pigWord + "ay"; + } + // if pigWord ends in a vowel + else { + pigWord = pigWord + "yay"; } - public static string TranslateWord(string word) - { - // your code goes here - return word; + Console.WriteLine(pigWord); } } } diff --git a/RockPaperScissors/RockPaperScissors.cs b/RockPaperScissors/RockPaperScissors.cs index 470ae756..8eb53d09 100644 --- a/RockPaperScissors/RockPaperScissors.cs +++ b/RockPaperScissors/RockPaperScissors.cs @@ -6,20 +6,80 @@ class Program { public static void Main() { - Console.WriteLine("Enter hand 1:"); - string hand1 = Console.ReadLine().ToLower(); - Console.WriteLine("Enter hand 2:"); - string hand2 = Console.ReadLine().ToLower(); - Console.WriteLine(CompareHands(hand1, hand2)); + + // Rock Paper Scissors game of a user vs. the computer + Console.WriteLine("Play Rock Paper Scissors"); + + // User Input Method + // Ask user to input R (Rock), P (Paper) or S (Scissors) + // Write to screen the player's choice + string player1 = "NONE"; + Console.WriteLine("Enter your choice R, P or S for Rock, Paper or Scissors: "); + string play = Console.ReadLine().ToUpper(); + if (play == "R") + { + player1 = "ROCK"; + } + else if (play == "P") + { + player1 = "PAPER"; + } + else { + player1 = "SCISSORS"; + } + Console.WriteLine("YOUR choice: " + player1); + + // Computer Input Method + // Computer generate a random number between 0 and 2 and assign to a variable + // Assign Computer variable according to the following instructions: + // 1) 0 = "R" (Rock) + // 2) 1 = "P" (Paper) + // 3) 2 = "S" (Scissors) + // and write to screen Computer choice + string comp1 = "NONE"; + Random rnd = new Random(); + int compHand = rnd.Next(0, 3); + if (compHand < 1) { + comp1 = "ROCK"; + } + else if (compHand > 1) { + comp1 = "PAPER"; + } + else { + comp1 = "SCISSORS"; + } + Console.WriteLine("COMPUTER choice: " + comp1); + + // Compare and Identify Winner Method + // Compare User variable to Computer variable and determine result according to instructions below: + // 1) if User variable (userHand)= Computer variable (compHand) result is "Tie" + // 2) R vs. S > R is winner + // 3) S vs. P > S is winner + // 4) P vs. R > P is winner + // Write to screen User winner + if (player1 == comp1) + { + Console.WriteLine("You Tie. Try Again"); + } + else if (player1 == "ROCK" && comp1 == "SCISSORS") + { + Console.WriteLine("You Win!"); + } + else if (player1 == "SCISSORS" && comp1 == "PAPER") + { + Console.WriteLine("You Win!"); + } + else if (player1 == "PAPER" && comp1 == "ROCK") + { + Console.WriteLine("You Win!"); + } + else { + Console.WriteLine("Computer Wins!"); + } // leave this command at the end so your program does not close automatically Console.ReadLine(); - } - - public static string CompareHands(string hand1, string hand2) - { - // Your code here - return hand1 + ' ' + hand2; + } } }