Skip to content

Commit

Permalink
C# basics code from replit to repo (#521)
Browse files Browse the repository at this point in the history
* Recording replit code for C# basics

* Include fiddle.md updates
  • Loading branch information
rbaneAtM authored Sep 20, 2024
1 parent 9ef5347 commit 8d60689
Show file tree
Hide file tree
Showing 16 changed files with 272 additions and 0 deletions.
22 changes: 22 additions & 0 deletions workshopcode/english/csharp-basics/CSharpBasicsClasses/answer.cs
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;}
}
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 workshopcode/english/csharp-basics/CSharpBasicsClasses/main.cs
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!");
}
}
}
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 workshopcode/english/csharp-basics/CSharpBasicsDataTypes/main.cs
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!"); }
}
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 workshopcode/english/csharp-basics/CSharpBasicsLoops/main.cs
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 workshopcode/english/csharp-basics/CSharpBasicsMethods/answer.cs
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 workshopcode/english/csharp-basics/CSharpBasicsMethods/main.cs
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 workshopcode/english/csharp-basics/CSharpBasicsMethods/tester.cs
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!");
}
}
}
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 workshopcode/english/csharp-basics/CSharpBasicsOperators/main.cs
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);
}
}
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);
}
}
7 changes: 7 additions & 0 deletions workshopcode/english/csharp-basics/CSharpBasicsTest/main.cs
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#!");
}
}
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

}
}
16 changes: 16 additions & 0 deletions workshopcode/english/csharp-basics/fiddle.md
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 |

0 comments on commit 8d60689

Please sign in to comment.