|
Structural Design Patterns |
|
public void delete(String quest) {
questDB.deleteQuestion(quest);
}
public void display() {
questDB.displayQuestion();
}
public void displayAll() {
System.out.println(“Question Catalog: ” + catalog);
questDB.displayAllQuestions();
}
}
Develop another class QuestionFormat
extending the QuestionManager class
QuestionFormat.java
class QuestionFormat extends QuestionManager {
public QuestionFormat(String catalog){
super(catalog);
}
public void displayAll() {
System.out.println(“\n~~~~~~~~~~~~~”);
super.displayAll();
System.out.println(“~~~~~~~~~~~~~~~”);
}}
Develop another class JavaQuestions implementing the “Question” interface:
JavaQuestions.java:
import java.util.*;
class JavaQuestions implements Question {
private List <String> questions =
new ArrayList<String>();
private int current = 0;
public JavaQuestions() {
questions.add(“What is Java? ”);
questions.add(“What is marker interface? ”);
questions.add(“What is cross-platform? ”);
questions.add(“How multiple polymorphism i
s 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 multi-tasking? ”);
questions.add(“What is multi-threading? ”);
}
public void nextQuestion() {
if( current <= questions.size() - 1 )
current++;
}
public void priorQuestion() {
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);
}}
}
Develop another class TestBridge
TestBridge.java class TestBridge {
public static void main(String[] args) {
QuestionFormat questions =
new QuestionFormat(“Java Language”);
questions.questDB = new JavaQuestions(); |
|
Oct 2007 | Java Jazz Up | 52 |
|
|
Pages:
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,
Download PDF |
|
|
|
|
|
|
|
|
|