public GUI() { // make UI controls part of the window this.Controls.Add(statement); this.Controls.Add(op1); this.Controls.Add(op2); this.Controls.Add(op3); this.Controls.Add(op4); this.Controls.Add(next); this.Controls.Add(previous); statement.Location = new Point(10, 10); op1.Location = new Point(10, 50); op2.Location = new Point(10, 90); op3.Location = new Point(10, 130); op4.Location = new Point(10, 170); next.Location = new Point(10, 210); previous.Location = new Point(100, 210); next.Text = "Next"; previous.Text = "Previous"; next.Click += NextButtonClicked; // registering the event handler // so that the event handler gets called when button is clicked previous.Click += PreviousButtonClicked; // registering the event handler // so that the event handler gets called when button is clicked Question question = tl.GetNextQuestion(); DisplayQuestion(question); }
public void StartTest() { TestLogic tl = new TestLogic(); while (true) { Question question = tl.GetNextQuestion(); if (question == null) { break; // test is over } // Display one question at a time Console.Clear(); Console.WriteLine(question.Statement); Console.WriteLine("1: " + question.Op1); Console.WriteLine("2: " + question.Op2); Console.WriteLine("3: " + question.Op3); Console.WriteLine("4: " + question.Op4); // take the user's choice Console.Write("Select an option: "); int choice = Convert.ToInt32(Console.ReadLine()); tl.CalculateUserMarks(choice); } // finally display usermarks out of total marks Console.Clear(); Console.WriteLine("You obtained {0} out of {1}", tl.GetUserMarks(), tl.GetTotalMarks()); }
public void Show() { Console.WriteLine("Please wait while we load the questions from the server...."); TestLogic testLogic = new TestLogic(); // long lived object // 1. Object is created with instance data members in it // 2. constructor is called with the ref. of the object // 3. reference of the object is stored in testLogic reference variable while (true) { Question question = testLogic.GetNextQuestion(); // question is a reference variable that receives reference of the Question object if (question != null) { Console.Clear(); DisplayQuestion(question); int option = this.GetOptionFromUser(); testLogic.CheckAnswer(option); } else { break; } } Console.Clear(); Console.WriteLine($"You obtained {testLogic.UserMarks} out of {testLogic.TotalMarks}"); Console.ReadLine(); }
// NO instance Data Members public void Start(/*ConsoleUI this = referance of calling object */) { TestLogic logic = new TestLogic(); while (true) { Question question = logic.GetNextQuestion(); if (question == null) { break; } Console.WriteLine($"Statement : {question.Statement}"); Console.WriteLine($"Option1 : {question.Option1}"); Console.WriteLine($"Option2 : {question.Option2}"); Console.WriteLine($"Option3 : {question.Option3}"); Console.WriteLine($"Option4 : {question.Option4}"); } }
public void Show() { TestLogic testLogic = new TestLogic(); while (true) { Question question = testLogic.GetNextQuestion(); if (question != null) { Console.WriteLine(question.Statement); Console.WriteLine(question.Option1); Console.WriteLine(question.Option2); Console.WriteLine(question.Option3); Console.WriteLine(question.Option4); } else { break; } } }