Archive

Archive for the ‘QUIZZES’ Category

Quiz 7 Solutions

December 27, 2011 Leave a comment

You can download solutions from quiz7sol.

UML Diagram is given below.

Categories: QUIZ-7

Quiz 7 Questions

December 27, 2011 Leave a comment

Refactor the following code segment and then reverse engineer the UML diagram from refactored code:

public class Player {
String playerName;
String address;
List<MatchInfo> matchesPlayed;
int goals;
int goalsConceeded;
int goalsSaved;
// public getter and setter methods.
}

public class GoalKeeper {
String goalKeeperName;
String goalKeeperAddress;
List<MatchInfo> matchesPlayed;
int goals;
int goalsConceeded;
int goalsSaved;
int penaltiesSaved;
// public getter and setter methods.
}

public class Coach {
String coachName;
String coachAddress;
List<MatchInfo> matchesCoached;
// public getter and setter methods.
}

public class Team {
Coach teamCoach;
List<Player> playerList;
GoalKeeper firstGoalKeeper;
List<GoalKeeper> otherGoalKeepers;
// public getter and setter methods.
}

public MatchInfo {
Team homeTeam;
Team awayTeam;
int homeGoals;
int awayGoals;
// public getter and setter methods.
}

You can download questions from CS319_quiz.

Categories: QUIZ-7

Quiz 6 Solutions

December 12, 2011 Leave a comment

You can download solutions from: BILKENT-CS319-DesignPatternsQuiz6-111212(x)

True / False Questions (each 1 pt.)
1. A class diagram is a dynamic view of the classes in a system. (T / F) (False)
2. There are built-in classes in Java SE API such as java.util.Observable. (T / F) (True)
3. Subject and Observers are tightly coupled. (T / F) (False)

Fill in the Blanks Questions (each 2 pt.)
1. Add / remove listener methods in AbstractButton (JButton’s superclass) are an example of ________ pattern. (Observer)
2. Find the matching pattern for the following scenario: A top level component like a Frame or a Panel, contains other components like menus, text panes, scrollbars and buttons. You tell the top level component to display, and count on that component to display all its parts. ______ (Composite)
3. The java.io package is largely based on _______. (Decorator)
4. The _________ design pattern lets you attach responsibilities to objects at runtime. (Decorator)
5. _________ provides a unified interface to a set of interfaces in a subsystem. (Facade)
6. _________ defines a family of algorithms, encapsulates each one, and makes them interchangeable. (Strategy)
7. The usage area of this pattern is as follows: Thread pools, Objects that handle preferences and registry settings, objects used for logging, objects that act as device drivers. Find the pattern. _______ (Singleton)
Classic Questions (each 3 pt.)
1. Why is synchronized keyword used in this code example?
public class Singleton {
private static Singleton uniqueInstance;
private Singleton( ) { }
public static synchronized Singleton getInstance( ) {
if(uniqueInstance == null)
uniqueInstance = new singleton();
return uniqueInstance;
}
}
To solve multithreading problem. By adding synchronized to getInstance( ), we force every thread to wait its turn before it can enter the method. That is, no two threads may enter the method at the same time.

Categories: QUIZ-6

Quiz 6 Questions

December 12, 2011 Leave a comment

You can download questions from here: BILKENT-CS319-DesignPatternsQuiz6-111212

True / False Questions (each 1 pt.)
1. A class diagram is a dynamic view of the classes in a system. (T / F)
2. There are built-in classes in Java SE API such as java.util.Observable. (T / F)
3. Subject and Observers are tightly coupled. (T / F)

Fill in the Blanks Questions (each 2 pt.)
1. Add / remove listener methods in AbstractButton (JButton’s superclass) are an example of ________ pattern.
2. Find the matching pattern for the following scenario: A top level component like a Frame or a Panel, contains other components like menus, text panes, scrollbars and buttons. You tell the top level component to display, and count on that component to display all its parts. ______
3. The java.io package is largely based on _______.
4. The _________ design pattern lets you attach responsibilities to objects at runtime.
5. _________ provides a unified interface to a set of interfaces in a subsystem.
6. _________ defines a family of algorithms, encapsulates each one, and makes them interchangeable.
7. The usage area of this pattern is as follows: Thread pools, Objects that handle preferences and registry settings, objects used for logging, objects that act as device drivers. Find the pattern. _______

Classic Questions (each 3 pt.)
1. Why is synchronized keyword used in this code example?
public class Singleton {
private static Singleton uniqueInstance;
private Singleton( ) { }
public static synchronized Singleton getInstance( ) {
if(uniqueInstance == null)
uniqueInstance = new singleton();
return uniqueInstance;
}
}

 

Categories: QUIZ-6

Quiz 5 Solutions

December 5, 2011 Leave a comment

Categories: QUIZ-5