Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            var post = new Post("C# question", "Blah blah blah");

            //post.CurrentVotes = 5;  is not accessible. This creates safety


            post.UpVote();
            post.UpVote();
            post.UpVote();
            post.UpVote();

            post.DownVote();
            post.DownVote();

            Console.WriteLine(post.CurrentVotes);
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            Post post = new Post("Titeln", "Vad har jag att säga");

            post.UpVote();
            post.UpVote();
            post.UpVote();
            Console.WriteLine(post.VoteValue());
            post.UpVote();
            post.DownVote();
            Console.WriteLine(post.VoteValue());
            post.DownVote();
            Console.WriteLine(post.VoteValue());
            post.DownVote();
            Console.WriteLine(post.Created);
            Console.WriteLine(post.Title + "  " + post.Description);
            Console.WriteLine(post.VoteValue());
            Console.ReadLine();
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            var newPost   = new Post();
            var isRunning = true;


            Console.WriteLine("Title:");
            var title = Console.ReadLine();

            Console.WriteLine("Description:");
            var description = Console.ReadLine();
            var date        = DateTime.Now;

            newPost.CreatePost(title, description, date);

            Console.WriteLine();
            Console.WriteLine("Title: {0}", newPost.ShowTitle());
            Console.WriteLine("Description: {0}", newPost.ShowDescription());
            Console.WriteLine(newPost.ShowDateTime());
            Console.WriteLine();

            while (isRunning)
            {
                Console.WriteLine("Do you like this post? y/n (To exit press e)");
                var vote = Console.ReadLine();
                switch (vote.ToLower())
                {
                case "y":
                    newPost.UpVote();
                    break;

                case "n":
                    newPost.DownVote();
                    break;

                case "e":
                    isRunning = false;
                    break;

                default:
                    Console.WriteLine("Error try one of the inputs above");
                    break;
                }
            }

            Console.WriteLine();

            Console.WriteLine();
            Console.WriteLine("Title: {0}", newPost.ShowTitle());
            Console.WriteLine("Description: {0}", newPost.ShowDescription());
            Console.WriteLine(newPost.ShowDateTime());
            Console.WriteLine("Upvotes: {0}, Downvotes: {1}", newPost.ShowUpVotes(), newPost.ShowDownVotes());
            Console.WriteLine("Exiting application...");
        }
Ejemplo n.º 4
0
        static void Main(string[] args)
        {
            var title       = "Title";
            var description = "Description";

            var post = new Post(title, description);

            Console.WriteLine($"Post created at: {post.Created:F}" +
                              $"\nTitle: {post.Title}" +
                              $"\nDescription: {post.Description}");

            for (int i = 0; i < 3; i++)
            {
                post.UpVote();
            }
            Console.WriteLine("Votes: " + post.Votes);

            for (int i = 0; i < 2; i++)
            {
                post.DownVote();
            }
            Console.WriteLine("Votes: " + post.Votes);

            for (int i = 0; i < 3; i++)
            {
                post.UpVote();
            }
            Console.WriteLine("Votes: " + post.Votes);

            Thread.Sleep(2000);

            var title1       = "Title 1";
            var description1 = "Description 1";

            post.Modify(title1, description1);

            Console.WriteLine($"Post modified at: {post.Created:F}" +
                              $"\nTitle: {post.Title}" +
                              $"\nDescription: {post.Description}");
            Console.WriteLine("Votes: " + post.Votes);
        }
Ejemplo n.º 5
0
        static void Main(string[] args)
        {
            var post = new Post
            {
                Title       = "First Blog Post",
                Description = "Hello World",
                DateCreated = new DateTime(2018, 06, 04)
            };

            var viewPost = true;

            post.DisplayPost();


            while (viewPost)
            {
                Console.WriteLine(UserPromptMessage);
                var input = Console.ReadLine();


                switch (input.ToLower())
                {
                case "u":
                    post.UpVote();
                    Console.WriteLine("Vote has been recorded");
                    Console.WriteLine();
                    break;

                case "d":
                    post.DownVote();
                    Console.WriteLine("Vote has been recorded");
                    Console.WriteLine();
                    break;

                case "s":
                    post.ShowVotes();
                    break;

                case "x":
                    Console.WriteLine("Exiting Application");
                    viewPost = false;
                    break;

                default:
                    Console.WriteLine("Invalid input");
                    Console.WriteLine();
                    break;
                }
            }
        }
        static void Main(string[] args)
        {
            var post = new Post();
            int choice;

            try
            {
                do
                {
                    Console.Write("1-Add a post\n2-Upvote\n3-DownVote\n4-CurrentVotes\n0-Quit\n");
                    choice = Convert.ToInt32(Console.ReadLine());


                    switch (choice)
                    {
                    case 1:
                    {
                        Console.WriteLine("Enter Title:");
                        post.Title = Console.ReadLine().ToString();
                        Console.WriteLine("Enter Description:");
                        post.Description  = Console.ReadLine().ToString();
                        post.CreationDate = DateTime.Today;
                        break;
                    }

                    case 2:
                    {
                        post.UpVote();
                        break;
                    }

                    case 3:
                    {
                        post.DownVote();
                        break;
                    }

                    case 4:
                    {
                        Console.WriteLine("The current votes for the post is " + post.score());
                        break;
                    }
                    }
                } while (choice != 0);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
Ejemplo n.º 7
0
        static void Main(string[] args)
        {
            var newPost = new Post();

            newPost.Title       = "How to do I create a post to StackOverflow?";
            newPost.Description = "I can't post anything to StackOverflow.";
            newPost.DownVote();
            newPost.DownVote();
            newPost.DownVote();
            newPost.DownVote();
            newPost.DownVote();
            newPost.UpVote();
            newPost.UpVote();
            newPost.UpVote();

            Console.WriteLine(newPost.Title);
            Console.WriteLine(newPost.Description);
            Console.WriteLine(newPost.DateCreated);
            Console.WriteLine();
            Console.WriteLine("Upvotes: " + newPost.UpVotesCount);
            Console.WriteLine("Downvotes: " + newPost.DownVotesCount);
            Console.WriteLine("Post Score: " + newPost.PostScore);
        }
Ejemplo n.º 8
0
        //Design a class called Post. This class models a StackOverflow post. It should have properties
        //for title, description and the date/time it was created. We should be able to up-vote or down-vote
        //a post. We should also be able to see the current vote value. In the main method, create a post,
        //up-vote and down-vote it a few times and then display the the current vote value.
        //In this exercise, you will learn that a StackOverflow post should provide methods for up-voting
        //and down-voting. You should not give the ability to set the Vote property from the outside,
        //because otherwise, you may accidentally change the votes of a class to 0 or to a random
        //number. And this is how we create bugs in our programs. The class should always protect its
        //state and hide its implementation detail.

        //Educational tip:
        //The aim of this exercise is to help you understand that classes should
        //encapsulate data AND behaviour around that data. Many developers (even those with years of
        //experience) tend to create classes that are purely data containers, and other classes that are
        //purely behaviour (methods) providers. This is not object-oriented programming. This is
        //procedural programming. Such programs are very fragile. Making a change breaks many parts
        //of the code.

        static void Main(string[] args)
        {
            var post = new Post
            {
                Title       = "HELLO WORLD",
                Description = "This is some awesome description added to this stack overflow post."
            };

            Console.WriteLine("Title: " + post.Title);
            Console.WriteLine("Description: " + post.Description);
            Console.WriteLine("Date/Time Creation: " + post.CreationDateTime);

            post.UpVote();   //1
            post.UpVote();   //2
            post.UpVote();   //3
            post.UpVote();   //4
            post.UpVote();   //5
            post.DownVote(); //4
            post.DownVote(); //3
            post.DownVote(); //2


            Console.WriteLine("Number of Votes: " + post.Score);
        }
Ejemplo n.º 9
0
        public static void Main(string[] args)
        {
            Console.WriteLine("Welcome to STACKOVERFLOW" + Environment.NewLine);

            Console.WriteLine("Post title:");
            string title = Console.ReadLine();

            Console.WriteLine(Environment.NewLine + "Post description:");
            string description = Console.ReadLine();

            var post = new Post(title, description);

            Console.WriteLine(Environment.NewLine + "Use \"up\" and \"down\" to cast your vote for this post.");
            Console.WriteLine("Use \"end\" to close this post." + Environment.NewLine);

            while (true)
            {
                string inputVote = Console.ReadLine().ToLower();

                if (inputVote == "end")
                {
                    break;
                }

                if (inputVote == "up")
                {
                    post.UpVote();
                }
                else if (inputVote == "down")
                {
                    post.DownVote();
                }
                else
                {
                    Console.WriteLine("Invalid Input!");
                }
            }

            Console.WriteLine(Environment.NewLine + post);
        }
Ejemplo n.º 10
0
        static void Main(string[] args)
        {
            var post = new Post();

            try
            {
                do
                {
                    if (string.IsNullOrEmpty(post.Title))
                    {
                        Console.WriteLine("Please enter a title for your post: ");
                        var titleInput = Console.ReadLine();
                        Console.WriteLine("Please enter a description for your post: ");
                        var descriptioInput = Console.ReadLine();

                        post.CreatePost(titleInput, descriptioInput);
                    }
                    else
                    {
                        Console.WriteLine("Please Press U to upvote and d to down vote");
                        var input = Console.ReadLine().ToLower();
                        if (input == "u")
                        {
                            post.UpVote();
                            Console.WriteLine("Total votes: " + post.ShowTally());
                        }
                        else if (input == "d")
                        {
                            post.DownVote();
                            Console.WriteLine("Total votes: " + post.ShowTally());
                        }
                    }
                } while (true);
            }
            catch (Exception ex)
            {
                Console.WriteLine("An error occured: here are some details" + ex);
            }
        }
Ejemplo n.º 11
0
        static void Main(string[] args)
        {
            var myPost = new Post("FirstPost", "Experiment of the program");

            var random        = new Random();
            int randomUpVotes = random.Next(0, 100);

            for (int i = 0; i < randomUpVotes; i++)
            {
                myPost.UpVote();
            }
            int randomDownVotes = random.Next(0, 100);

            for (int i = 0; i < randomDownVotes; i++)
            {
                myPost.DownVote();
            }

            Console.WriteLine(myPost.Title);
            Console.WriteLine(myPost.Description);
            Console.WriteLine(myPost.CreationTime);
            Console.WriteLine("Up votes: {0} | Down votes: {1} | Rating: {2}", randomUpVotes, randomDownVotes, myPost.Rating);
        }