Esempio n. 1
0
        public static void Main(string[] args)
        {
            // In the main method, create a post, up-vote and down-vote it a
            // few times and then display the the current vote value.

            var post = new Post(
                "This is the Title",
                "This is the description of the post.",
                DateTime.Now
                );

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

            Console.WriteLine("Current Value: " + post.CurrentValue());
        }
        static void Main(string[] args)
        {
            // In a real world example the string below would be pulled from the inputfield of course...
            Console.WriteLine("Title..:");
            var title = Console.ReadLine();

            Console.WriteLine("Post..:");
            var post = new Post(title, Console.ReadLine());

            // 7 Upvotes...
            for (int i = 1; i <= 7; i++)
            {
                post.Upvote();
            }

            // And 3 Downvotes...
            for (int i = 1; i <= 3; i++)
            {
                post.DownVote();
            }

            Console.WriteLine("Post | ({0}) | \"{1}\" [score: {2}]", post.PostTitle, post.PostContent, post.PostScore);
            Console.ReadKey(true);

            // Here comes reddit! 300 downvotes...
            for (int i = 1; i <= 300; i++)
            {
                post.DownVote();
            }

            // Udemy to the rescue (500 votes!)...
            for (int i = 1; i <= 500; i++)
            {
                post.Upvote();
            }

            Console.WriteLine("Post | ({0}) | \"{1}\" [score: {2}]", post.PostTitle, post.PostContent, post.PostScore);
            Console.ReadKey(true);

            // In the real world there would be an input field for the user to edit the post. We assume this method
            // Would then take the new version of the post and insert it as a new string.
            // Note that this OP is not a nice human as he didn't post the fix!!!
            post.EditPost("Solved - Please close", "Edit: I fixed this now please close the post...");

            Console.WriteLine("Post | ({0}) | \"{1}\" [score: {2}]", post.PostTitle, post.PostContent, post.PostScore);
            Console.ReadKey(true);

            // Downvoted to oblivion for bad internet manners.
            for (int i = 1; i <= 4124; i++)
            {
                post.DownVote();
            }

            Console.WriteLine("Post | ({0}) | \"{1}\" [score: {2}]", post.PostTitle, post.PostContent, post.PostScore);
            Console.ReadKey(true);
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            var post1 = new Post("First Post", "This is the first post");

            Console.WriteLine($"Title: {post1.Title}");
            Console.WriteLine($"Description: {post1.Description}");
            Console.WriteLine($"Created: {post1.Created}");
            post1.DownVote(); // no can do - still has 0 votes
            post1.UpVote();
            post1.UpVote();
            post1.UpVote();
            post1.UpVote();   // has 4 votes
            post1.DownVote(); // has 3 votes
            Console.WriteLine($"Votes: {post1.GetVotes()}");
        }
Esempio n. 4
0
        static void Main(string[] args)
        {
            var post = new Post
            {
                Title       = "New post",
                Description = "Description"
            };

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

            Console.WriteLine("The post has {0} votes", post.Vote);
        }
Esempio n. 5
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);
        }
        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();
        }
Esempio n. 7
0
        static void Main(string[] args)
        {
            Post p = new Post("How do I make a Class in C#?", "I've been trying all day!");

            p.UpVote();                   //   1 Vote
            p.UpVote().UpVote().UpVote(); //+  3 Votes
            p.DownVote().DownVote();      //-  2 Votes
                                          // _________
            Console.WriteLine(p.Votes);   //   2 Votes
        }
Esempio n. 8
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...");
        }
Esempio n. 9
0
        static void Main(string[] args)
        {
            Post myPost = new Post();

            myPost.UpVote();
            myPost.UpVote();
            myPost.UpVote();
            myPost.DownVote();

            Console.WriteLine($"Negative votes: {myPost.NegativeVotes}; Positive votes: {myPost.PositiveVotes}");
        }
Esempio n. 10
0
        static void Main(string[] args)
        {
            Post post = new Post("Should I delete the System32 folder?", "My friend told me to do it");

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

            System.Console.WriteLine("This is my post's vote value: " + post.VoteValue);
        }
        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);
            }
        }
Esempio n. 12
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;
                }
            }
        }
Esempio n. 13
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);
        }
Esempio n. 14
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);
        }
Esempio n. 15
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);
        }
        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);
        }
Esempio n. 17
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);
            }
        }
Esempio n. 18
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);
        }