public void KaldMed_lovligVærdi_returnereResultat_ElBil()
        {
            // arrange
            decimal lovligVærdi = 300000m; // Lovlig værdi
            decimal forventet   = 64000m;

            // act
            decimal resultat = _afgift.ElBilAfgift(lovligVærdi);

            // assert
            Assert.AreEqual(forventet, resultat);
        }
Beispiel #2
0
        internal void DoIt()
        {
            Console.WriteLine("Klient Joined");

            Stream       ns = connectionSocket.GetStream();
            StreamReader sr = new StreamReader(ns);
            StreamWriter sw = new StreamWriter(ns);

            sw.AutoFlush = true;

            while (true)
            {
                sw.WriteLine("Vil du vælge personbil eller elbil?");
                string msg = sr.ReadLine();

                if (msg.ToLower().ToUpper().Contains("person"))
                {
                    sw.WriteLine("Hvad er prisen på personbilen?");
                    string pris = sr.ReadLine();
                    sw.WriteLine("Afgift: " + afgift.BilAfgift(Convert.ToInt32(pris)) + " - Tryk enter for ny beregning");
                    sr.ReadLine();
                }
                else if (msg.ToLower().ToUpper().Contains("el"))
                {
                    sw.WriteLine("Hvad er prisen på elbilen?");
                    string pris = sr.ReadLine();
                    sw.WriteLine("Afgift: " + afgift.ElBilAfgift(Convert.ToInt32(pris)) + " - Tryk enter for ny beregning");
                    sr.ReadLine();
                }
            }
            ns.Close();
            connectionSocket.Close();
        }
Beispiel #3
0
        internal void DoIt()
        {
            Stream ns = connectionSocket.GetStream();

            Afgift       afgift = new Afgift();
            StreamReader sr     = new StreamReader(ns);
            StreamWriter sw     = new StreamWriter(ns);

            sw.AutoFlush = true;
            while (true)
            {
                string message = sr.ReadLine();
                string answer  = "";
                while (!string.IsNullOrEmpty(message))
                {
                    Console.WriteLine("Client: " + message);
                    if (message.Contains("Elbil"))
                    {
                        var number = Regex.Match(message, @"\d+").Value;

                        if (number != null)
                        {
                            int elbilafgift = Convert.ToInt32(number);


                            answer = "Afgift på elbil: " + afgift.ElBilAfgift(elbilafgift).ToString();
                        }
                        else
                        {
                            answer = "Angiv pris f.eks. 200000";
                        }
                    }
                    else if (message.Contains("Personbil"))
                    {
                        var number = Regex.Match(message, @"\d+").Value;

                        if (number != null)
                        {
                            int personbilafgift = Convert.ToInt32(number);


                            answer = "Afgift på personbil: " + afgift.Bilafgift(personbilafgift).ToString();
                        }
                        else
                        {
                            answer = "Angiv pris f.eks. 200000";
                        }
                    }
                    else
                    {
                        answer = "Angiv om det er Personbil eller Elbil og prisen";
                    }
                    sw.WriteLine(answer);
                    message = sr.ReadLine();
                }

                ns.Close();
                connectionSocket.Close();
            }
        }
Beispiel #4
0
        // this method needs to be async and have the return type Task
        public async Task doIt()
        {
            Stream ns = _connectionSocket.GetStream();
            // Stream ns = new NetworkStream(connectionSocket);

            StreamReader sr = new StreamReader(ns);
            StreamWriter sw = new StreamWriter(ns);

            sw.AutoFlush = true; // enable automatic flushing


            while (true)
            {
                string type = await sr.ReadLineAsync();

                string price = await sr.ReadLineAsync();

                // runs this code if the type is per
                if (type == "per")
                {
                    int outcome = Afgift.BilAfgift(Convert.ToInt32(price));
                    sw.WriteLine(outcome + " kr");
                }

                // runs this code if the type is el
                if (type == "el")
                {
                    int outcome = Afgift.ElBilAfgift(Convert.ToInt32(price));
                    sw.WriteLine(outcome + " kr");
                }
            }

            ns.Close();
        }
        public void DoIt()
        {
            Stream       networkStream = _connectionSocket.GetStream();
            StreamReader sr            = new StreamReader(networkStream);
            StreamWriter sw            = new StreamWriter(networkStream);

            sw.AutoFlush = true; // enable automatic flushing

            string message = sr.ReadLine();
            string answer  = "";

            while (message != null && message != "")
            {
                Console.WriteLine("Client: " + message);
                if (message == "Personbil")
                {
                    answer = "Indtast pris";
                    sw.WriteLine(answer);

                    message = sr.ReadLine();
                    int pris = Convert.ToInt32(message);

                    Afgift afgift = new Afgift();

                    answer = ("Afgiften er " + afgift.BilAfgift(pris).ToString());
                    sw.WriteLine(answer);
                }

                if (message == "Elbil" || message == "elbil")
                {
                    answer = "Indtast pris:";
                    sw.WriteLine(answer);

                    message = sr.ReadLine();

                    try
                    {
                        int pris = Convert.ToInt32(message);

                        Afgift afgift = new Afgift();

                        answer = ("Elbil afgiften er: " + afgift.ElBilAfgift(pris).ToString());
                        sw.WriteLine(answer);
                    }
                    catch (FormatException e)
                    {
                        Console.WriteLine("Svar skal kun være tal", e.Message);
                    }
                }

                else
                {
                    answer = "Du skal indtaste personbil eller elbil";
                    sw.WriteLine();
                }
                message = sr.ReadLine();
            }
        }
Beispiel #6
0
        public void TestMethodElBilAfgiftOver200000()
        {
            Afgift a           = new Afgift();
            var    acualResult = a.ElBilAfgift(462000);

            const double expectedResult = 112600;

            Assert.AreEqual(expectedResult, acualResult, 0.5,
                            "ERROR: The expected result did not match the actual result.");
        }
Beispiel #7
0
        public void ElBilAfgift()
        {
            //Arrange
            var bilafgift = new Afgift();

            //Act
            double afgift = bilafgift.ElBilAfgift(100000);

            //Assert
            Assert.AreEqual(17000, afgift);
        }
Beispiel #8
0
        public void ElbilUnder200000()
        {
            // ARRANGE
            int    pris     = 150000;
            double expected = (pris * 0.85) * 0.20;

            // ACT
            int actual = Afgift.ElBilAfgift(pris);

            // ASSERT
            Assert.AreEqual((int)expected, actual, "Are not equal");
        }
Beispiel #9
0
        public void TestEilBilAfgiftForhøjet()
        {
            // Arrange
            Afgift afgiftKlasse = new Afgift();

            // Act
            int resultat          = afgiftKlasse.ElBilAfgift(200001);
            int forventetResultat = 34000;

            // Assert
            Assert.AreEqual(forventetResultat, resultat);
        }
Beispiel #10
0
        public void ElbilOver200000()
        {
            // ARRANGE
            int    pris     = 250000;
            double expected = ((pris * 1.50) - 130000) * 0.20;

            // ACT
            int actual = Afgift.ElBilAfgift(pris);

            // ARRANGE
            Assert.AreEqual((int)expected, actual, "Are not equal");
        }
Beispiel #11
0
        public void TestElBilAfgift()
        {
            // Arrange
            Afgift afgiftKlasse = new Afgift();

            // Act
            int resultat          = afgiftKlasse.ElBilAfgift(100000);
            int forventetResultat = 17000;

            // Assert
            Assert.AreEqual(forventetResultat, resultat);
        }
        public void ElbilAfgiftTest()
        {
            //Arrange
            double pris = 250000;

            double expectedvalue = 49000;

            //Act
            double actual = Afgift.ElBilAfgift(pris);

            //Assert
            Assert.AreEqual(expectedvalue, actual);
        }
Beispiel #13
0
        public void ElBilAfgiftOver200000()
        {
            // ARRANGE
            Afgift afgift   = new Afgift();
            int    pris     = 400000;
            double expected = ((pris * 1.50) - 130000) * 0.20;

            // ACT
            int actual = afgift.ElBilAfgift(pris);

            // ASSERT
            Assert.AreEqual(expected, actual, "Are not equal");
        }
Beispiel #14
0
        public void DoIt()
        {
            try
            {
                Stream       ns = _connectionSocket.GetStream();
                StreamReader sr = new StreamReader(ns);
                StreamWriter sw = new StreamWriter(ns);
                sw.AutoFlush = true;
                Afgift afgift = new Afgift();

                string messageCarType = sr.ReadLine();
                string messagePrice   = sr.ReadLine();
                int    price          = Convert.ToInt32(messagePrice);
                string answer;

                switch (messageCarType)
                {
                case "Personbil":
                {
                    string regAfgift = afgift.BilAfgift(price).ToString();
                    answer = "Registreringsafgiften er: " + regAfgift;
                    sw.WriteLine(answer);
                    break;
                }

                case "Elbil":
                {
                    string regAfgift = afgift.ElBilAfgift(price).ToString();
                    answer = "Registreringsafgiften er: " + regAfgift;
                    sw.WriteLine(answer);
                    break;
                }

                default:
                {
                    answer = "Du skal skrive Personbil eller Elbil";
                    sw.WriteLine(answer);
                    break;
                }
                }
            }
            catch (FormatException e)
            {
                Console.WriteLine("Format is not number", e.Message);
            }
            catch (ArgumentNullException e)
            {
                Console.WriteLine("Argument cant be null or empty", e.Message);
            }
        }
Beispiel #15
0
        public void ElBilAfgiftUnder0()
        {
            // ARRANGE
            Afgift afgift = new Afgift();
            int    pris   = -35000;

            // ACT & ARRANGE
            try
            {
                afgift.ElBilAfgift(pris);
                Assert.Fail();
            }
            catch (ArgumentException)
            { }
        }
Beispiel #16
0
        public void ElbilUnder0()
        {
            // ARRANGE
            int pris = -1000;

            // ACT & ASSERT
            try
            {
                Afgift.ElBilAfgift(pris);
                Assert.Fail(); // If it gets to this line, no exception was thrown.
            }
            catch (ArgumentException e)
            {
                Console.WriteLine(e.Message);
            }
        }
Beispiel #17
0
        public string BilAfgift(string bilType, int pris)
        {
            int bilAfgift = 0;

            if (bilType == "Personbil" || bilType == "personbil")
            {
                bilAfgift = Afgift.BilAfgift(pris);
            }

            else if (bilType == "Elbil" || bilType == "elbil")
            {
                bilAfgift = Afgift.ElBilAfgift(pris);
            }

            string answer = "Registreringsafgiften er: " + bilAfgift.ToString();

            return(answer);
        }
Beispiel #18
0
        internal void UdregnAfgift()
        {
            Stream       networkStream = connectionSocket.GetStream();
            StreamReader sr            = new StreamReader(networkStream);
            StreamWriter sw            = new StreamWriter(networkStream);

            sw.AutoFlush = true;

            string message = "startup";
            string answer  = "";

            while (message != null && message != "")
            {
                sw.WriteLine("Hvilken type bil skal afgiften regnes på? Personbil eller Elbil?");
                message = sr.ReadLine();
                string indtastetBiltype = message;

                sw.WriteLine("Hvad er prisen på bilen?");
                message = sr.ReadLine();
                int bilpris = Convert.ToInt32(message);


                if (indtastetBiltype == "Elbil" || indtastetBiltype == "elbil") //hvordan gør man at den ikke er case sensitive?
                {
                    string afgiftResultElbil = Convert.ToString(Afgift.ElBilAfgift(bilpris));
                    answer = "Afgiften på " + indtastetBiltype + "en er  " + afgiftResultElbil;
                }
                else if (indtastetBiltype == "Personbil" || indtastetBiltype == "personbil")
                {
                    string afgiftResultatPersonbil = Convert.ToString(Afgift.BilAfgift(bilpris));
                    answer = "Afgiften på " + indtastetBiltype + "en er " + afgiftResultatPersonbil;
                }
                else
                {
                    answer = "Den indtastede biltype er ugyldig.";
                }

                sw.WriteLine(answer);
            }

            networkStream.Close();
            connectionSocket.Close();
        }
        public void Doit()
        {
            Stream ns = _connectionSocket.GetStream();

            StreamReader sr = new StreamReader(ns);
            StreamWriter sw = new StreamWriter(ns);

            sw.AutoFlush = true; // enable automatic flushing

            string message = sr.ReadLine();
            string answer;

            while (message != "")
            {
                int pris = Int32.Parse(message);
                Console.WriteLine("Bilens pris: " + pris + " kr.");
                sw.WriteLine(pris);

                string bilType = sr.ReadLine();
                Console.WriteLine("Bilens type: " + bilType);
                if (bilType == "benzin")
                {
                    answer = Convert.ToString(Afgift.BilAfgift(pris));
                    Console.WriteLine("Bilens Afgift " + answer + " kr.");

                    sw.WriteLine(answer);
                }
                else if (bilType == "el")
                {
                    answer = Convert.ToString(Afgift.ElBilAfgift(pris));
                    Console.WriteLine("Bilens Afgift " + answer + " kr.");
                    sw.WriteLine(answer);
                }
                else
                {
                    answer = "Fejl";
                    sw.WriteLine(answer);
                }
            }

            ns.Close();
            _connectionSocket.Close();
        }
Beispiel #20
0
        internal void DoIt()
        {
            Stream       ns = connectionSocket.GetStream();
            StreamReader sr = new StreamReader(ns);
            StreamWriter sw = new StreamWriter(ns);

            sw.AutoFlush = true; // enable automatic flushing

            string message = sr.ReadLine();
            string answer;

            while (message != null && message != "")
            {
                Console.WriteLine("Client: " + message);
                if (message.Contains("elbil"))
                {
                    var number = Regex.Match(message, @"\d+").Value;

                    if (number != null)
                    {
                        int price = Convert.ToInt32(number);
                        if (message.Contains($"{number}k"))
                        {
                            price = price * 1000;
                        }

                        answer = "Afgift på ElBil: " + nyafgift.ElBilAfgift(price).ToString();
                    }
                    else
                    {
                        answer = "Please enter price eg. 200k";
                    }
                }
                else if (message.Contains("personbil"))
                {
                    var number = Regex.Match(message, @"\d+").Value;

                    if (number != null)
                    {
                        int price = Convert.ToInt32(number);
                        if (message.Contains($"{number}k"))
                        {
                            price = price * 1000;
                        }

                        answer = "Afgift på PersonBil: " + nyafgift.BilAfgift(price).ToString();
                    }
                    else
                    {
                        answer = "Please enter price eg. 200k";
                    }
                }
                else
                {
                    answer = "Please define PersonBil or Elbil and your price";
                }
                sw.WriteLine(answer);
                message = sr.ReadLine();
            }
            ns.Close();
            connectionSocket.Close();
        }
Beispiel #21
0
        private static void Listen(object obj)
        {
            Console.WriteLine("Tråd oprettet.");

            TcpClient client = (TcpClient)obj;

            NetworkStream nwStream = client.GetStream();
            StreamReader  stReader = new StreamReader(nwStream);
            StreamWriter  stWriter = new StreamWriter(nwStream)
            {
                AutoFlush = true
            };

            while (true)
            {
                try
                {
                    stWriter.WriteLine("Vil du vælge personbil eller elbil? 'Stop' for at lukke programmet!");
                    string msg = stReader.ReadLine();
                    if (msg != null && !msg.All(char.IsDigit) && msg.Length < int.MaxValue)
                    {
                        if (msg.ToLower().Contains("person"))
                        {
                            Console.WriteLine("Personbil valgt");
                            stWriter.WriteLine("Angiv prisen for personbilen:");
                            string pris = stReader.ReadLine();
                            if (pris != null && pris.All(char.IsDigit))
                            {
                                Console.WriteLine("Pris: " + pris);
                                stWriter.WriteLine("Afgift for personbil: " +
                                                   Afgift.BilAfgift(Convert.ToInt32(pris)) +
                                                   " - Tryk enter for at udregne ny pris.");
                                Console.WriteLine("Afgift: " + Afgift.BilAfgift(Convert.ToInt32(pris)));
                                stReader.ReadLine();
                            }
                        }

                        if (msg.ToLower().Contains("el"))
                        {
                            Console.WriteLine("Elbil valgt");
                            stWriter.WriteLine("Angiv prisen for elbilen:");
                            string pris = stReader.ReadLine();
                            if (pris != null && pris.All(char.IsDigit))
                            {
                                Console.WriteLine("Pris: " + pris);
                                stWriter.WriteLine("Afgift for elbil: " +
                                                   Afgift.ElBilAfgift(Convert.ToInt32(pris)) +
                                                   " - Tryk enter for at udregne ny pris.");
                                Console.WriteLine("Afgift: " + Afgift.ElBilAfgift(Convert.ToInt32(pris)));
                                stReader.ReadLine();
                            }
                        }

                        if (msg.ToLower().Contains("stop"))
                        {
                            break;
                        }
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine("Klient stoppet.");
                    break;
                }
            }
        }
Beispiel #22
0
        public void DoIt()
        {
            while (true)
            {
                try
                {
                    Stream ns = ConnectionSocket.GetStream();
                    var    sr = new StreamReader(ns);
                    var    sw = new StreamWriter(ns)
                    {
                        AutoFlush = true
                    };
                    var    message1 = sr.ReadLine();
                    double message2 = double.Parse(sr.ReadLine());
                    var    answer   = "";

                    if (message1 == string.Empty)
                    {
                        Console.WriteLine("Empty string detected!");
                        Console.WriteLine(
                            "Either the client sent an empty string or the connection is lost.\nRestarting server");
                        Thread.Sleep(2300);
                        Console.Clear();
                        ns.Close();
                        ConnectionSocket.Close();
                        break;
                    }

                    while (!string.IsNullOrEmpty(message1) && message2 != 0)
                    {
                        Console.WriteLine("Client: " + message1);
                        Console.WriteLine("Client: " + message2);

                        if (message1 == "stop")
                        {
                            Console.WriteLine("Received interrupt signal!");
                            Console.WriteLine("The server will close the connection and wait for a new client.");
                            sw.WriteLine("Received interrupt signal! Closing connection...");
                            Thread.Sleep(2300);
                            Console.Clear();
                            ns.Close();
                            ConnectionSocket.Close();
                            break;
                        }

                        if (message1 == "Personbil")
                        {
                            Afgift a = new Afgift();
                            answer = (a.BilAfgift(message2)).ToString();
                        }
                        else if (message1 == "Elbil")
                        {
                            Afgift a = new Afgift();
                            answer = (a.ElBilAfgift(message2)).ToString();
                        }

                        // Responds to client.
                        //answer = message1.ToUpper();
                        sw.WriteLine(answer);
                        message1 = sr.ReadLine();
                    }

                    // Closes connection after client disconnect.
                    ns.Close();
                    ConnectionSocket.Close();
                }
                catch (ArgumentNullException)
                {
                    Console.WriteLine("Caught a ArgumentNullException");
                    Console.WriteLine("Probably lost connection to client.\nEnding thread...");
                    ConnectionSocket.Close();
                    break;
                }
                catch (IOException)
                {
                    Console.WriteLine("Caught a IOException");
                    Console.WriteLine("Probably lost connection to client.\nEnding thread...");
                    ConnectionSocket.Close();
                    break;
                }
            }
        }
Beispiel #23
0
        static void Main(string[] args)
        {
            // IPAddress ip = new IPAddress("127.0.0.1");

            IPAddress ip = IPAddress.Parse("127.0.0.1");


            TcpListener serverSocket = new TcpListener(ip, 6789);

            //Alternatively but deprecated
            //TcpListener serverSocket = new TcpListener(6789);


            serverSocket.Start();
            Console.WriteLine("Server started");

            TcpClient connectionSocket = serverSocket.AcceptTcpClient();

            //Socket connectionSocket = serverSocket.AcceptSocket();
            Console.WriteLine("Server activated");

            Stream ns = connectionSocket.GetStream();
            // Stream ns = new NetworkStream(connectionSocket);

            StreamReader sr = new StreamReader(ns);
            StreamWriter sw = new StreamWriter(ns);

            sw.AutoFlush = true; // enable automatic flushing


            string message2 = sr.ReadLine();
            string message  = sr.ReadLine();
            double answer   = 00.0;
            double pris     = Convert.ToDouble(message);


            if (message2 == "Personbil")
            {
                if (pris < 200000)
                {
                    Afgift.BilAfgift(pris);
                }
                else if (pris > 200000)
                {
                    Afgift.BilAfgift(pris);
                }

                Console.WriteLine("Client: " + Afgift.BilAfgift(pris));
                answer = Afgift.BilAfgift(pris);
                sw.WriteLine(answer);
            }
            else if (message2 == "Elbil")
            {
                if (pris < 200000)
                {
                    Afgift.ElBilAfgift(pris);
                }
                else if (pris > 200000)
                {
                    Afgift.ElBilAfgift(pris);
                }

                Console.WriteLine("Client: " + Afgift.ElBilAfgift(pris));
                answer = Afgift.ElBilAfgift(pris);
                sw.WriteLine(answer);
            }
            Console.ReadLine();

            ns.Close();
            connectionSocket.Close();
            serverSocket.Stop();
        }
Beispiel #24
0
        public void DoIt()
        {
            Stream       ns = _connectionSocket.GetStream();
            StreamReader sr = new StreamReader(ns);
            StreamWriter sw = new StreamWriter(ns);

            sw.AutoFlush = true;
            Afgift afgift = new Afgift();

            string messageCarType = sr.ReadLine();
            string messagePrice   = sr.ReadLine();

            while (!string.IsNullOrEmpty(messageCarType))
            {
                Console.WriteLine("Client: " + messageCarType);
                string answer;

                if (messageCarType == "Personbil" || messageCarType == "personbil")
                {
                    try
                    {
                        int pris = Convert.ToInt32(messagePrice);

                        string regAfgift = afgift.BilAfgift(pris).ToString() + " kr.";
                        answer = ("Registreringsafgiften er: " + regAfgift);
                        sw.WriteLine(answer);
                    }
                    catch (FormatException e)
                    {
                        Console.WriteLine("Formattet er ikke tal", e.Message);
                    }
                    finally
                    {
                        answer = "Formattet kan kun være tal";
                        sw.WriteLine(answer);
                    }
                }

                if (messageCarType == "Elbil" || messageCarType == "elbil")
                {
                    try
                    {
                        int pris = Convert.ToInt32(messagePrice);

                        string regAfgift = afgift.ElBilAfgift(pris).ToString() + " kr.";
                        answer = ("Registreringsafgiften er: " + regAfgift);
                        sw.WriteLine(answer);
                    }
                    catch (FormatException e)
                    {
                        Console.WriteLine("Formattet er ikke tal", e.Message);
                    }
                    finally
                    {
                        answer = "Formattet kan kun være tal";
                        sw.WriteLine(answer);
                    }
                }
                else
                {
                    answer = "Du skal indtaste personbil eller elbil";
                    sw.WriteLine(answer);
                }

                messageCarType = sr.ReadLine();
            }
        }
Beispiel #25
0
        internal void DoIt()
        {
            Stream       ns = connectionSocket.GetStream();
            StreamReader sr = new StreamReader(ns);
            StreamWriter sw = new StreamWriter(ns)
            {
                AutoFlush = true
            };

            string message = sr.ReadLine();
            string answer;

            // Undersøger om beskeden er tom eller null før der fortsættes
            while (!string.IsNullOrEmpty(message))
            {
                try
                {
                    // Kunne eventuelt bruge decimal.TryParse(message, out var pris)

                    decimal pris = decimal.Parse(message);

                    if (pris >= 0)
                    {
                        sw.WriteLine("Hvilken type bil drejer det sig om?");
                        string type = sr.ReadLine();
                        switch (type.ToLower())
                        {
                        case "normal":
                            sw.WriteLine($"Biler af typen {type} med en pris på {pris} vil have en afgift på {afgift.BilAfgift(pris)}");
                            break;

                        case "el":
                            sw.WriteLine($"Biler af typen {type} med en pris på {pris} vil have en afgift på {afgift.ElBilAfgift(pris)}");
                            break;

                        default:
                            sw.WriteLine("Brug venligst 'normal' eller 'el'");
                            break;
                        }
                    }
                    else
                    {
                        throw new Exception("Systemet kan ikke håndtere negative tal");
                    }
                }
                catch (Exception e)
                {
                    answer = $"Brug venligst tal | {e.Message}";
                    sw.WriteLine(answer);
                }

                // Venter på en ny pris


                message = sr.ReadLine();
            }

            sw.WriteLine("Stopping ..");
            ns.Close();
            connectionSocket.Close();
        }
Beispiel #26
0
        public static void Main(string[] args)
        {
            IPAddress ip = IPAddress.Parse("127.0.0.1");


            TcpListener serverSocket = new TcpListener(ip, 6789);


            serverSocket.Start();
            Console.WriteLine("Server started");

            TcpClient connectionSocket = serverSocket.AcceptTcpClient();

            Console.WriteLine("Server activated");

            Stream ns = connectionSocket.GetStream();

            StreamReader sr = new StreamReader(ns);
            StreamWriter sw = new StreamWriter(ns);

            sw.AutoFlush = true;


            string message = sr.ReadLine();
            string answer  = "";

            while (message != null && message != "")
            {
                Console.WriteLine("Client: " + message);
                if (message == "Bil" || message == "bil")
                {
                    answer = "Indtast pris på den pågældende bil.";
                    sw.WriteLine(answer);
                    message = sr.ReadLine();
                    int pris = Convert.ToInt32(message); //her koverteres string til int så vi ved hvad prisen er

                    string Udregnet = Afgift.BilAfgift(pris).ToString();

                    answer = "Afgiften er så ledes: " + Udregnet;
                    sw.WriteLine(answer);
                }

                if (message == "Elbil" || message == "elbil")
                {
                    answer = "Indtast pris på den pågældende bil";
                    sw.WriteLine(answer);
                    message = sr.ReadLine();
                    int pris = Convert.ToInt32(message);

                    string udregnet = Afgift.ElBilAfgift(pris).ToString();

                    answer = "Afgiften er så leds: " + udregnet;
                    sw.WriteLine(answer);
                }

                message = sr.ReadLine();
            }

            ns.Close();
            connectionSocket.Close();
            serverSocket.Stop();
        }