0

C# "Social Networking" question

I could use some help figuring this out. I get the basics of what I'm supposed to do -- make a constructor and a property "fit" together so the program creates the desired output, but I have no idea what to "Plug in." Properties and constructors are similar, and the given names for elements aren't nearly descriptive enough for me to read easily. Below is the code. I'm able to understand the basic concepts of the code, but struggle to know how to implement that knowledge, does anyone have any advice on that? using System; using System.Collections.Generic; namespace Code_Coach_Challenge { class Program { static void Main(string[] args) { string postText = Console.ReadLine(); Post post = new Post(); post.Text = postText; post.ShowPost(); } } class Post { private string text; //write a constructor here public void ShowPost() { Console.WriteLine(text); } //write a property for member text

30th Jul 2022, 8:00 PM
MAB
MAB - avatar
12 Respuestas
0
Remove line 32 (there is already input in the Main method.) Remove "string" in line 35 – the type is already specified with the corresponding property.
1st Aug 2022, 6:01 PM
Lisa
Lisa - avatar
+ 1
Could you link your code please? Maybe it's just a small bug.
30th Jul 2022, 9:27 PM
Alex
Alex - avatar
+ 1
Look at the class name: Post with capital P; look at the class property: text with small t. Object methods and properties are called using the "."
31st Jul 2022, 6:46 AM
Lisa
Lisa - avatar
+ 1
Please LINK THE COMPLETE CODE. DO NOT REMOVE THE GIVEN CODE. You are trying to read user input somewhere in the class. Take the given code in the main method and leave it where it is.
1st Aug 2022, 6:28 AM
Lisa
Lisa - avatar
+ 1
MAB Great! Could you please put your code in a script on playground and try to link it? This way it is more readable and we can test it right away. It works like this: Go to Code section, click+, select the programming language, insert your code, save. Come back to this thread, click +, Insert Code, sort for My Code Bits, select your code. I think there could be an issue with ShowPost(): It isn't clear to me if Text refers to the get/set or the property itself and I would like to test this.
1st Aug 2022, 2:43 PM
Lisa
Lisa - avatar
0
1.) Write a constructor for the Post class (1. comment). Look at at the task description to find iut what should be printed to console. 2.) Write a method that gets and sets the Text property (2. comment)
30th Jul 2022, 8:12 PM
Lisa
Lisa - avatar
0
I know that's what I'm supposed to do. How to do that is where I'm struggling. The names the program is using are too similar to be helpful in deciphering what everything is? Maybe I just need to go back through the lessons; constructors and properties are so similar that I can't understand why the code I'm trying isn't working.
30th Jul 2022, 9:21 PM
MAB
MAB - avatar
0
Thank you both! My attempts so far are here: using System; using System.Collections.Generic; namespace Code_Coach_Challenge { class Program { static void Main(string[] args) { string postText = Console.ReadLine(); Post post = new Post(); post.Text = postText; post.ShowPost(); } } class Post { private string text; //write a constructor here public Post (){ Console.WriteLine("New post"); } public void ShowPost() { Console.WriteLine(Text); } string postText = Console.ReadLine(); public string Text { get { return text;} set {string text = value;} //write a property for member text
31st Jul 2022, 9:51 PM
MAB
MAB - avatar
0
Hi Lisa, Thank you! I edited my response to include the given code.
1st Aug 2022, 2:27 PM
MAB
MAB - avatar
0
Hi Lisa, Sorry but I'm not seeing the option to add code that you described. I've made my code public on the playground, though, so hopefully linking it here will help? I appreciate you taking the time to help me with this. https://code.sololearn.com/cLaRYTByO88r/#cs
1st Aug 2022, 5:19 PM
MAB
MAB - avatar
0
Lisa, This worked, thank you! I really appreciate your help.
1st Aug 2022, 6:37 PM
MAB
MAB - avatar
0
using System; using System.Collections.Generic; namespace Code_Coach_Challenge { class Program { static void Main(string[] args) { string postText = Console.ReadLine(); Post post = new Post(); post.Text = postText; post.ShowPost(); } } class Post { private string text; public string Text { get{return text;} set{text = value;} } //write a constructor here public void ShowPost() { Console.WriteLine("New post"); Console.WriteLine(text); } //write a property for member text } } This is the solution that I came up with. I don't think that this is the best way to solve it, but it was the only solution that I could think of.
14th Nov 2022, 6:56 PM
Robert