From 8d60689be369a9461e20da88f8e500381745a2ee Mon Sep 17 00:00:00 2001 From: rbaneAtM <53240708+rbaneAtM@users.noreply.github.com> Date: Thu, 19 Sep 2024 22:12:41 -0700 Subject: [PATCH] C# basics code from replit to repo (#521) * Recording replit code for C# basics * Include fiddle.md updates --- .../CSharpBasicsClasses/answer.cs | 22 +++++++++++++++ .../csharp-basics/CSharpBasicsClasses/bird.cs | 4 +++ .../csharp-basics/CSharpBasicsClasses/main.cs | 18 ++++++++++++ .../CSharpBasicsControlStructures/main.cs | 21 ++++++++++++++ .../CSharpBasicsDataTypes/main.cs | 14 ++++++++++ .../CSharpBasicsHelloWorld/main.cs | 9 ++++++ .../csharp-basics/CSharpBasicsLoops/main.cs | 21 ++++++++++++++ .../CSharpBasicsMethods/answer.cs | 25 +++++++++++++++++ .../csharp-basics/CSharpBasicsMethods/main.cs | 17 +++++++++++ .../CSharpBasicsMethods/tester.cs | 19 +++++++++++++ .../CSharpBasicsOperatorPractice/main.cs | 28 +++++++++++++++++++ .../CSharpBasicsOperators/main.cs | 22 +++++++++++++++ .../CSharpBasicsRelationalOperators/main.cs | 20 +++++++++++++ .../csharp-basics/CSharpBasicsTest/main.cs | 7 +++++ .../CSharpBasicsVariables/main.cs | 9 ++++++ workshopcode/english/csharp-basics/fiddle.md | 16 +++++++++++ 16 files changed, 272 insertions(+) create mode 100644 workshopcode/english/csharp-basics/CSharpBasicsClasses/answer.cs create mode 100644 workshopcode/english/csharp-basics/CSharpBasicsClasses/bird.cs create mode 100644 workshopcode/english/csharp-basics/CSharpBasicsClasses/main.cs create mode 100644 workshopcode/english/csharp-basics/CSharpBasicsControlStructures/main.cs create mode 100644 workshopcode/english/csharp-basics/CSharpBasicsDataTypes/main.cs create mode 100644 workshopcode/english/csharp-basics/CSharpBasicsHelloWorld/main.cs create mode 100644 workshopcode/english/csharp-basics/CSharpBasicsLoops/main.cs create mode 100644 workshopcode/english/csharp-basics/CSharpBasicsMethods/answer.cs create mode 100644 workshopcode/english/csharp-basics/CSharpBasicsMethods/main.cs create mode 100644 workshopcode/english/csharp-basics/CSharpBasicsMethods/tester.cs create mode 100644 workshopcode/english/csharp-basics/CSharpBasicsOperatorPractice/main.cs create mode 100644 workshopcode/english/csharp-basics/CSharpBasicsOperators/main.cs create mode 100644 workshopcode/english/csharp-basics/CSharpBasicsRelationalOperators/main.cs create mode 100644 workshopcode/english/csharp-basics/CSharpBasicsTest/main.cs create mode 100644 workshopcode/english/csharp-basics/CSharpBasicsVariables/main.cs create mode 100644 workshopcode/english/csharp-basics/fiddle.md diff --git a/workshopcode/english/csharp-basics/CSharpBasicsClasses/answer.cs b/workshopcode/english/csharp-basics/CSharpBasicsClasses/answer.cs new file mode 100644 index 000000000..42d232f5d --- /dev/null +++ b/workshopcode/english/csharp-basics/CSharpBasicsClasses/answer.cs @@ -0,0 +1,22 @@ +public class Bird { + // your code goes here + private string name; + private string species; + private string hobby; + private int age; + private bool loveMusic; + + public Bird(string speciesInput, string nameInput, string hobbyInput, int ageInput, bool loveMusicInput) { + species = speciesInput; + name = nameInput; + hobby = hobbyInput; + age = ageInput; + loveMusic = loveMusicInput; + } + + public string getName() {return name;} + public string getSpecies() {return species;} + public string getHobby() {return hobby;} + public int getAge() {return age;} + public bool getLoveMusic() {return loveMusic;} +} \ No newline at end of file diff --git a/workshopcode/english/csharp-basics/CSharpBasicsClasses/bird.cs b/workshopcode/english/csharp-basics/CSharpBasicsClasses/bird.cs new file mode 100644 index 000000000..1366fc20d --- /dev/null +++ b/workshopcode/english/csharp-basics/CSharpBasicsClasses/bird.cs @@ -0,0 +1,4 @@ +public class Bird { + // your code goes here + +} \ No newline at end of file diff --git a/workshopcode/english/csharp-basics/CSharpBasicsClasses/main.cs b/workshopcode/english/csharp-basics/CSharpBasicsClasses/main.cs new file mode 100644 index 000000000..5571f3136 --- /dev/null +++ b/workshopcode/english/csharp-basics/CSharpBasicsClasses/main.cs @@ -0,0 +1,18 @@ +using System; + +class Program { + public static void Main (string[] args) { + + Bird test = new Bird("duck", "Patrick", "swimming", 12, true); + + if (test.getSpecies() == "duck" && + test.getName() == "Patrick" && + test.getHobby() == "swimming" && + test.getAge() == 12 && + test.getLoveMusic()) { + Console.WriteLine("Congradulations! You correctly implemented the Bird Class :)"); + } else { + Console.WriteLine("Something is still not quite right!"); + } + } +} \ No newline at end of file diff --git a/workshopcode/english/csharp-basics/CSharpBasicsControlStructures/main.cs b/workshopcode/english/csharp-basics/CSharpBasicsControlStructures/main.cs new file mode 100644 index 000000000..d9c2560ea --- /dev/null +++ b/workshopcode/english/csharp-basics/CSharpBasicsControlStructures/main.cs @@ -0,0 +1,21 @@ +using System; + +class Program { + public static void Main (string[] args) { + + int currentHour = 0; // current hour between 0 - 23 + + if(/*boolean statement A*/) + { + Console.WriteLine("Good Morning"); + } + else if (/*boolean statement B*/) + { + Console.WriteLine("Good Afternoon"); + } + else + { + Console.WriteLine("Good Night"); + } + } +} \ No newline at end of file diff --git a/workshopcode/english/csharp-basics/CSharpBasicsDataTypes/main.cs b/workshopcode/english/csharp-basics/CSharpBasicsDataTypes/main.cs new file mode 100644 index 000000000..702b37524 --- /dev/null +++ b/workshopcode/english/csharp-basics/CSharpBasicsDataTypes/main.cs @@ -0,0 +1,14 @@ +using System; + +class Program { + public static void Main (string[] args) { + // Help Patrick fix his code by changing the type for each variable so this program can run (do not change the value assigned to the variable, only the type) + + int bestFriend = "Minerva"; + bool numOfFriends = 4; + string GPA = 3.6; + double meaningOfLife = '$'; + char loveMusic = true; + + Console.WriteLine("You fixed it!"); } +} \ No newline at end of file diff --git a/workshopcode/english/csharp-basics/CSharpBasicsHelloWorld/main.cs b/workshopcode/english/csharp-basics/CSharpBasicsHelloWorld/main.cs new file mode 100644 index 000000000..80d20ed95 --- /dev/null +++ b/workshopcode/english/csharp-basics/CSharpBasicsHelloWorld/main.cs @@ -0,0 +1,9 @@ +using System; + +class Program { + public static void Main (string[] args) { + Console.WriteLine ("Hello World"); + // TODO: your code here + + } +} \ No newline at end of file diff --git a/workshopcode/english/csharp-basics/CSharpBasicsLoops/main.cs b/workshopcode/english/csharp-basics/CSharpBasicsLoops/main.cs new file mode 100644 index 000000000..cf0c4f0bc --- /dev/null +++ b/workshopcode/english/csharp-basics/CSharpBasicsLoops/main.cs @@ -0,0 +1,21 @@ +using System; + +class Program { + public static void Main (string[] args) { + + int total = 0; + int num = 1; + + // here is a while loop + while(num <= 100){ + total = total + num; + num = num + 1; + } + Console.WriteLine("Answer calculated in a while loop: " + total); + + int myTotal = 0; + // TODO: write it out in for loop, it is ok to reuse the total and num variables + + Console.WriteLine("Answer calculated in a for loop: " + myTotal); + } +} \ No newline at end of file diff --git a/workshopcode/english/csharp-basics/CSharpBasicsMethods/answer.cs b/workshopcode/english/csharp-basics/CSharpBasicsMethods/answer.cs new file mode 100644 index 000000000..e59db3ff3 --- /dev/null +++ b/workshopcode/english/csharp-basics/CSharpBasicsMethods/answer.cs @@ -0,0 +1,25 @@ +class answer { + + // here are two ways to solve this challenge + public static int pyramidCount1(int height) { + int sum = 0; + int level = height; + + while (level > 0 ) { + sum = sum + level * level; + level = level - 1; + } + return sum; + } + + public static int pyramidCount2(int height) { + int sum = 0; + int level = 1; + + while (level <= height ) { + sum = sum + level * level; + level = level + 1; + } + return sum; + } +} diff --git a/workshopcode/english/csharp-basics/CSharpBasicsMethods/main.cs b/workshopcode/english/csharp-basics/CSharpBasicsMethods/main.cs new file mode 100644 index 000000000..c07f12686 --- /dev/null +++ b/workshopcode/english/csharp-basics/CSharpBasicsMethods/main.cs @@ -0,0 +1,17 @@ +using System; + +class Program { + public static void Main (string[] args) { + Tester.test(); // do not change or remove + } + + // Instructions(Method): + // Write the method pyramidCount + // 1. fill the correct return type and parameter + // 2. implement the method + + public static /*return type*/ pyramidCountx(/*parameter*/) { + // Add your code here + + } +} \ No newline at end of file diff --git a/workshopcode/english/csharp-basics/CSharpBasicsMethods/tester.cs b/workshopcode/english/csharp-basics/CSharpBasicsMethods/tester.cs new file mode 100644 index 000000000..1ae99facb --- /dev/null +++ b/workshopcode/english/csharp-basics/CSharpBasicsMethods/tester.cs @@ -0,0 +1,19 @@ +using System; + +class Tester { + public static void test() { + if(Program.pyramidCount(1) == 1 && + Program.pyramidCount(2) == 5 && + Program.pyramidCount(3) == 14 && + Program.pyramidCount(4) == 30 && + Program.pyramidCount(24) == 4900 && + Program.pyramidCount(88) == 231044) + { + Console.WriteLine("Congradulations! Challenge Solved!"); + } + else + { + Console.WriteLine("Challenge failed!"); + } + } +} \ No newline at end of file diff --git a/workshopcode/english/csharp-basics/CSharpBasicsOperatorPractice/main.cs b/workshopcode/english/csharp-basics/CSharpBasicsOperatorPractice/main.cs new file mode 100644 index 000000000..f7be5e348 --- /dev/null +++ b/workshopcode/english/csharp-basics/CSharpBasicsOperatorPractice/main.cs @@ -0,0 +1,28 @@ +using System; + +class Program { + public static void Main (string[] args) { + Console.WriteLine("---------------------------\n" + + " Music Grade Report \n" + + "---------------------------\n" + + "\nStudent Grades: "); + double average = 0; + // start here: + // 1. define the variables for each student + // 2. define the variables for each "overxx" + // 3. calculate the average - use parenthesis around the addition operations + // 4. use relational operators to determine the level + + + // end here + + Console.WriteLine("- Patrick: " + patrickGrade + "\n- Tom: " + tomGrade + + "\n- Mary: " + maryGrade + "\n- Chris: " + chrisGrade + "\n- Jen: " + jenGrade + "\n"); + + Console.WriteLine("Class Average: " + average); + Console.WriteLine("- Average Over 60: " + over60); + Console.WriteLine("- Average Over 70: " + over70); + Console.WriteLine("- Average Over 80: " + over80); + Console.WriteLine("- Average Over 90: " + over90); + } +} \ No newline at end of file diff --git a/workshopcode/english/csharp-basics/CSharpBasicsOperators/main.cs b/workshopcode/english/csharp-basics/CSharpBasicsOperators/main.cs new file mode 100644 index 000000000..202202bf3 --- /dev/null +++ b/workshopcode/english/csharp-basics/CSharpBasicsOperators/main.cs @@ -0,0 +1,22 @@ +using System; + +class Program { + public static void Main (string[] args) { + // TODO: Run once and note the resulting output. Then change each line and run again. + int add = 9876 + 5432; //change the numbers + int subtract = 9876 - 5432; //change the numbers + int multiply = 9876 * 5432; //change the numbers + int divide1 = 9876/5431; //change the numbers + double divide2 = 9876/5431.0; //change the numbers + int modulus = 9876 % 5432; //change the numbers + String concat = "Hello" + " " + "World"; //change the phrase + + Console.WriteLine("adding: " + add); + Console.WriteLine("subtracting: " + subtract); + Console.WriteLine("multiplying: " + multiply); + Console.WriteLine("dividing integers: " + divide1); + Console.WriteLine("dividing doubles: " + divide2); + Console.WriteLine("modulus: " + modulus); + Console.WriteLine("concatting Strings: " + concat); + } +} \ No newline at end of file diff --git a/workshopcode/english/csharp-basics/CSharpBasicsRelationalOperators/main.cs b/workshopcode/english/csharp-basics/CSharpBasicsRelationalOperators/main.cs new file mode 100644 index 000000000..b42f144c0 --- /dev/null +++ b/workshopcode/english/csharp-basics/CSharpBasicsRelationalOperators/main.cs @@ -0,0 +1,20 @@ +using System; + +class Program { + public static void Main (string[] args) { + // TODO: Run once and note the output. Then change each line and run again. + bool equals = (333 == 333); //change the numbers + bool notEquals = (333 != 333); //change the numbers + bool greater = (333 > 444); //change numbers + bool lessthan = (333 < 444); //change numbers + bool greaterEqual = (333 >= 444); //change numbers + bool lessEqual = (333 <= 444); //change numbers + + Console.WriteLine("Equals: " + equals); + Console.WriteLine("Not Equals: " + notEquals); + Console.WriteLine("Greater Than: " + greater); + Console.WriteLine("Less Than: " + lessthan); + Console.WriteLine("Great Than or Equal to: " + greaterEqual); + Console.WriteLine("Less Than or Equal to: " + lessEqual); + } +} \ No newline at end of file diff --git a/workshopcode/english/csharp-basics/CSharpBasicsTest/main.cs b/workshopcode/english/csharp-basics/CSharpBasicsTest/main.cs new file mode 100644 index 000000000..dcca4977e --- /dev/null +++ b/workshopcode/english/csharp-basics/CSharpBasicsTest/main.cs @@ -0,0 +1,7 @@ +using System; + +class Program { + public static void Main (string[] args) { + Console.WriteLine ("Let's get started learning C#!"); + } +} \ No newline at end of file diff --git a/workshopcode/english/csharp-basics/CSharpBasicsVariables/main.cs b/workshopcode/english/csharp-basics/CSharpBasicsVariables/main.cs new file mode 100644 index 000000000..46448a2c4 --- /dev/null +++ b/workshopcode/english/csharp-basics/CSharpBasicsVariables/main.cs @@ -0,0 +1,9 @@ +using System; + +class Program { + public static void Main (string[] args) { + Console.WriteLine("Get started with variables"); + // TODO: Enter your code here + + } +} \ No newline at end of file diff --git a/workshopcode/english/csharp-basics/fiddle.md b/workshopcode/english/csharp-basics/fiddle.md new file mode 100644 index 000000000..70107ebb6 --- /dev/null +++ b/workshopcode/english/csharp-basics/fiddle.md @@ -0,0 +1,16 @@ +## DotNet Fiddles + + +|Code |Fiddle Link | +|---------|---------| +| CSharpBasicsClasses | https://dotnetfiddle.net/OH5XQO | +| CSharpBasicsControlStructures | https://dotnetfiddle.net/T6AUdh | +| CSharpBasicsDataTypes | https://dotnetfiddle.net/xKMKvn | +| CSharpBasicsHelloWorld | | +| CSharpBasicsLoops | https://dotnetfiddle.net/ySFwK0 | +| CSharpBasicsMethods | https://dotnetfiddle.net/ireaAA | +| CSharpBasicsOperatorPractice | https://dotnetfiddle.net/mM7xbj | +| CSharpBasicsOperators | https://dotnetfiddle.net/dUSTOt | +| CSharpBasicsRelationalOperators | https://dotnetfiddle.net/tZs8tb | +| CSharpBasicsTest | | +| CSharpBasicsVariables | https://dotnetfiddle.net/PPCCzG |