Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions ExceptionPractice/ExceptionPractice.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.1</TargetFramework>
</PropertyGroup>

</Project>
29 changes: 29 additions & 0 deletions ExceptionPractice/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System;

namespace ExceptionPractice
{
class Program
{
static void Main(string[] args)
{
try
{
double ans1 = divide(17.0, 0.0);
Console.WriteLine(ans1);
}
catch
{
Console.WriteLine("Oops, there was a problem with the divide function.");
}

}
public static double divide(double num1, double num2)
{
if (num2 == 0.0)
{
throw new Exception("Cannot divide by 0, Sorry!");
}
return num1 / num2;
}
}
}
136 changes: 126 additions & 10 deletions RockPaperScissors/RockPaperScissors.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,136 @@ 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));
if (tests())
{
Console.WriteLine("Tests Passed!");
}
else
{
Console.WriteLine("Tests Failed!");
}
Console.WriteLine("-----------------");

string hand1 = null;


while (hand1 == null)
{
try
{
playerInput();
}
catch
{
Console.WriteLine("Enter Rock Paper or Scissor. Come on, you know better than that.");
}
}

string hand2 = computerInput();
int compare = CompareHands(hand1, hand2);


if (compare == 0)
{
Console.WriteLine("It's a tie!");
}
else if (compare == 1)
{
Console.WriteLine("You Win, Congrats!");
}
else if (compare == 2)
{
Console.WriteLine("Computer Wins! Sorry bud.");
}


// leave this command at the end so your program does not close automatically
//Keep this here to keep code from closing out.
Console.ReadLine();
}

public static string CompareHands(string hand1, string hand2)

//Get input from user and check if it's valid.
public static string playerInput()
{

Console.WriteLine("Rock, Paper, Scissors!");
string hand1 = Console.ReadLine().ToLower();

if (hand1 != "rock" && hand1 != "paper" && hand1 != "scissors")
{
throw new Exception("Incorrect Input.");
}
else
{
return hand1;
}

}


//Takes a random number and turns it into the computer's hand.
public static string computerInput()
{
// Your code here
return hand1 + ' ' + hand2;
Random rps = new Random();
int num = rps.Next(0, 3);
string hand2;

if (num == 0)
{
hand2 = "rock";
Console.WriteLine("The computer chose rock!");
}
else if (num == 1)
{
hand2 = "paper";
Console.WriteLine("The Computer chose paper!");
}
else if (num == 2)
{
hand2 = "scissors";
Console.WriteLine("The computer chose scissors!");
}
else
{
throw new Exception("Error in computer generation.");
}
return hand2;
}


public static int CompareHands(string hand1, string hand2)
{
if (hand1 == hand2)
{
return 0;
}
else if (hand1 == "rock" && hand2 == "scissors" || hand1 == "paper" && hand2 == "rock" || hand1 == "scissors" && hand2 == "paper")
{
return 1;
}
else if (hand2 == "rock" && hand1 == "scissors" || hand2 == "paper" && hand1 == "rock" || hand2 == "scissors" && hand1 == "paper")
{
return 2;
}
else
{
throw new Exception("Comparison Error.");
}
}

public static bool tests()
{
return
CompareHands("rock", "rock") == 0 &&
CompareHands("rock", "scissors") == 1 &&
CompareHands("rock", "paper") == 2 &&

CompareHands("paper", "paper") == 0 &&
CompareHands("paper", "rock") == 1 &&
CompareHands("paper", "scissors") == 2 &&

CompareHands("scissors", "scissors") == 0 &&
CompareHands("scissors", "paper") == 1 &&
CompareHands("scissors", "rock") == 2;
}
}
}
13 changes: 13 additions & 0 deletions textGame/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;
using System.Threading;

namespace textGame
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
}
}
}
32 changes: 32 additions & 0 deletions week2Practice/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System;

namespace week2Practice
{
class Program
{
static void Main(string[] args)
{
//ask user for grade
//if number is a grade, print out you made an A
int grade = 0;
string input;

Console.WriteLine("Enter a Numerical Grade:");
input = Console.ReadLine();
grade = Convert.ToInt32(input);

if(grade >= 90){
Console.WriteLine("You made an A! Congrats!");
}else if(grade >= 80){
Console.WriteLine("You made a B! Almost Perfect.");
}else if(grade >= 70){
Console.WriteLine("You made a C! Study up.");
}else if(grade >= 60){
Console.WriteLine("You made a D! You can do better.");
}else{
Console.WriteLine("You Failed! Try again!");
}
Console.WriteLine("Thank you for submitting.");
}
}
}
8 changes: 8 additions & 0 deletions week2Practice/week2Practice.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.1</TargetFramework>
</PropertyGroup>

</Project>