Exported from Notepad++
1 // Name: M Abdelaziz
2 // File: Questions.cs
3 // Purpose: All the methods that deal with questions other than output (creating, editing, deleting)
4
5 using System;
6 using System.Collections.Generic;
7 using System.Linq;
8 using System.Text;
9 using System.Threading.Tasks;
10
11 namespace CPSC1012_Advanced_Portfolio_mabdelaziz
12 {
13 class Questions
14 {
15 public static void Create(List<MultipleChoiceQuestion> questionsList)
16 {
17 // declare variables
18 string question;
19 string choice1;
20 string choice2;
21 string choice3;
22 string choice4;
23 char correctChoice;
24
25 // display what option we are in
26 Console.WriteLine("Multiple Choice Exam - New Question");
27 Console.WriteLine("-----------------------------------");
28 Console.WriteLine("There are currently {0} questions in the exam. \n", questionsList.Count);
29
30 if (questionsList.Count > 30)
31 {
32 Console.WriteLine("The exam is at the maximum of 30 questions");
33 }
34 else
35 {
36 // ask for and capture components
37 Console.WriteLine("Enter the question:");
38 question = Console.ReadLine();
39 Console.WriteLine("Enter choice 1 for the question:");
40 choice1 = Console.ReadLine();
41 Console.WriteLine("Enter choice 2 for the question:");
42 choice2 = Console.ReadLine();
43 Console.WriteLine("Enter choice 3 for the question:");
44 choice3 = Console.ReadLine();
45 Console.WriteLine("Enter choice 4 for the question:");
46 choice4 = Console.ReadLine();
47 Console.WriteLine("Enter the correct choice (A, B, C, D):");
48 correctChoice = InputOutput.GetQuestionChoice("Enter the correct choice (A, B, C, D):\n");
49
50 // add components to new object in list
51 questionsList.Add(new MultipleChoiceQuestion(question, choice1, choice2, choice3, choice4, correctChoice));
52 Console.WriteLine("Successfully added question {0} to the exam.", questionsList.Count);
53 }
54
55 Console.Write("Press any key to continue. ");
56 Console.ReadKey();
57 }
58
59 public static void Delete(List<MultipleChoiceQuestion> questionsList)
60 {
61 // declare variables
62 int questionNumber;
63 char confirmation;
64
65 // display what option we are in
66 Console.WriteLine("Multiple Choice Exam - Delete Question");
67 Console.WriteLine("--------------------------------------");
68
69 // ask for and capture question to delete
70 Console.WriteLine("Enter the question number to delete:");
71 questionNumber = int.Parse(Console.ReadLine());
72 int index = questionNumber - 1;
73
74 // check if question number is valid
75 // if valid
76 if (questionNumber <= questionsList.Count && questionNumber > 0)
77 {
78 Console.WriteLine("Found the following question:");
79
80 // display question
81 Console.WriteLine("Question {0}: ", questionNumber);
82 Console.WriteLine("------------------------------");
83 Console.WriteLine("{0} \n{1} \n{2} \n{3} \n{4} \n",
84 questionsList[index].Question,
85 questionsList[index].Choice1,
86 questionsList[index].Choice2,
87 questionsList[index].Choice3,
88 questionsList[index].Choice4);
89
90 // ask for confirmation
91 Console.WriteLine("Are you sure you want to delete question {0} (y/n)?", questionNumber);
92 confirmation = char.Parse(Console.ReadLine());
93
94 if (confirmation == 'y')
95 {
96 // delete question
97 questionsList.RemoveAt(index);
98 Console.WriteLine("Successfully deleted question {0}", questionNumber);
99 }
100 else
101 {
102 // tell them question was not deleted
103 Console.WriteLine("Question {0} was not deleted. ", questionNumber);
104 }
105 }
106 // if not valid
107 else
108 {
109 Console.WriteLine("Error! {0} is not a valid question number.", questionNumber);
110 }
111
112 Console.Write("Press any key to continue. ");
113 Console.ReadKey();
114 }
115
116 public static void Edit(List<MultipleChoiceQuestion> questionsList)
117 {
118 // declare variables
119 int questionNumber;
120 string question;
121 string choice1;
122 string choice2;
123 string choice3;
124 string choice4;
125 char correctChoice;
126
127 // display what option we are in
128 Console.WriteLine("Multiple Choice Exam - Edit Question");
129 Console.WriteLine("------------------------------------");
130
131 // ask for and capture question to delete
132 Console.WriteLine("Enter the question number to Edit:");
133 questionNumber = int.Parse(Console.ReadLine());
134 int index = questionNumber - 1;
135
136 // check if question number is valid
137 // if valid
138 if (questionNumber <= questionsList.Count && questionNumber > 0)
139 {
140 Console.WriteLine("The question is as follows:");
141
142 // display question
143 Console.WriteLine("Question {0}: ", questionNumber);
144 Console.WriteLine("------------------------------");
145 Console.WriteLine("{0} \nA. {1} \nB. {2} \nC. {3} \nD. {4} \n",
146 questionsList[index].Question,
147 questionsList[index].Choice1,
148 questionsList[index].Choice2,
149 questionsList[index].Choice3,
150 questionsList[index].Choice4);
151
152 // ask for and capture components
153 Console.WriteLine("Enter the question:");
154 question = Console.ReadLine();
155 Console.WriteLine("Enter choice 1 for the question:");
156 choice1 = Console.ReadLine();
157 Console.WriteLine("Enter choice 2 for the question:");
158 choice2 = Console.ReadLine();
159 Console.WriteLine("Enter choice 3 for the question:");
160 choice3 = Console.ReadLine();
161 Console.WriteLine("Enter choice 4 for the question:");
162 choice4 = Console.ReadLine();
163 Console.WriteLine("Enter the correct choice (A, B, C, D):");
164 correctChoice = InputOutput.GetQuestionChoice("Enter the correct choice (A, B, C, D):\n");
165
166 // replace list entry at index
167 questionsList.RemoveAt(index);
168 questionsList.Insert(index, new MultipleChoiceQuestion(question, choice1, choice2, choice3, choice4, correctChoice));
169
170 Console.WriteLine("Successfully updated question {0}", questionNumber);
171 }
172 // if not valid
173 else
174 {
175 Console.WriteLine("Error! {0} is not a valid question number.", questionNumber);
176 }
177
178 Console.Write("Press any key to continue. ");
179 Console.ReadKey();
180
181 }
182
183 }
184 }
185