-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathNavigationFromOneQuestionToAnother.java
More file actions
125 lines (95 loc) · 2.79 KB
/
NavigationFromOneQuestionToAnother.java
File metadata and controls
125 lines (95 loc) · 2.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
package Solutions;
import java.util.ArrayList;
import java.util.List;
interface Question {
public void nextQuestion();
public void previousQuestion();
public void newQuestion(String q);
public void deleteQuestion(String q);
public void displayQuestion();
public void displayAllQuestions();
}
class JavaQuestions implements Question {
private List<String> questions = new ArrayList<String>();
private int current = 0;
public JavaQuestions() {
questions.add("What is class? ");
questions.add("What is interface? ");
questions.add("What is abstraction? ");
questions.add("How multiple polymorphism is achieved in java? ");
questions.add("How many types of exception handling are there in java? ");
questions.add("Define the keyword final for variable, method, and class in java? ");
questions.add("What is abstract class? ");
questions.add("What is multi-threading? ");
}
public void nextQuestion() {
if (current <= questions.size() - 1)
current++;
System.out.print(current);
}
public void previousQuestion() {
if (current > 0)
current--;
}
public void newQuestion(String quest) {
questions.add(quest);
}
public void deleteQuestion(String quest) {
questions.remove(quest);
}
public void displayQuestion() {
System.out.println(questions.get(current));
}
public void displayAllQuestions() {
for (String quest : questions) {
System.out.println(quest);
}
}
}
class QuestionManager {
protected Question q;
public String catalog;
public QuestionManager(String catalog) {
this.catalog = catalog;
}
public void next() {
q.nextQuestion();
}
public void previous() {
q.previousQuestion();
}
public void newOne(String quest) {
q.newQuestion(quest);
}
public void delete(String quest) {
q.deleteQuestion(quest);
}
public void display() {
q.displayQuestion();
}
public void displayAll() {
System.out.println("Question Paper: " + catalog);
q.displayAllQuestions();
}
}
class QuestionFormat extends QuestionManager {
public QuestionFormat(String catalog) {
super(catalog);
}
public void displayAll() {
System.out.println("\n---------------------------------------------------------");
super.displayAll();
System.out.println("-----------------------------------------------------------");
}
}
public class NavigationFromOneQuestionToAnother {
public static void main(String[] args) {
QuestionFormat questions = new QuestionFormat("Java Programming Language");
questions.q = new JavaQuestions();
questions.delete("what is class?");
questions.display();
questions.newOne("What is inheritance? ");
questions.newOne("How many types of inheritance are there in java?");
questions.displayAll();
}
}