2017-09-08 7 views
-3

현재 dotnetacademy를 ​​통해 C#을 배우려고합니다. 최종 시험에서 나는 지침이 어디에 마지막 단계에 오전 :dotnetacademy 최종 시험 문제 C#

  1. 설문 조사 형식의 인스턴스를 선언하는 진입 점 방법을 수정하십시오. 선언 후 두 가지 텍스트 질문을 선택한 설문 조사에 추가하십시오.

  2. 다음으로 두 질문의 선언 후에 GetScore 메서드의 결과를 반환하는 새 로컬 선언을 만듭니다.

  3. 마지막으로 WriteLine을 사용하여 "Your score : {Score}"메시지를 콘솔에 인쇄하십시오. 여기서 {Score}는 설문 조사에서 얻은 점수입니다.

내가 점수를 인쇄 할 수 있기 때문에 내가 생각하는 마지막 두 단계를 완료하는 데 성공했다. 이 질문 유형의 질문 매개 변수를 필요로하기 때문에

using System; using System.Collections.Generic; public class Program { public static void Main(string [] args) { Survey survey = new Survey("Survey"); survey.Questions.AsReadOnly(); TextQuestion tq = new TextQuestion(); survey.AddQuestion((Question)tq.Ask()); int score = survey.GetScore(); Console.Write("Your score: {0}", score); } } public abstract class Answer { public int Score { get; set; } } public abstract class Question { public string Label { get; set; } protected abstract Answer CreateAnswer(string input); protected virtual void PrintQuestion() { Console.WriteLine(Label); } public Answer Ask() { PrintQuestion(); string input = Console.ReadLine(); return CreateAnswer(input); } } public class TextAnswer : Answer { public string Text { get; set; } } public class TextQuestion : Question { protected override Answer CreateAnswer(string input) { return new TextAnswer { Text = input, Score = input.Length }; } } public class Survey { public Survey(string title) { Title = title; Questions = new List<Question>(); } public string Title { get; set; } public List<Question> Questions { get; private set; } public void AddQuestion(Question question) { Questions.Add(question); } public int GetScore() { int total = 0; foreach (Question question in Questions) { Answer answer = question.Ask(); total = total + answer.Score; } return total; }

내가 설문 조사 인스턴스에 질문을 추가 할 수 없습니다 : I 단계 여기에 1

내 코드가 도움이 필요합니다. 어떤 제안?

그리고 마지막으로,이 운동에 대한 링크입니다 : Exercise

+0

은' ? 설문 조사 전에 – Sybren

+0

을 추가합니다 .AdQuest (tq) put tq.Ask(); – DanielVorph

+2

그 과정의 튜토리얼은 질문을 완료하기 위해해야 ​​할 일을 설명하고, 지금까지 배웠던 것을보고 조금 더 배우는 것처럼 보입니다. 시험에 도움이되도록 SO를 사용하지 마십시오. 학습 경험을 훼손시킬 수 있습니다. – Kodaloid

답변

0

지금 통과 너희들의 도움으로 :

public static void Main() 
{ 
    Survey survey = new Survey("Survey"); 
    Question tq1 = new TextQuestion(); 
    Question tq2 = new TextQuestion(); 
    tq1.Ask(); 
    tq2.Ask(); 
    survey.AddQuestion(tq1); 
    survey.AddQuestion(tq2); 

    int score = survey.GetScore(); 
    Console.WriteLine("Your score: {0}", score); 

} 

}`survey.AddQuestion (TQ)를 시도