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); }
static void Main(string[] args) { var post = new Post("HelloWorld", "This is my implementation of a mock StackOverFlow post."); Console.WriteLine("The date and time of the creation of this post is: {0}", post.DateTimeOfCreation.ToString()); // let's up-vote/down-vote this post n times, then display its vote value var upvotes = 0; var downvotes = 0; try { Console.WriteLine("How many times would you like to up-vote this post?"); upvotes = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("How many times would you like to down-vote this post?"); downvotes = Convert.ToInt32(Console.ReadLine()); } catch (Exception) { throw new Exception("Input must be an integer"); } for (int i = 0; i < upvotes; i++) { post.Upvote(); } for (int i = 0; i < downvotes; i++) { post.Downvote(); } Console.WriteLine("This post has a vote value of: {0}", post.GetVoteValue()); }
static void Main(string[] args) { var post = new Post("Hello", "World"); System.Console.WriteLine($"{post.Title} {post.Description} {post.TimeCreated} {post.Score}"); post.Upvote(); post.Upvote(); post.Upvote(); post.Upvote(); post.Downvote(); System.Console.WriteLine($"{post.Title} {post.Description} {post.TimeCreated} {post.Score}"); post.Downvote(); post.Downvote(); post.Downvote(); post.Downvote(); System.Console.WriteLine($"{post.Title} {post.Description} {post.TimeCreated} {post.Score}"); }
static void Main(string[] args) { Post myPost = new Post("Help, I need something", "there is a problem, here it is. Help."); for (int i = 0; i < 10; i++) { myPost.Upvote(); } myPost.Downvote(); Console.WriteLine("Score: {0}", myPost.Score); }
static void Main(string[] args) { try { var post = new Post("How do I remove a particular element from an array in JavaScript?", "Is there a simple way to remove a specific element from an array? I have to use core JavaScript -no frameworks are allowed."); post.Upvote(); post.Upvote(); post.Upvote(); post.Upvote(); post.Upvote(); Console.WriteLine("Welcome to StackOverflow"); Console.WriteLine("Title: {0}", post.Title); Console.WriteLine("Description: {0}", post.Description); Console.WriteLine("Press 1 to upvote and 0 to downvote this post."); int vote = Convert.ToInt32(Console.ReadLine()); if (vote == 1) { post.Upvote(); } else { post.Downvote(); } Console.WriteLine("Votes: {0}", post.Votes); } catch (ArgumentException) { Console.WriteLine("Post title and description can't be blank."); } }