swaysteady
swaysteady
CC#
Created by swaysteady on 1/18/2025 in #help
Defining a protected method with a single call. Failing verification and I can't figure out why
Instructions Please define a public class named Question. This class should be abstract as it will be inherited by other classes. The Question class should have an automatic public property called Label which should be a string. The Label property must have both a getter and a setter. The Question class should define a protected method named CreateAnswer that has a single string parameter. This method should be abstract so should not have an implementation within this class. The method must return an instance of Answer. The input parameter must be named input and represents the user's response from the question. The Question class should define a protected method named PrintQuestion that by default will write Label property value to the Console using WriteLine. It must be possible to override this method in any inherited classes. The Question class should also define a public method named Ask which will first print the question. It will then collect the next line from Console using ReadLine and create an answer by returning the value of the CreateAnswer method, using the collected input. The answer must then be returned as the return value of the Ask method. [part 3/3]
4 replies
CC#
Created by swaysteady on 1/18/2025 in #help
Defining a protected method with a single call. Failing verification and I can't figure out why
My submission is below and the instructions are below that, with the relevant paragraph in bold. I'm sure I'm missing something basic, can you help train my beginner eye and point me to where I'm going wrong? Thank you! My Submission
using System;
using System.Collections.Generic;

public class Program
{
public static void Main()
{

}
}

public abstract class Answer
{
public int Score { get; set; }
}

// Your code here.
public abstract class Question
{
public string Label { get; set; }

abstract protected Answer CreateAnswer ( string input );

protected virtual void PrintQuestion ()
{
Console.WriteLine( this.Label );
}

public Answer Ask ( ) {
Console.WriteLine( this.Label );
string response = Console.ReadLine();
Answer answer = this.CreateAnswer(response);
return answer;
}
}
using System;
using System.Collections.Generic;

public class Program
{
public static void Main()
{

}
}

public abstract class Answer
{
public int Score { get; set; }
}

// Your code here.
public abstract class Question
{
public string Label { get; set; }

abstract protected Answer CreateAnswer ( string input );

protected virtual void PrintQuestion ()
{
Console.WriteLine( this.Label );
}

public Answer Ask ( ) {
Console.WriteLine( this.Label );
string response = Console.ReadLine();
Answer answer = this.CreateAnswer(response);
return answer;
}
}
[part 2/3]
4 replies
CC#
Created by swaysteady on 1/5/2025 in #help
C# fiddle space in Visual Studio
Great leads, thank you both!
9 replies
CC#
Created by swaysteady on 1/5/2025 in #help
C# fiddle space in Visual Studio
Awesome. thank you, @Sehra !
9 replies
CC#
Created by swaysteady on 8/6/2024 in #help
What's this syntax in this object instantiation
That got me right to the microsoft learn page I need to read. Thank you!
6 replies