-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
C# basics code from replit to repo (#521)
* Recording replit code for C# basics * Include fiddle.md updates
- Loading branch information
Showing
16 changed files
with
272 additions
and
0 deletions.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
workshopcode/english/csharp-basics/CSharpBasicsClasses/answer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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;} | ||
} |
4 changes: 4 additions & 0 deletions
4
workshopcode/english/csharp-basics/CSharpBasicsClasses/bird.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
public class Bird { | ||
// your code goes here | ||
|
||
} |
18 changes: 18 additions & 0 deletions
18
workshopcode/english/csharp-basics/CSharpBasicsClasses/main.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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!"); | ||
} | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
workshopcode/english/csharp-basics/CSharpBasicsControlStructures/main.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"); | ||
} | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
workshopcode/english/csharp-basics/CSharpBasicsDataTypes/main.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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!"); } | ||
} |
9 changes: 9 additions & 0 deletions
9
workshopcode/english/csharp-basics/CSharpBasicsHelloWorld/main.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using System; | ||
|
||
class Program { | ||
public static void Main (string[] args) { | ||
Console.WriteLine ("Hello World"); | ||
// TODO: your code here | ||
|
||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
workshopcode/english/csharp-basics/CSharpBasicsLoops/main.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
workshopcode/english/csharp-basics/CSharpBasicsMethods/answer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
workshopcode/english/csharp-basics/CSharpBasicsMethods/main.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
|
||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
workshopcode/english/csharp-basics/CSharpBasicsMethods/tester.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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!"); | ||
} | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
workshopcode/english/csharp-basics/CSharpBasicsOperatorPractice/main.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
workshopcode/english/csharp-basics/CSharpBasicsOperators/main.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
workshopcode/english/csharp-basics/CSharpBasicsRelationalOperators/main.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
using System; | ||
|
||
class Program { | ||
public static void Main (string[] args) { | ||
Console.WriteLine ("Let's get started learning C#!"); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
workshopcode/english/csharp-basics/CSharpBasicsVariables/main.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | |