Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Assignment_week_1_1
- {
- class Program
- {
- private static void RunExerciseOne()
- {
- Console.WriteLine("You successfully ran exercise one!");
- string firstName = "Jonte";
- string lastName = "Adolfsson";
- Console.WriteLine("Hello " + firstName + " " + lastName + "! I'm glad to inform you that you are the test subject of my very first assignment!");
- }
- // Dumförklarad " " = Mellanslag, satt och kliade på den ett tag.
- private static void RunExerciseTwo()
- {
- Console.WriteLine("You successfully ran exercise two!");
- DateTime today = DateTime.Now;
- DateTime tomorrow = today.AddDays(1);
- DateTime yesterday = today.AddDays(-1);
- Console.WriteLine("Todays date is " + today);
- Console.WriteLine("Tomorrows date is " + tomorrow);
- Console.WriteLine("Yesterdays date was " + yesterday);
- }
- // No comment.
- private static void RunExerciseThree()
- {
- Console.WriteLine("You successfully ran exercise three!");
- Console.ForegroundColor = ConsoleColor.White;
- Console.Write("Enter you first name: ");
- string firstname = Console.ReadLine();
- Console.Write("Enter you last name: ");
- string lastname = Console.ReadLine();
- Console.Clear();
- Console.ForegroundColor = ConsoleColor.Green;
- Console.WriteLine("Alright, I will call you " + firstname + " " + lastname + " from now on!");
- }
- // So far so good.
- private static void RunExerciseFour()
- {
- Console.WriteLine("You successfully ran exercise four!");
- String str = "The quick fox jumped Over the DOG";
- Console.ForegroundColor = ConsoleColor.Red;
- Console.WriteLine(str);
- Console.ResetColor();
- Console.WriteLine("Hit any key to fix the issues!");
- Console.ReadKey();
- Console.Clear();
- {
- if (str.Contains("DOG")) // Replace
- str = str.Replace("DOG", "LAZY DOG");
- if (str.Contains("quick")) // Remove
- str = str.Remove(4, 6);
- if (str.Contains("Over")) // Substring Tolower
- str = str.Substring(0, 1) + str.Substring(1).ToLower();
- if (str.Contains("fox")) // Insert
- str = str.Insert(4, "brown ");
- }
- Console.ForegroundColor = ConsoleColor.Green;
- Console.WriteLine(str);
- }
- // Försökte använda lite olika metoder utan att behöva göra en ny string
- private static void RunExerciseFive()
- {
- Console.WriteLine("You successfully ran exercise five!");
- Console.ResetColor();
- String str = "Arrays are very common in programming, they look something like: [1,2,3,4,5]";
- Console.ReadLine();
- string substr = str.Substring(65, 11);
- if (substr.Contains("1"))
- substr = substr.Replace("[1,2,3,4,5]", "[1,4,5,6,7,8,9,10]");
- Console.WriteLine(substr);
- }
- // va lite lat, visdomstand gör mig irriterad x(
- private static void RunExerciseSix()
- {
- Console.WriteLine("You successfully ran exercise six!");
- Console.ResetColor();
- var num1 = 1;
- var num2 = 0;
- Console.Write("Enter your first number: ");
- num1 = Convert.ToInt32(Console.ReadLine());
- Console.Write("Enter you second number: ");
- num2 = Convert.ToInt32(Console.ReadLine());
- Console.Clear();
- string biggest = ("The biggest number is: ");
- Console.WriteLine(biggest + Math.Max(num1, num2));
- string smallest = ("The smallest number is: ");
- Console.WriteLine(smallest + Math.Min(num1, num2));
- string difference = ("The difference between the two numbers are: ");
- Console.WriteLine(difference + Math.Abs(num1 - num2));
- string sum = ("The sum of the two numbers are: ");
- Console.WriteLine(sum + Math.Abs(num1 + num2));
- string product = ("The product between the two numbers are: ");
- Console.WriteLine(product + Math.Abs(num1 * num2));
- string ratio = ("The ratio between the two numbers are: ");
- Console.WriteLine(ratio + Math.Abs(num1 / num2));
- }
- // tandvärk all day erry day wooh
- private static void RunExerciseSeven()
- {
- Console.WriteLine("You successfully ran exercise seven!");
- Console.ResetColor();
- {
- double c, cir;
- double PI = 3.14;
- double s, spha, sphv;
- Console.WriteLine("Enter the radius of the circle : ");
- c = Convert.ToDouble(Console.ReadLine());
- cir = PI * c * c;
- Console.WriteLine("Enter the Radius of the Sphere: ");
- s = Convert.ToDouble(Console.ReadLine());
- spha = 4 * PI * s * s;
- sphv = (4.0 / 3) * PI * s * s * s;
- Console.WriteLine("The area of the circle is : {0}", cir);
- Console.WriteLine("The area of the sphere is : {0} ", spha);
- Console.WriteLine("The volume of the sphere is : {0}", sphv);
- }
- }
- // matte ;c
- private static void RunExerciseEight()
- {
- Console.WriteLine("You successfully ran exercise eight!");
- Console.ResetColor();
- {
- double num, sqrt = 0;
- int currentDecimal = 0, dA = 5, iA = 5;
- do
- {
- Console.Write("Enter a decimal value: ");
- } while (!double.TryParse(Console.ReadLine(), out num));
- while (0 < iA)
- {
- double currentIncrement = Math.Pow(10, iA);
- while (Math.Pow(sqrt + currentIncrement, 2) <= num)
- {
- sqrt += currentIncrement;
- }
- iA--;
- }
- while (currentDecimal <= dA)
- {
- double currentIncrement = (double)1 / Math.Pow(10, currentDecimal);
- while (Math.Pow(sqrt + currentIncrement, 2) <= num)
- {
- sqrt += currentIncrement;
- }
- currentDecimal++;
- }
- Console.WriteLine(("Square root: ") + sqrt);
- Console.WriteLine(("Raised to the power of 2: ") + Math.Pow(num, 2));
- Console.WriteLine(("Raised to the power of 10: ") + Math.Pow(num, 10));
- }
- }
- // Det funkade till slut tror jag
- private static void RunExerciseNine()
- {
- DateTime today = DateTime.Today;
- Console.WriteLine("You successfully ran exercise nine!");
- Console.ResetColor();
- Console.WriteLine("Please enter your name: ");
- string name = (Console.ReadLine());
- while (true)
- {
- Console.WriteLine("Hello " + name + ", please enter your date of birth (MM/DD/YYYY): ");
- DateTime birthDate;
- if (DateTime.TryParse(Console.ReadLine(), out birthDate))
- {
- TimeSpan age = DateTime.Now - birthDate;
- var a = (int)(age.Days / 365.25);
- if (a < 18)
- {
- Console.Clear();
- Console.WriteLine("Would you like to order a coke? (y/n):");
- string coke = Console.ReadLine();
- if (coke.Equals("y", StringComparison.OrdinalIgnoreCase) || coke.Equals("yes", StringComparison.OrdinalIgnoreCase))
- {
- Console.ForegroundColor = ConsoleColor.Green;
- Console.WriteLine("A coke has been served!");
- Console.ResetColor();
- break;
- }
- if (coke.Equals("n", StringComparison.OrdinalIgnoreCase) || coke.Equals("no", StringComparison.OrdinalIgnoreCase))
- {
- Console.ForegroundColor = ConsoleColor.Red;
- Console.WriteLine("No order options are available!");
- Console.ResetColor();
- break;
- }
- }
- else
- Console.Clear();
- Console.WriteLine("Would you like to order a beer? (y/n):");
- string beer = Console.ReadLine();
- if (beer.Equals("y", StringComparison.OrdinalIgnoreCase) || beer.Equals("yes", StringComparison.OrdinalIgnoreCase))
- {
- Console.ForegroundColor = ConsoleColor.Green;
- Console.WriteLine("A beer has been served!");
- Console.ResetColor();
- break;
- }
- if (beer.Equals("n", StringComparison.OrdinalIgnoreCase) || beer.Equals("no", StringComparison.OrdinalIgnoreCase))
- {
- Console.WriteLine("Would you like to order a coke instead?(y/n):");
- string coke = Console.ReadLine();
- if (coke.Equals("y", StringComparison.OrdinalIgnoreCase) || coke.Equals("yes", StringComparison.OrdinalIgnoreCase))
- {
- Console.ForegroundColor = ConsoleColor.Green;
- Console.WriteLine("A coke has been served!");
- Console.ResetColor();
- break;
- }
- if (coke.Equals("n", StringComparison.OrdinalIgnoreCase) || coke.Equals("no", StringComparison.OrdinalIgnoreCase))
- {
- Console.ForegroundColor = ConsoleColor.Red;
- Console.WriteLine("No order options are available!");
- Console.ResetColor();
- break;
- }
- }
- }
- else
- Console.ForegroundColor = ConsoleColor.Red;
- Console.WriteLine("You have entered an invalid birthdate, try again." + Environment.NewLine);
- Console.ResetColor();
- }
- }
- // null
- private static void RunExerciseTen()
- {
- var keepAlive = true;
- while (keepAlive)
- {
- try
- {
- Console.WriteLine("You successfully ran exercise ten!");
- Console.WriteLine("Input 1 for division.");
- Console.WriteLine("Input 2 for Exercise 4.");
- Console.WriteLine("Input 3 for color switch.");
- Console.WriteLine("Input -1 to exit");
- var ExerciseTen = int.Parse(Console.ReadLine() ?? "");
- switch (ExerciseTen)
- {
- case 1:
- Console.ResetColor();
- var num1 = 1;
- var num2 = 0;
- Console.Write("Enter your first number: ");
- num1 = Convert.ToInt32(Console.ReadLine());
- Console.Write("Enter you second number: ");
- num2 = Convert.ToInt32(Console.ReadLine());
- if (num2 == 0)
- {
- Console.ForegroundColor = ConsoleColor.Red;
- Console.WriteLine("You have entered a invalid number, try again." + Environment.NewLine);
- Console.ResetColor();
- }
- else
- {
- Console.ForegroundColor = ConsoleColor.Green;
- Console.WriteLine(num1 + " divided by " + num2 + " is: " + (num1 / num2));
- Console.ReadKey();
- }
- break;
- case 2:
- RunExerciseFour();
- break;
- case 3:
- if (Console.ForegroundColor == ConsoleColor.Green)
- {
- Console.ForegroundColor = ConsoleColor.Red;
- }
- else
- {
- Console.ForegroundColor = ConsoleColor.Green;
- }
- break;
- case -1:
- keepAlive = false;
- break;
- default:
- Console.ForegroundColor = ConsoleColor.Red;
- Console.WriteLine("That is not a valid test number!");
- break;
- }
- Console.WriteLine("Hit any key to continue!");
- Console.ReadKey();
- Console.Clear();
- }
- catch
- {
- Console.ForegroundColor = ConsoleColor.Red;
- Console.WriteLine("That is not a valid test number!");
- Console.ResetColor();
- }
- }
- }
- private static void RunExerciseEleven()
- {
- Console.WriteLine("You successfully ran exercise eleven!");
- Console.ResetColor();
- var num1 = 1;
- Console.Write("Enter a number over 0:");
- num1 = Convert.ToInt32(Console.ReadLine());
- if (num1 == 0)
- {
- Console.ForegroundColor = ConsoleColor.Red;
- Console.WriteLine("You have entered a invalid number, try again." + Environment.NewLine);
- Console.ResetColor();
- }
- Console.WriteLine(num1 + 5);
- Console.ReadKey();
- }
- private static void RunExerciseTwelve()
- {
- Console.WriteLine("You successfully ran exercise twelve!");
- Console.ResetColor();
- int start = 1;
- int end = 10;
- for (int i = start; i <= end; i++)
- {
- for (int j = start; j <= end; j++)
- {
- Console.Write("{0,6:d}", (i * j));
- }
- Console.WriteLine();
- }
- }
- // Hoppas det duger för uppgiften.
- private static void RunExerciseThirteen()
- {
- Console.WriteLine("You successfully ran exercise eleven!");
- Console.ResetColor();
- Random r = new Random();
- int val = r.Next(1, 500);
- int guess = 0;
- int guessnum = 0;
- bool correct = false;
- Console.WriteLine("I'm thinking of a number between 1-500, can you guess what number it is?");
- while (!correct)
- {
- Console.Write("Guess: ");
- string input = Console.ReadLine();
- if (!int.TryParse(input, out guess))
- {
- Console.WriteLine("That's not a number, try again.");
- continue;
- }
- guessnum++;
- if (guess < val)
- {
- Console.WriteLine("No, the number I'm thinking of is higher than that number.");
- }
- else if (guess > val)
- {
- Console.WriteLine("No, the number I'm thinking of is lower than that number.");
- }
- else
- {
- correct = true;
- Console.ForegroundColor = ConsoleColor.Green;
- Console.WriteLine("You guessed right and it only took you " + guessnum + " tries!");
- }
- }
- }
- private static void RunExerciseFourteen()
- {
- Console.WriteLine("You successfully ran exercise fourteen!");
- Console.ResetColor();
- }
- private static void RunExerciseTwentyOne()
- {
- Console.WriteLine("You successfully ran exercise twentyone!");
- Console.ResetColor();
- }
- private static void RunTest() // använder för att lättare testa saker
- {
- //Console.WriteLine("Enter a number: ");
- //int x = int.Parse(Console.ReadLine());
- //double sum = 0;
- //for (int i = 0; i < x; i++)
- //{
- // Console.WriteLine("Ange tal {0}: ", i);
- // double number = double.Parse(Console.ReadLine());
- // sum += number;
- //}
- //Console.WriteLine("Sum of the entered numbers is: {0}", sum);
- //Console.ReadLine();
- //{
- // Console.WriteLine("Enter the radius of the circle : ");
- // var c = Convert.ToInt32(Console.ReadLine());
- // while (c <= 4)
- // {
- // Console.WriteLine("Number {0}", c);
- // c++;
- // }
- //}
- //string number;
- //double total = 0;
- //int numbers = 0;
- //while ((number = Console.ReadLine()) != "")
- //{
- // total += double.Parse(number);
- // numbers++;
- //}
- //Console.WriteLine("The average of the numbers entered is {0}", total / numbers);
- }
- static void Main(string[] args)
- {
- var keepAlive = true;
- while (keepAlive)
- {
- try
- {
- Console.Write("Enter assignment number (or -1 to exit): ");
- var assignmentChoice = int.Parse(Console.ReadLine() ?? "");
- Console.ForegroundColor = ConsoleColor.Green;
- switch (assignmentChoice)
- {
- case 1:
- RunExerciseOne();
- break;
- case 2:
- RunExerciseTwo();
- break;
- case 3:
- RunExerciseThree();
- break;
- case 4:
- RunExerciseFour();
- break;
- case 5:
- RunExerciseFive();
- break;
- case 6:
- RunExerciseSix();
- break;
- case 7:
- RunExerciseSeven();
- break;
- case 8:
- RunExerciseEight();
- break;
- case 9:
- RunExerciseNine();
- break;
- case 10:
- RunExerciseTen();
- break;
- case 11:
- RunExerciseEleven();
- break;
- case 12:
- RunExerciseTwelve();
- break;
- case 13:
- RunExerciseThirteen();
- break;
- case 14:
- RunExerciseFourteen();
- break;
- case 21:
- RunExerciseTwentyOne();
- break;
- case -1:
- keepAlive = false;
- break;
- case 77: // Använder för att testa saker
- RunTest();
- break;
- default:
- Console.ForegroundColor = ConsoleColor.Red;
- Console.WriteLine("That is not a valid assignment number!");
- break;
- }
- Console.ResetColor();
- Console.WriteLine("Hit any key to continue!");
- Console.ReadKey();
- Console.Clear();
- }
- catch
- {
- Console.ForegroundColor = ConsoleColor.Red;
- Console.WriteLine("That is not a valid assignment number!");
- Console.ResetColor();
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement