How can you change the Speak method to write the sentence "The dog says" + the value of your Sound property. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

How can you change the Speak method to write the sentence "The dog says" + the value of your Sound property.

using System; public class Animal { public string Sound { get; set; } public void Speak() { Console.WriteLine("The dog says woof!"); } } public class Program { public static void Main() { } }

26th May 2017, 4:42 AM
Marlon
Marlon - avatar
12 Answers
+ 3
get {return sound; } ! get{return Sound; } class Animal ! public class Animal static void main !public static void main delete the "public class program" above main.
26th May 2017, 7:13 AM
Manual
Manual - avatar
+ 1
Thanks Alvaro! I tried that ,it didn't work.
26th May 2017, 5:57 AM
Marlon
Marlon - avatar
+ 1
using System; public class Animal { public string Sound { get{return Sound;} set {Sound="woof!";} } public void Speak() { Console.WriteLine("The dog says woof!"+this.Sound); } } public class Program { public static void Main() { } } //this is the error I get: Not all requirements have been met. Your method body must be 'Console.WriteLine("The dog says " + Sound);'
26th May 2017, 6:00 AM
Marlon
Marlon - avatar
+ 1
The "this.Sound" looks good. try doing this as well { set = value; } ! set = "woof!" // in main args add Animal dog = new Animal; dog.Sound = "Woof!";
26th May 2017, 6:30 AM
Manual
Manual - avatar
+ 1
Thanks Manuel! . I tried this. using System; public class Animal { public string Sound { get{return Sound;} set {Sound=value;} } public void Speak() { Console.WriteLine("The dog says"+this.Sound); } } public class Program { public static void Main() { Animal dog = new Animal(); dog.Sound="woof"; } } // this is error I get :× Close Execution time limit was exceeded Run-time exception (line -1): Execution time limit was exceeded Run-time exception (line -1): Execution time limit was exceeded Run-time exception (line -1): Execution time limit was exceeded
26th May 2017, 6:52 AM
Marlon
Marlon - avatar
+ 1
I have a similar code that runs I made two classes and use private, before the get and set. https://code.sololearn.com/cKz8Zy3CdaCA/?ref=app
26th May 2017, 7:10 AM
Manual
Manual - avatar
0
Maybe this way? Console.WriteLine("The dog says " + this.Sound);
26th May 2017, 5:16 AM
Álvaro
0
maybe this one using System; namespace SoloLearn { class Animal { public string sound; public string Sound{ get {return sound;} set {sound = value;} } public void Speak(){ Console.WriteLine("The dog says " + sound); } } class Program { static void Main(string[] args) { Animal a = new Animal (); a.Sound = "woof"; a.Speak(); } } }
2nd Jun 2017, 2:33 PM
Russel Pedrosa
Russel Pedrosa - avatar
0
Did you find the final solution?
7th Jul 2017, 12:37 PM
Max Efimenko
Max Efimenko - avatar
0
THIS IS THE ANSWER, IT WORKED FOR ME. PS: remember to use "Sound" with an uppercase S all through. if not, you won't pass it. using System; public class Animal { public string Sound { get{ return Sound;} set{ Sound = "woof";} } public void Speak() { Console.WriteLine("The dog says " + Sound); } } public class Program { public static void Main() { } }
21st Feb 2018, 3:31 AM
Gloraayy Yele
Gloraayy Yele - avatar
0
THIS IS THE ANSWER, IT WORKED FOR ME. PS: remember to use "Sound" with an uppercase S all through. if not, you won't pass it. using System; public class Animal { public string Sound { get{ return Sound;} set{ Sound = "woof";} } public void Speak() { Console.WriteLine("The dog says " + Sound); } } public class Program { public static void Main() { } }
21st Feb 2018, 3:31 AM
Gloraayy Yele
Gloraayy Yele - avatar
0
thank you. working fine
21st Feb 2018, 12:17 PM
Marlon
Marlon - avatar