0% found this document useful (0 votes)
429 views82 pages

Week Wise Solutions

The document contains multiple-choice questions related to Object Oriented System Development using UML, Java, and design patterns, specifically focusing on use case modeling and class diagrams. Each question includes a correct answer and a detailed explanation of the reasoning behind it. The document is structured into three assignments, each consisting of 10 questions, covering various concepts in software design and UML representation.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
429 views82 pages

Week Wise Solutions

The document contains multiple-choice questions related to Object Oriented System Development using UML, Java, and design patterns, specifically focusing on use case modeling and class diagrams. Each question includes a correct answer and a detailed explanation of the reasoning behind it. The document is structured into three assignments, each consisting of 10 questions, covering various concepts in software design and UML representation.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 82

NPTEL Online Certification Courses

Indian Institute of Technology Kharagpur

Object Oriented System Development Using UML, Java and Patterns


Assignment- 1
TYPE OF QUESTION: MCQ/MSQ
Number of questions: 10 Total mark: 10 X 1 = 10

For each of the following questions one or more of the given options are correct. Choose the
correct options.

QUESTION 1:
Consider the following part of a use case model.

Which one of the following can be inferred from the given diagram?
a. Lookup Catalog use case may be optionally executed during execution of Place Order
use case
b. Use case Place Order may be optionally executed during execution of use case Lookup
Catalog
c. Use case Lookup Catalog will be compulsorily executed during execution of use case
Place Order
d. Use case Place Order will be compulsorily executed during execution of use case Lookup
Catalog
e. Use case Lookup Catalog is derived from the use case Place Order

Correct Answer: a. Lookup Catalog use case may be optionally executed during execution of Place
Order use case
Detailed Solution:

Here Place Order use case extend Lookup catalog use case. So, Lookup Catalog use case may be
optionally executed during execution of Place Order use case
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

QUESTION 2:
Which of the following are correct statements about a use case?
a. It is a way in which a system can be used by the users to achieve specific goals
b. It corresponds to a non-functional requirement.
c. It defines external behavior without revealing internal structure of system
d. It is a set of related usage scenarios tied together by a common goal
e. It is one scenario of use of the system

Correct Answer: a. It is a way in which a system can be used by the users to achieve specific
goals
c. It defines external behavior without revealing internal structure of system
d. It is a set of related usage scenarios tied together by a common goal
Detailed Solution:
Use cases does not correspond to a non-functional requirement. Also, Use case does not depict any
scenario of use of the system.

QUESTION 3:
Identification of the different categories of users of a system in its use case diagram does not help
towards which of the following?
a. Design of user interface
b. Design of entity classes
c. Design of security and authentication mechanism
d. Design of back-end processing of the system
e. Design of suitable user manuals
f. Design of controller classes

Correct Answer: b. Design of entity classes


f. Design of controller classes
Detailed Solution:
Identification of the different categories of users in a use case does not help in design of entity
classes and design of controller classes.
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

QUESTION 4:
A library automation software is to be designed. Before a book can be issued to a member, it needs
to be checked whether the member has cleared all past dues. Which one of the following
mechanisms is most appropriate to factor the issue book use case into reserve book and check
pending dues use cases?
a. Inheritance
b. Dependency
c. Include
d. Extend
e. Aggregation

Correct Answer: c. Include

Detailed Solution:
Here, reserve book and check pending dues use cases are common use cases whereas issue book is a
base use case that includes the common use cases.

QUESTION 5:
How should an external system be represented in a use case diagram?
a. Using a specific icon available for this purpose
b. Using text description
c. By subclassing the actor icon
d. Using object constraint language (OCL)
e. By stereotyping the actor icon

Correct Answer: e. By stereotyping the actor icon

Detailed Solution:
An external system is represented by stereotyping the actor icon.
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

QUESTION 6:
Which of the following styles of documenting a Use case diagram are not recommended?
a. A use case name should begin with a noun
b. An actor should be associated with exactly one use cases
c. Actors are associated with one or more use cases
d. Use arrows to represent the actor-use case relationship
e. Show interaction of actors with each other.

Correct Answer: a. A use case name should begin with a noun,


b. An actor should be associated with exactly one use cases,
d. Use arrows to represent the actor-use case relationship,
e. Show interactions of actors with each other.
Detailed Solution:
There is no certain rules to use noun in use case name. Actors can be associated with more than one
use cases. Arrows as well as interaction of actors not allowed in use case.
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

QUESTION 7:
Suppose in a course management software, a student during registration can request the course
list to be displayed if he/she needs to consult the course list before making a decision about a
course to register. Which one of the following use cases, correctly models this?

a. A
b. B
c. C
d. D

Correct Answer: a. A
Detailed Solution:
Figure A represents the given description. Here, See Course List is a common use case and Register
course is a base use case.
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

QUESTION 8:
Consider the following use case model. Which of the following statements concerning the model
can be inferred from it?

a. Issue book use case implicitly invokes Check reservation use case
b. Issue book use case invokes Check reservation use case only if some conditions
are satisfied
c. Issue book and Renew book use cases are inter dependent
d. This factorization helps in reducing the duplication in the implementation
e. The factorization helps in reducing the runtime complexity of the two use cases
Correct Answer: a. Issue Book use case implicitly invokes Check reservation use case
. d. This factorization helps in reducing the duplication in the
implementation
Detailed Solution:
Here, Issue Book and Renew Book implicitly invokes Check Reservation use case this help to implement
check reservation only one time. So, it reduces the duplication in the implementation.

QUESTION 9:
The line connecting an actor (user) to a use case in an UML use case diagram represents which of
the following?
a. Association relationship
b. Control flow relationship
c. Dependency relationship
d. Composition relationship
e. Data flow relationship
Correct Answer: a. Association relationship
Detailed Solution:
The line connection an actor to a use case in an UML use case diagram represents Association
relationship
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

QUESTION 10:

Which of the following are not mechanisms supported in UML to factor a complex use case into
simpler use cases?
a. Generalization-specialization
b. Include
c. Composition
d. Extend
e. Dependency

Correct Answer: c. Composition,


e. Dependency
Detailed Solution:

Complex use cases need to be factored into simpler use cases. Three ways of factoring:
− Generalization
− Include
− Extend
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

Object Oriented System Development Using UML, Java and Patterns


Assignment- 2
TYPE OF QUESTION: MCQ/MSQ
Number of questions: 10 Total mark: 10 X 1 = 10

For each of the following questions one or more of the given options are correct. Choose the
correct options.

QUESTION 1:
A student has many student friends. What can be said about the class relation in the description.
a. Unary relation
b. Binary relation
c. Ternary relation
d. Quaternary relation

Correct Answer: a. Unary relation


Detailed Solution:
Here a Student class is associated with itself. So, it’s a Unary relation.

QUESTION 2:
Which of the followings can be inferred from the following UML class diagram?

a. A PetOwner owns at most 1 Pet


b. Each pet has exactly one PetOwner
c. 1 pet is owned by many PetOwners
d. Many pets are owned by many PetOwners
e. Many petOwners own 1 or more Pets
Correct Answer: a. A petOwner owns at most 1 pet
b. Each pet has exactly one PetOwner

Detailed Solution:
From the class diagram it can be inferred that A PetOwner owns at most 1 pet and if there is a pet
then there is exactly one owner for that pet.
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

QUESTION 3:
Which one of the following UML class diagrams most accurately models: “A person keeps many
animals as pets. But, an animal is owned by a single person.”

a. A
b. B
c. C
d. D
e. Both C and D

Correct Answer: a. A

Detailed Solution:

A person keeps many animals as pets. But, an animal is owned by a single person is correctly depicted
by figure A of the above diagram.

QUESTION 4:
Which of the following is implied by the class diagram given below?

a. Neither a Door object nor a Key object store attributes of each other
b. Either of a Door object or a Key object store attributes of the other
c. A reference of a Door object is stored as an attribute of a Key object and also a reference of
a Key object is stored as an attribute of a Door object
d. A reference of a Door object is stored as an attribute of a Key object
e. A reference of a Key object is stored as an attribute of a Door object

Correct Answer: d. A reference of a Door object is stored as an attribute of a key object


Detailed Solution:
Here, an arrow direction given from ‘Key’ class to ‘Door’ class that means a reference of a door object
is stored as an attribute of a key object..
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

QUESTION 5:
Which one of the following phrases indicates the relationship that exists between a class and its
public parent class?
a. "...is a..."
b. "...has a..."
c. "...is implemented as a..."
d. "...uses a..."
e. “…implementation of…”
Correct Answer:
a. “…is a….”
Detailed Solution:
Here child and parent class relationship which is inheritance relationship also called is a
relationship.

QUESTION 6:
Which of the following aspects is not part of a class diagram design?
a. Attributes with their types
b. Operations with arguments and results
c. Composition relationship
d. Events and actions
e. Visibility information
f. Navigation information

Correct Answer: d. Events and actions

Detailed Solution:
Events and actions are part of a state chart diagram. Its not part of class diagram.
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

QUESTION 7:
Which one of the following terms is a measure of the number links of an object with another object?
a. Stereotype
b. Cardinality
c. Numericity
d. Linkedness
e. Coupling

Correct Answer: b. Cardinality


Detailed Solution:
Cardinality is a measure of the number of links of an object with another object.

QUESTION 8:
Which of the followings are implied by the class diagram given below?

a. Many keys open up to five doors


b. Many doors are opened by a key
c. A Key object stores reference of up to 5 Door objects
d. A door is opened by up to 5 keys
e. A Door object stored reference of at least one Key object
f. A key opens up to 5 doors

Correct Answer: c. A key object stores reference of up to 5 Door objects


f. A key opens up to 5 doors
Detailed Solution:
Left to right read: A key opens 0 to 5 doors.
So, A key opens up to 5 doors is the right option. Also, a Key object stores reference of up to 5 Door
objects.
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

QUESTION 9:
Which of the following characterize the inheritance relation between two classes?
a. Encapsulation.
b. Aggregation
c. Generalization and specialization.
d. Polymorphism
e. “Has a” relation
f. “Is a” relation
g. Composition

Correct Answer: c. Generalization and specialization


f. “Is a” relation

Detailed Solution:

Inheritance relation between two classes refer Generalization-specialization and “Is a” relation.
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

QUESTION 10:
Which of the following is NOT implied by the class diagram given below?

a. A key opens up to 5 doors


b. A door is opened by up to 2 key
c. A door is opened by up to 5 keys
d. A door is opened by at least one key
e. A key opens at least one door
f. Some keys open 2 doors only

Correct Answer: c. A door is opened up to 5 keys

Detailed Solution:

Here, A Door is opened up to 2 keys. So, option c. is not true.


NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

Object Oriented System Development Using UML, Java and Patterns


Assignment- 3
TYPE OF QUESTION: MCQ/MSQ
Number of questions: 10 Total mark: 10 X 1 = 10

For each of the following questions one or more of the given options are correct. Choose the
correct options.
QUESTION 1:
Consider the following Java code:
class Student {
class Enrollment {
String name;
Student student;
public Student(String name) { Course course;
this.name = name; String grade;
}
} public Enrollment(Student student, Course course) {
this.student = student;
class Course { this.course = course;
String name; }
public Course(String name) { }
this.name = name;
}
}
Which one of the following class diagrams most accurately corresponds to the given Java
code?

a) A
b) B
c) C
d) D
e) E
f) F
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

Correct Answer: a) A

Detailed Solution:
From the given code, Student and course has single object. Arraylist not used for both the class.
So, option a. is correct.
QUESTION 2:
Consider the following Java code.

Which one of the following class diagrams is equivalent to the given Java code?

a. A
b. B
c. C
d. D
e. Both C and D
Correct Answer: a. A
Detailed Solution:
From the given java code, we can observe there exist up to one player for each instance of nickname
in League class. So, among all the given class diagram, class diagram A is equivalent to the given java
code.
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

QUESTION 3:
A sentence taken from the user story in the development of an ERP system for an university is
the following: “Many professors work for the university.” From this sentence, which one of
the following relationships between the Professor class and University class can be inferred?
a. Inheritance
b. Aggregation
c. Composition
d. Dependency
e. Unary association

Correct Answer: b. Aggregation

Detailed Solution:
Among all the options Aggregation is the most suitable for the given scenario.

QUESTION 4:
Consider the statement: “A file is either an ordinary file or a directory file.” From this sentence,
which one of the following relationships between the File class and Ordinary file class can be
inferred?
a) Inheritance
b) Aggregation
c) Composition
d) Dependency
e) Association

Correct Answer: a. Inheritance

Detailed Solution:
“A file is either an ordinary file or a directory file.” – here file is the parent class and ordinary file
and a directory file are the child class. So, the relationship is inheritance here.
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

QUESTION 5:
Consider the following sentence: “A square is a polygon”. From an analysis of the sentence, identify
the relation between the two classes Square and Polygon, that can be inferred from the sentence.
a. Inheritance
b. Association
c. Aggregation
d. Composition
e. Dependency

Correct Answer: a. Inheritance


Detailed Solution:
Here is a relationship implied. So, the correct option is inheritance.

QUESTION 6:
Consider the statement: "An employee is either a worker or a manager." Assuming that Employee
and Manager to be two classes, what can be said about the relationship between these two classes?
a. Association
b. Generalization-specialization
c. Aggregation
d. Polymorphism
e. Composition

Correct Answer: b. Generalization-specialization


Detailed Solution:
An employee could be a worker or a manager. So, the relationship is Generalization-specialization.
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

QUESTION 7:
Consider the following Java code.

Which one of the following class diagrams corresponds to the given code.

a. A
b. B
c. C
d. D
e. Both A and D

Correct Answer: a. A
Detailed Solution:
Figure A represents the give code segment. From the given code it can be inferred that a person has
either one account or multiple accounts.
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

QUESTION 8:
Consider the following class diagram depicting the skills acquired by a person, and the competency level for
each skill acquired.

Given that there are 100 person objects and 10 skill objects, at most how many competency objects
may exist?
a. 30
b. 100
c. 150
d. 300
e. 1000

Correct Answer: d.300

Detailed Solution:

For every person-skill link, there a competency object. From the class diagram, we can observe that
each person may be link with at most 3 skills. So, if we want to calculate maximum possible
competency objects then we have to take 3 skills objects for each person object. So, maximum
possible competency objects = 100 * 3 =300.
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

QUESTION 9:
Consider the following class diagram.

Which of the following are implied by the class diagram?


a. There exists up to one Student object for each instance of Roll in the Class.
b. There exists up to one Roll for each instance of Student in the Class.
c. Each Student object is associated with one Class object.
d. Many Student objects are associated with one Class object.
e. Each Student object contains at most one Class object.

Correct Answer: a. There exists up to one Student object for each instance of Roll in the class
d. Many student objects are associated with one class object

Detailed Solution:
The class diagram is an example of qualified association. The class diagram implied “There exist up to
one student for each instance of roll in the class”.

QUESTION 10:
Consider that an educational institute assigns unique roll number to its students. Which one
of the following class diagrams most accurately captures this?

a. A
b. B
c. C
d. D
e. Both C and D

Correct Answer: a. A
Detailed Solution:
The class diagram is an example of qualified association. The class diagram implied “an educational
institute assigns unique roll number to its students”.

************END***********
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

Object Oriented System Development Using UML, Java and Patterns


Assignment- 4
TYPE OF QUESTION: MCQ/MSQ
Number of questions: 10 Total mark: 10 X 1 = 10

For each of the following questions one or more of the given options are correct. Choose the
correct options.

QUESTION 1:
Which of the following are not factors behind the use of abstract classes in object-oriented
designs?
a. Reduced design complexity
b. Enhanced design and code understandability
c. Reduced code size
d. Reduced number of objects
e. Increased efficiency of executable code

Correct Answer: d.Reduced number of objects


e. Increased efficiency of executable code
Detailed Solution:

Abstract class Reduces complexity of design, enhances understandability, increases productivity,


reduces code size.
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

QUESTION 2:
Consider the following sentence: “A library member can borrow upto five books”. From an analysis
of the sentence, identify the classes and relation between the LibraryMember and the Book classes.
a. Inheritance
b. Association
c. Aggregation
d. Composition
e. Dependency

Correct Answer: b. Association

Detailed Solution:

Association represents a general relationship between two classes, where one class (in this case,
LibraryMember) is connected to another (Book) but neither class depends on the lifecycle of the other.

QUESTION 3:
Which one of the following mechanisms is deployed by a state chart to overcome the state
explosion problem inherent to the finite state machine formalism?
a. Composite states
b. History states
c. Guards on transitions
d. Pseudo transitions
e. Pseudo initial state

Correct Answer: a. Composite states

Detailed Solution:
State explosion problem can be solved by composite state. Please refer slide no. 51 of week 4
lecture material.
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

QUESTION 4:
Method overloading can be considered to be a form of which one of the following mechanisms?
a. Static polymorphism
b. Dynamic polymorphism
c. Interface implementation
d. Encapsulation
e. Inheritance

Correct Answer: a. Static Polymorphism

Detailed Solution:
Method overloading is an example of static binding. Please refer slide no. 21 to 23 of week 3
lecture material

QUESTION 5:
Which one of the following can be said of the method create in the following Java code?

a. Overridden method
b. Overloaded method
c. Dynamically bound method
d. Inherited method
e. Dependent method
Correct Answer: b. Overloaded method
Detailed Solution:
Here, class circle has three definition of create method. Each one is defined with different number of
arguments. So, we can say create is a overloaded method.
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

QUESTION 6:
A state machine diagram is typically used to model the behavior of which one of the following?
a. Class
b. Method
c. System
d. Package
e. Class relations

Correct Answer: a. Class


Detailed Solution:
State machine diagrams are used for modeling class objects with complex state-dependent
behavior.

QUESTION 7:
A car has a Starter switch, two head lights, an Air Conditioning System, and an accelerator pedal.
The driver first operates the Starter, then switches on the Lights, then the Air Conditioning System,
and finally presses the accelerator pedal. Which pair of diagrams is most useful to model this
situation?
a. Use case diagram and state machine diagram
b. Use case diagram and class diagram
c. Class diagram and sequence diagram
d. Class and state machine diagrams
e. Sequence diagram and state machine diagram

Correct Answer: c. Class diagram and sequence diagram


Detailed Solution:
Here, class diagram is required to represent class relationship. From the question statement we
can observe that the driver operates all the components in a time ordering manner. To represent
time ordering, sequence diagram is the best fit here.
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

QUESTION 8:
If a class has 5 state variables, and each of state variable can assume 4 discrete values, what is the
maximum number states that an object of the class can assume?
a. 5
b. 20
c. 525
d. 625
e. 1024
Correct Answer: e. 1024
Detailed Solution:
Number of states exponentially rises with state variable. Here, 5 state variables, and each of state variable
can assume 4 discrete values. So, the maximum number of possible states = 45 = 1024.

QUESTION 9:
Consider the following state chart diagram modelling the behaviour of a turnstile gate. Based on
the modelled behaviour, what would happen if a coin is inserted into the turnstile gate when the
turnstile gate is in the unlocked state?

a. The turnstile gate allows one person to pass and remains in the unlocked state
b. The turnstile gate sounds an alarm and remains in the unlocked state
c. The turnstile gate remains in the unlocked state
d. The turnstile gate returns the coin and remains in the unlocked state
e. The turnstile gate returns the coin and becomes locked
f. The turnstile gate becomes locked

Correct Answer: d. The turnstile gate returns the coin and remains in the unlocked state
Detailed Solution:
From the state chart diagram it is clearly visible that The turnstile gate returns the coin and remains
in the unlocked state.
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

QUESTION 10:

Which of the following features of the state chart model are primarily responsible towards reduced
number of states in the finite state modelling of a given problem?
a. Nested states
b. Concurrent states
c. History state
d. Broadcast messages
e. Actions on state entry and exit

Correct Answer: a. Nested states


b. Concurrent states

Detailed Solution:

These two major features Nested states and concurrent states are introduced for controlling
complexity and combinatorial explosion in state diagrams.

************END***********
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

Object Oriented System Development Using UML, Java and Patterns


Assignment- 5
TYPE OF QUESTION: MCQ/MSQ
Number of questions: 10 Total mark: 10 X 1 = 10

For each of the following questions one or more of the given options are correct. Choose the
correct options.

QUESTION 1:
Suppose the objects of a class display non-trivial state behavior. The class has three state
variables that assume 2, 3, and 4 discrete values. What is the number of states that an object
of the class can assume?
a. 24
b. 128
c. 256
d. 512
e. 1024

Correct Answer: a.24

Detailed Solution:
Three state variables that assume 2,3, and 4 discrete values. So, the answer is = 2*3*4=24.
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

QUESTION 2:
Consider the following sequence diagram.

Which methods should be provided in the class Y?


a. Both doB() and doE()
b. Only doB()
c. Only doE()
d. Both doA() and doD()
e. Only doD()

Correct Answer: a. Both doB() and doE()

Detailed Solution:

Based on the above diagram, ‘ON’ is a superstate and ‘idle ’ is a default state.
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

QUESTION 3:
In a State Diagram, which of the following are true?
a. Actions are associated with a transition and are considered to be processes that occur
quickly and are not interruptible
b. Actions are associated with transition and are considered to be processes that occur
quickly and are interruptible
c. Activities are associated with states and can take longer. An activity may be
interrupted by some event
d. Activities are associated with transition that occur quickly and are not interruptible
e. Activities are associated with states and can take longer. An activity cannot be interrupted by
any event

Correct Answer: a. Actions are associated with a transition and are considered to be processes
that occur quickly and are not interruptible
c. Activities are associated with states and can take longer. An activity may
be interrupted by some event

Detailed Solution:
Actions are associated with transitions and are considered to be processes that occur quickly and are
not interruptible. Activities are associated with states and can take longer. An activity may be
interrupted by some event.
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

QUESTION 4:
Consider the following state machine diagram that models the state behavior of the
RobotController class.

Which one of the following most accurately states the initial starting state of a RobotController?
a. Walk and forward
b. Walk and backward
c. Run and forward
d. Run and backward
e. Walk
f. Forward

Correct Answer: a. Walk and forward

Detailed Solution:
The given state machine diagram is a concurrent state machine diagram. We can observe from the
diagram that both walk and forward is the initial starting state of the RobotController.

QUESTION 5:
Consider the following state machine diagram that models the state behavior of the
RobotController class.

Which one of the following is an infeasible state for a RobotController?


a. Walk and forward
b. Walk and Run
c. Run and forward
d. Run and backward
e. Walk and Backward

Correct Answer: b. Walk and Run

Detailed Solution:
Walk and Run is an infeasible state for the RobotController
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

QUESTION 6:
Which one of the following best characterizes a sequence diagram?

a. A call graph illustrating all possible sequences of calls between class method members
b. A typical sequence of calls occurring among methods of various objects on a time-line
c. A typical sequence of method calls occurring on an object over its life time
d. A typical sequence of changes occurring to the inheritance and association relationships
among classes on a time line
e. A tree illustrating inheritance relationship existing among various classes

Correct Answer: b. A typical sequence of calls occurring among methods of various objects on a
time-line
Detailed Solution:
Sequence diagram captures how objects interact with each other. Sequence diagram emphasizes time
ordering of messages between object.
QUESTION 7:
Which of the following UML diagrams should you use when allocating use-case behavior to classes?
a. Sequence and communication diagrams
b. Use-case and activity diagrams
c. Sequence and activity diagrams
d. Class and deployment diagrams
e. Class and activity diagrams

Correct Answer: a. Sequence and Communication diagrams


Detailed Solution:
Sequence and Communication diagrams are nearly equivalent. Both the diagrams are useful for allocating
use-case behaviour to classes.
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

QUESTION 8:

Which one of the following can be said of a sequence diagram?


a. It is used to model the behavior of a single object over its life time
b. It is used to model the behavior of a single object when many use cases are executed
c. It is used to model the behavior of several objects when a single use case is executed
d. It is used to model the behavior of a single object when a single use case is executed
e. It is used to model the behavior of several objects when many use cases are executed

Correct Answer: c. It is used to model the behavior of several objects when a single use case is
executed
Detailed Solution:
For each use case there is one sequence diagram is developed. It shows interactions
among obejects for a single use case. So, option c. is correct.

QUESTION 9:

Which one of the following is true about a UML sequence diagram?


a. It describes the behaviour arising out of execution of many Use Cases.
b. It describes the behaviour arising out of execution of a single Use Case.
c. It describes the behaviour arising out of execution of a single object.
d. It describes the state behaviour arising out of execution of several objects.
e. It describes the behaviour arising out of changes to a system’s states.

Correct Answer: b. It describes the behaviour arising out of execution of a single use case.
Detailed Solution:
For a single use case there is one sequence diagram is developed. It shows
interactions among obejects for a single use case. So, option b. is correct.
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

QUESTION 10:
Consider the following C code.

Which one of the following is the state machine diagram is encoded by the given code?

a. A
b. B
c. C
d. D
e. Both C and D

Correct Answer: a. A
Detailed Solution:
We can see from the code, state s1 is going to state s2 after e2 event. Similarly, state s2 is going to
state s1 after e3 event. So, state machine diagram A is correct for the given code.
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

Object Oriented System Development Using UML, Java and Patterns


Assignment- 6
TYPE OF QUESTION: MCQ/MSQ
Number of questions: 10 Total mark: 10 X 1 = 10

For each of the following questions one or more of the given options are correct. Choose the
correct options.

QUESTION 1:
Consider the following fork construct used in an activity diagram.

Which of the following can be inferred from the given example fork construct?
a. Both Verify Order and Verify Customer activities start after Receive Order
activity
b. Verify Order activity precedes Verify Customer activity
c. Either Verify Order or Verify Customer activity take place after Receive Order
activity, but not both
d. Both Verify Order or Verify Customer activity take place in any order after
Receive Order activity is complete

Correct Answer: a. Both Verify Order and Verify Customer activities start after Receive Order activity
d. Both Verify Order or Verify Customer activity take place in any order after Receive
Order activity is complete

Detailed Solution:
Both Verify Order or Verify Customer activity take place in any order after Receive Order
activity is complete. So, options a. and d. are correct.
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

QUESTION 2:
Which of the following Activity diagram constructs imply that Verify Order and Verify Customer
activities can take place in any order?

a. A only
b. B Only
c. Both C and D
d. Both D and E
e. Both C and E
f. All of C, D, and E

Correct Answer: c. Both C and D

Detailed Solution:

Both the diagram of C and D reflects that Verify order and verify customer can take place in any order.
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

QUESTION 3:

Which of the followings can be inferred from the activity diagram given below?

a. Pay and Take Order activities can take place in any order
b. Pay activity must complete before Pack Order activity can
start
c. Pay and Pack Order activities can take place in any order
d. Request Service and Pack Order activities can take place in any
order
e. Take Order and Pack Order activities can take place in any
order

Correct Answer: a. Pay and Take Order activities can take place in any order
c. Pay and Pack Order activities can take place in any order

Detailed Solution:
Both a. and c. are correct.
Pay and Pack Order from different thread so they can start at any order.
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

QUESTION 4:

How is object creation through call to the new method in Java represented on a UML sequence
diagram?
a. Stereotyping asynchronous message send symbol with new
b. Stereotyping synchronous message send symbol with new
c. Stereotyping asynchronous signal send symbol with create
d. Annotating synchronous message send symbol with create
e. Annotating synchronous message send symbol with new

Correct Answer: c. Stereotyping asynchronous signal send symbol with create

Detailed Solution:
An object may create another object via an asynchronous <create> message.
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

QUESTION 5:

Consider the following UML sequence diagram. Based on the given sequence diagram, which one
of the following methods should be implemented by the Controller class?

a. register
b. register, checkDuplicate
c. register, displayCIN
d. register, showError, generateCIN
e. displayCIN, checkDuplicate, register
Correct Answer: d. register, showError, generateCIN

Detailed Solution:
The methods with incoming edges to the Controller class should be implemented by it.
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

QUESTION 6:
Consider the following Java code.

Which one of the following sequence diagrams corresponds to the given Java code for class B?

a. A
b. B
c. C
d. D
e. C and D
Correct Answer: a. A
Detailed Solution:

For class B, diagram A is most suitable.


NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

QUESTION 7:

Consider the following sequence diagram for the borrow book use case.

Based on the sequence diagram, which methods will get allocated to the LibraryMember class.
a. borrow
b. borrowBook and canBorrow
c. borrowBook and borrow
d. borrow and canBorrow
e. borrowBook

Correct Answer: b. borrowBook and canBorrow


Detailed Solution:
The methods with incoming edges to the LibraryMember class should be implemented by it.
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

QUESTION 8:
Consider the following sequence diagram for a use case named order.

Which methods should be supported by the Cart class, as can be inferred from the given sequence
diagram.
a. addItem, reserveItem, processInventory
b. addItem, checkOut, processOrder
c. reserveItem, adjustInventory
d. checkout, processOrder, adjustInventory, confirmOrder
e. addItem, reserveIte
Correct Answer: b. addItem, CheckOut, processOrder

Detailed Solution:
addItem, CheckOut, processOrder are incoming to Cart class. So, these theree methods are
supported by the Cart class.
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

QUESTION 9:
Consider the following fragment of an activity diagram.

Which one of the following is implied by the given segment of the activity diagram?
a. Both the Verify Order and the Verify Customer activities must complete, before
Accept Order activity can start
b. Any of Verify Order and the Verify Customer activities must complete, before
Accept Order activity can start
c. Verify order activity must complete, before any of Verify Customer and the
Accept Order activities can start.
d. Verify Customer activity must complete, before any of Verify Order and Accept
Order activities can start.
e. Verify Order, Verify Customer, and Accept Order execute concurrently
Correct Answer: a. Both the Verify Order and the Verify Customer activities must complete,
before Accept Order activity can start

Detailed Solution:
From the activity diagram it is clear that the Verify Order and the Verify Customer activities
must complete, before Accept Order activity can start.
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

QUESTION 10:

Consider the following Java code.

Which one of the following UML class diagrams corresponds most accurately with the given code?

a. A
b. B
c. C
d. D
e. C and D

Correct Answer: a. A

Detailed Solution:

Diagram A most accurately models the given code snippet.

***********END***********
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

Object Oriented System Development Using UML, Jav and Patterns


Assignment- 7
TYPE OF QUESTION: MCQ/MSQ
Number of questions: 10​ Total mark: 10 X 1 = 10

QUESTION 1:

In an informal (natural language) description of a programming problem, which parts of the


description are likely represent objects?

a.​ All of the nouns and all of the verbs


b.​ All of the verbs and some of the nouns
c.​ Some of the nouns
d.​ Some of the verbs
e.​ Some of the nouns and some of the verbs
Correct Answer: c. Some of the nouns
Detailed Solution:

Some of the nouns are likely to represent objects in an informal description of a programming
problem.

QUESTION 2:

Violations of the Open/Closed Principle can be recognized by:


a.​ Classes that are not be inherited, for example final classes in Java.
b.​ Classes that contain many private methods.
c.​ Classes with many private attributes
d.​ Classes with many protected methods
e.​ Class undergoes frequent code change
f.​ New public methods get added frequently

Correct Answer: e. Class undergoes frequent code change


f. New public methods get added get added frequently

Detailed Solution:
Open/Close principle violation can be attributed to scenarios where a class undergoes frequent code
change or new public methods get added frequently.
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

QUESTION 3:

Consider the following use case diagram for a supermarket automation software.

Based on the given use case diagram, how many boundary classes should be designed in the domain model.
a.​ 2
b.​ 3
c.​ 4
d.​ 6
e.​ 9

Correct Answer: c. 4

Detailed Solution:

Number of boundary classes depends on the number of user interactions with the system. Here,
there are 4 user interactions, therefore 4 boundary classes possible for this diagram.

QUESTION 4:

Which of the following are not responsibilities of a controller object in a domain model?
a.​ Interact with the boundary objects
b.​ Create the entity objects
c.​ Coordinate the activities of a set of entity objects
d.​ Embody most of the business logic required for use case execution
e.​ Permanently store frequently used data

Correct Answer: b. Create the entity objects


​ ​ e. Permanently store frequently used data
Detailed Solution:
In a domain model, the controller object interacts with the boundary objects, coordinates activities
of a set of entity objects, and embodies most of the business logic.
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

QUESTION 5:

Which one of the following are not true of boundary objects in a domain model?
a.​ Handle interactions with actors.
b.​ Have all the information to compute the response during a use case execution
c.​ Often implemented as screens, menus, forms, dialogs etc.
d.​ Often implement the business logic
e.​ Often validate input, format output, etc.

Correct Answer: b. Have all the information to compute the response during a use case execution
​ ​ d. Often implement the business logic

Detailed Solution:

Storing information to compute the response and implementing business logic are not the
responsibilities of boundary objects in a domain model.

QUESTION 6:

Which one of the following is the primary responsibility of a controller object in a domain model?
a.​ Receive user inputs
b.​ Validate the received inputs
c.​ Format output
d.​ Permanently store frequently used data
e.​ Coordinate the activities of a set of entity objects

Correct Answer: e. Coordinate the activities of a set of entity objects

Detailed Solution:

Controller object coordinates the activities of a set of entity objects in a domain model.
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

QUESTION 7:

A bank has two main types of accounts cash account or credit account. Also either type of account can be
held either by an individual or an Institution. Consider the following design that a designer has arrived at for
the bank automation.

Which one of the following design principles does the given design violate?
a.​ Single Responsibility Principle (SRP)
b.​ Dependency Inversion Principle (DIP)
c.​ Liskov Substitution Principle (LSP)
d.​ Open/Closed Principle (OCP)
e.​ Interface Segregation Principle (ISP)

Correct Answer: a. Single Responsibility Principle (SRP)


Detailed Solution:

Since the individual cash account and credit account inherit from multiple classes, it violates the
single responsibility principle.

QUESTION 8:

Which one of the following statements are FALSE regarding CRC cards?
a.​ CRC cards are used to assign methods to classes
b.​ CRC cards are used to assign class-level attributes to classes
c.​ CRC cards stands for Class-Responsibility-Collaborator cards
d.​ CRC cards are used to plan user interactions
e.​ Use of CRC cards involves performing structured walkthrough of use case scenarios

Correct Answer: b. CRC cards are used to assign class-level attributes to classes
​ ​ d. CRC cards are used to plan user interactions
Detailed Solution:
The CRC card does not assign class-level attributes to classes, rather it assigns methods to the class.
Neither does it plan for user interaction.
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

QUESTION 9:

Consider the following use case diagram for a supermarket automation software.

Based on the use case diagram, how many boundary classes should be designed in the domain
model?

a.​ 3
b.​ 5
c.​ 6
d.​ 8
e.​ 9

Correct Answer: e. 9
Detailed Solution:
The number of user interactions represents the number of boundary classes in a use case diagram.
In the given diagram, it is 9.
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

QUESTION 10:

Consider the following use case diagram for a supermarket automation software.

Based on the use case diagram, how many controller classes should be designed in the domain
model.

a.​ 3
b.​ 4
c.​ 5
d.​ 6
e.​ 7

Correct Answer: c. 5
Detailed Solution:
The number of use cases in a use case diagram represents the number of controller classes in the
corresponding domain model.

************END**********
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

Object Oriented System Development Using UML, Jav and Patterns


Assignment- 8
TYPE OF QUESTION: MCQ/MSQ
Number of questions: 10​ Total mark: 10 X 1 = 10

QUESTION 1:

Which of the following are not true of design patterns?


a.​ Give important design solutions explicit names
b.​ Save design iterations
c.​ Facilitate reuse of good design
d.​ Describe how to implement a solution to a particular problem using a given
programming language.
e.​ Describes a core solution that is used for generating many distinct designs
f.​ Help improve the design quality and designer productivity.
g.​ Design patterns directly lead to code reuse.

Correct Answer: d. Describe how to implement a solution to a particular problem using a given
programming language.
​ ​ g. Design patterns directly lead to code reuse.

Detailed Solution:

Design patterns neither describe how to implement a solution to a particular problem using a given
programming language nor does it directly lead to a code reuse.

QUESTION 2:

Which of the following statements are correct of the expert pattern?


a.​ Use of expert pattern increases cohesion in the design
b.​ Use of expert pattern increases coupling in the design
c.​ It suggests to assign responsibility to a class that has all/most information necessary to fulfil the
required responsibility
d.​ It suggests assigning a highly cohesive set of responsibilities to an artificial class
e.​ It suggests to assign responsibility to a class that is associated with maximum number of other
classes

Correct Answer: a. Use of expert pattern increases cohesion in the design


c. It suggests to assign responsibility to a class that has all/most information necessary to
fulfil the required responsibility
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

Detailed Solution:
Expert pattern increases cohesion and it also suggests assigning responsibility to a class that has
many information necessary to fulfil the required responsibility.

QUESTION 3:

Which of the following statements are correct of the pure fabrication pattern?
a.​ Use of expert pattern increases cohesion in the design
b.​ Use of expert pattern increases coupling in the design
c.​ It suggests to assign responsibility to a class that has all/most information necessary to fulfil the
required responsibility
d.​ It suggests assigning a highly cohesive set of responsibilities to an artificial class
e.​ It suggests to assign responsibility to a class that is associated with maximum number of other
classes

Correct Answer: d. It suggests assigning a highly cohesive set of responsibilities to an artificial class

Detailed Solution:

Pure fabrication pattern suggest assigning a highly cohesive set of responsibilities to an artificial
class.

QUESTION 4:

Which of the following are possible reasons as to why no design patterns exist for procedural development?
a.​ Lack of support of inheritance
b.​ Lack of support for abstract classes and interfaces
c.​ Lack of support for modular design
d.​ Lack of support of polymorphism
e.​ Lack of support for layered design

Correct Answer: a. Lack of support of inheritance


b. Lack of support for abstract classes and interfaces
d. Lack of support of polymorphism
Detailed Solution:
There exists no design patterns for procedural development due to its inherent disadvantages like:
lack of inheritance, abstract classes, interfaces, and polymorphism support
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

QUESTION 5:

Which of the following are not objectives of design patterns?


a.​ Codify good design
b.​ Give important design solutions explicit names to form a common vocabulary
c.​ Facilitate development of compact code
d.​ Facilitate easier maintenance
e.​ Improve run time efficiency

Correct Answer: c. Facilitate development of compact code


​ ​ e. Improve run time efficiency
Detailed Solution:

Design patterns do not focus on facilitating development of compact code. It neither focuses on
improving run time efficiency.

QUESTION 6:

Suppose a Controller class in a design has too many responsibilities. Which of the following should be
attempted to address the issue?
a.​ Fabricate an assistant controller class and assign some responsibilities to it
b.​ Inherit an assistant controller
c.​ Encapsulate the controller class
d.​ Delegate some responsibilities of the controller class to a co-controller class
e.​ Make the controller class an abstract class
f.​ Make the controller class an Interface class

Correct Answer: a. Fabricate an assistant controller class and assign some responsibilities to it
​ ​ d. Delegate some responsibilities of the controller class to a co-controller class

Detailed Solution:

To address the issue of too many responsibilities, fabricate an assistant controller class and assign
some responsibilities to it or delegate some responsibilities of the controller class to a co-controller
class.
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

QUESTION 7:

Which of the following is/are important ways in which an idiom (code pattern) differs from a design pattern?
a.​ It documents a good solution to a recurrent problem
b.​ It codifies a good solution
c.​ It helps reuse past experience of programmers
d.​ It gives a good solution an explicit name
e.​ It applies only in a narrow context

Correct Answer: e. It applies only in a narrow context


Detailed Solution:

Idiom or code pattern is applied in a narrow context as opposed to design pattern which is applied
in a broader context.

QUESTION 8:

In which of the following situations, should an object of a class C1 be responsible for creation of
an object of class C2?
a.​ C1 aggregates objects of type C2
b.​ C2 aggregates objects of type C1
c.​ C1 contains objects of type C2
d.​ C2 contains object of type C1
e.​ C1 has the initializing data for C2
f.​ C2 has the initializing data for C1

Correct Answer: a. C1 aggregates objects of type C2


​ ​ c. C1 contains objects of type C2
​ ​ e. C1 has the initializing data for C2
Detailed Solution:
C1 is responsible for creation of an object of clas C2 where, C1 aggregates objects of type C2 or it
contains any object of C2 or it has initialized any data for C2.
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

QUESTION 9:

Law of Demeter pattern suggests that an object should restrict its method calls to a method
belonging to which of the following?

a.​ This object (or self)


b.​ An object parameter of the method
c.​ An object attribute of self
d.​ An object created within the method
e.​ An object that is indirectly associated

Correct Answer: a. This object (or self)


b. An object parameter of the method

c. An object attribute of self

d. An object created within the method

Detailed Solution:
Law of demeter pattern suggests that an object should restrict its method calls to a method
belonging to this object(itself), or an object parameter of the method, or an object attribute of self,
or an object created within the method.

QUESTION 10:

Which one of the following is not true of an antipattern?

a.​ It represents lessons learned from a bad design.


b.​ It helps to recognize deceptive solutions that appear attractive at first, but turn out to be a
liability later
c.​ It helps reuse past experience of programmers
d.​ It helps to avoid certain design traps
e.​ It represents a good design practice

Correct Answer: e. It represents a good design practice


Detailed Solution:
Antipatterns do not represent good design patterns.

************END**********
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

Object Oriented System Development Using UML, Jav and Patterns


Assignment- 9
TYPE OF QUESTION: MCQ/MSQ
Number of questions: 10​ Total mark: 10 X 1 = 10

QUESTION 1:

In which of the following situations, use of the observer pattern should be recommended?
a.​ Asynchronous update of model elements
b.​ Model elements hold static information, any updating is not possible
c.​ Observer and model states need to be consistent all the time
d.​ Number of observers can change dynamically
e.​ Observers are fixed and statically configured

Correct Answer: a. Asynchronous update of model elements


​ ​ c. Observer and model states need to be consistent all the time

​​ d. Number of observers can change dynamically

Detailed Solution:

Observer pattern is recommended in situations where asynchronous update of model element,


observer and states need to be consistent all the time, and the number of observers can change
dynamically.

QUESTION 2:

Why is it not advised for model objects to directly invoke the view objects' services?
a.​ View objects are transient
b.​ Reuse, extension, maintenance are frequent.
c.​ A change to a view object should not require change to the model object
d.​ View objects are encapsulated
e.​ It would impact overall security of the solution

Correct Answer: a. View objects are transient


b. Reuse, extension, maintenance are frequent
c. A change to a view object should not require change to the model object
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

Detailed Solution:
In the case of MVC architecture, it is not advised for model objects to directly invoke the view
objects. services, because view objects are temporary where reuse, extension, and maintenance are
frequent. Also a change to a view object should not require change to the model object.

QUESTION 3:

Which of the following pattern hides the complexities of the system and provides an interface to the client
using which the client can access the system?
a.​ Composite Pattern
b.​ Facade pattern
c.​ Bridge pattern
d.​ Decorator pattern
e.​ Proxy pattern

Correct Answer: b. Facade pattern

Detailed Solution:

Facade pattern hides the complexities of the system and provides an interface to the client using
which the client can access the system.

QUESTION 4:

Law of Demeter design pattern does not recommend a method call to be made to which one of the following
types of objects?
a.​ This object (or self)
b.​ An object parameter of the method
c.​ An object attribute of self
d.​ An object that is an attribute of a called method
e.​ A controller object

Correct Answer: d. An object that is an attribute of a called method

Detailed Solution:
Law of Demeter design pattern does not recommend a method call to be made to an object that is an attribute
of a called method.
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

QUESTION 5:

In the following Bank package, which one of the following can be said of the BankServices class?

a.​ Observer class


b.​ Creator class
c.​ Controller class
d.​ Façade class
e.​ Model class

Correct Answer: d. Façade class


Detailed Solution:

Since the user uses BankServises interface to use the details of the bank services, this represents a
facade pattern..

QUESTION 6:

Which of the following pattern is used when there is one-to-many relationship between objects such as if
one object is modified, its dependent objects are to be notified automatically?
a.​ Iterator Pattern
b.​ Decorator pattern
c.​ Facade Pattern
d.​ Observer Pattern
e.​ Bridge pattern

Correct Answer: d. Observer Pattern

Detailed Solution:

Observer pattern is used in case of one-to-many relationship between objects such as if one object
is modified, its dependent objects are to be notified automatically.
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

QUESTION 7:

Which one of the following statements is not true of the façade design pattern?
a.​ Use of façade class in a server package reduces the overall coupling in the design
b.​ Use of façade class in a server package increases the overall cohesion of the classes in the server
package
c.​ The façade class often does little more than just delegating requests to other classes inside the
package.
d.​ A façade allows objects with incompatible interfaces to collaborate.
e.​ A façade class provides a common interface to the services of the package

Correct Answer: b. Use of façade class in a server package increases the overall cohesion of the classes
in the server package
Detailed Solution:

Since facade pattern felicitate a unified interface to a set of interfaces in a subsystem. It hides the
complexities of the system and makes it easier to use by providing a higher-level API. Therefore, it
does not increases the overall cohesion of the server pattern.

QUESTION 8:

Consider the following class diagram of the compiler sub-system of an application.

What can be said about the role of the compiler class in the package?
a.​ Façade
b.​ Observer
c.​ Adapter
d.​ Expert
e.​ Controller
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

Correct Answer: a. Façade


Detailed Solution:
In the given figure, compiler() provides an interface to the underlying complexity of its
architecture. Therefore, it can be considered as a facade pattern.

QUESTION 9:

In a push from below mechanism for interaction between the view and model elements, the model
object hard codes the references of the view objects and notifies them as soon as an event of
interest occurs. Which of the following is/are a reason for not using the push from below
mechanism for interaction between the view and model classes in an application such as network
monitoring?

a.​ View objects are usually transient


b.​ Intensity of interaction between the view and model objects
c.​ Sometimes more view objects are added and some view objects are taken off.
d.​ A change to a view object should not require change to the model object.
e.​ Model objects may need to be changed at times.

Correct Answer: a. View objects are usually transient


c. Sometimes more view objects are added and some view objects are taken off.

d. A change to a view object should not require change to the model object.

Detailed Solution:
In the given problem description, the reasons for not using the push from below mechanism for
interaction between the view and the model classes are: view objects are usually transient,
sometimes more view objects are added and some view objects are taken off, and a change to a
view object should not require change to the model object.
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

QUESTION 10:

Which one of the following is achieved through a judicious use of the observer pattern?

a.​ Loose coupling between the model and view objects


b.​ Encapsulation of the observers
c.​ Automate interaction between observer and view objects
d.​ Polymorphic binding between the observer and observable
e.​ Composition of the observers

Correct Answer: a. Loose coupling between the model and view objects
Detailed Solution:
Judicious use of observer pattern can achieve loose coupling between the model and view objects.

************END**********
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

Object Oriented System Development Using UML, Jav and Patterns


Assignment- 10
TYPE OF QUESTION: MCQ/MSQ
Number of questions: 10​ Total mark: 10 X 1 = 10

QUESTION 1:

Which design pattern would you apply if you would need when in an application that you are
developing, you want all the clients using class A to use the same instance of class A?
a.​ Apply the Creator pattern to class A
b.​ Apply the Controller pattern to class A
c.​ Apply the Singleton pattern to class A
d.​ Apply the Facade pattern to class A
e.​ Apply the Observer pattern to class A

Correct Answer: c. Apply the Singleton pattern to class A


Detailed Solution:

Singleton pattern is used in a situation where all the clients using a class use the instance od the
same class.

QUESTION 2:

Which one of the following GOF design patterns has been applied in the code snippet below?
public class PrintSpooler {
private static final PrintSpooler INSTANCE = new PrintSpooler();
private PrintSpooler() {}
public static PrintSpooler getInstance() {
return INSTANCE;
}
}
a.​ Observer design pattern
b.​ Controller design pattern
c.​ Singleton design pattern
d.​ Facade design pattern
e.​ Creator design pattern

Correct Answer: c. Singleton design pattern


NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

Detailed Solution:
The statement “private static final PrintSpooler INSTANCE = new PrintSpooler();” indicates that singleton
design pattern has been used in the given code.

QUESTION 3:

Consider the following structure of a singleton class.

For the singleton to work satisfactorily in a Java concurrent thread execution environment, which of the
following methods must be declared synchronized?

a.​ getSingletonData()
b.​ getInstance()
c.​ singletonOperation()
d.​ Singleton()
e.​ Both getSingletonData() and Singleton()

Correct Answer: b. getInstance()

Detailed Solution:
getInstance() method must be declared synchronized to work satisfactorily in a Java concurrent thread
execution environment.

QUESTION 4:

Which of the following describes the purpose of the State pattern correctly?
a.​ Used to design a class for which the object behaviour changes based on the present state.
b.​ The state behaviour of an object is implemented using a doubly nested switch
c.​ The behaviour of the algorithm a class method can be changed at run time.
d.​ The state behaviour of a class is implemented in an abstract class and are inherited by the concrete
state classes.
e.​ Provides an easily maintainable design for a class whose objects have non-trivial state behavior

Correct Answer: a. Used to design a class for which the object behaviour changes based on the present
state.
e. Provides an easily maintainable design for a class whose objects have non-trivial state
behavior
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

Detailed Solution:
State pattern is used to design a class for which the object behavior changes based on the present state.
Therefore, it can provide an easily maintainable design for a class whose objects have non-trivial state
behavior.

QUESTION 5:

Consider the class diagram for the state pattern shown below.

Which of the class/classes shown in the diagram exhibits state-dependent behaviour?


a.​ Context
b.​ AbsState
c.​ Concrete State 1
d.​ Concrete State 2
e.​ Concrete State 3

Correct Answer: a. Context


Detailed Solution:

The context class in the diagram exhibits state-dependent behavior since it depends on the abstract
state.
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

QUESTION 6:

Consider the class diagram shown below for the state pattern.

Which of the following statements about the state pattern is/are most inaccurate?
a.​ Model view separation is a main idea used
b.​ State object pointed to by the context class, changes its state
c.​ The state variable is of the type AbsState
d.​ The state transition logic can only be implemented in the context class
e.​ Concrete state objects are usually created by the Context class

Correct Answer: b. State object pointed to by the context class, changes its state
e. Concrete state objects are usually created by the Context class

Detailed Solution:

In the given state pattern, state object pointed by the context class does not change its state and the
concrete state objects are usually not created by the context class.
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

QUESTION 7:

Consider a watch that can toggle the display of time between analog or digital modes when the user presses
a toggle switch on the watch. Which one of the following is the most accurate class model of the watch
obtained by applying the state pattern.

a.​ A
b.​ B
c.​ C
d.​ D
e.​ Both A and B

Correct Answer: c. C
Detailed Solution:

Diagram C is the most accurate class model of the watch where we can switch between analog and
digital modes. Here the state is abstracted so that it can be used as per the requirement.
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

QUESTION 8:

In an implementation of the state pattern, the transitions among the states is usually implemented in
which of the following elements of the class diagram? ​
a.​ Context
b.​ Abstract state
c.​ Concrete state
d.​ Aggregation relation
e.​ Client

Correct Answer: a. Context


c. Concrete state
Detailed Solution:
The transitions among states in a state pattern is usually implemented in context and concrete states
elements of the class diagram.

QUESTION 9:

Suppose the behaviour of an embedded controller class can be represented by 10 states and 25
transitions. The transitions among states occur on the average once in 10milli Seconds. For an
efficient implementation of the controller, the transitions among states should be accomplished in
which one of the following elements of the class design?

a.​ Context
b.​ Abstract state
c.​ Concrete state
d.​ Aggregation relation
e.​ Client

Correct Answer: a. Context


Detailed Solution:
Since the state transitions occur frequently, this behavior can be accomplished in Context element
of the class design.
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

QUESTION 10:

Which of the following are the main objectives of the Singleton pattern?

a.​ Ensure that no more than one instance of a class exists.


b.​ Ensure that only one instance of a class exists for each thread of access.
c.​ Separate the objects of a single class from objects of another class.
d.​ Control the creation of the first instance of the classes to enhance efficiency.
e.​ Provide global access to the single object

Correct Answer: a. Ensure that no more than one instance of a class exists.
​ ​ e. Provide global access to the single object
Detailed Solution:

Singleton pattern basically ensures that no more than one instance of a class can exists, thereby
provides a global access to the single object.

************END**********
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

Object Oriented System Development Using UML, Jav and Patterns


Assignment- 11
TYPE OF QUESTION: MCQ/MSQ
Number of questions: 10​ Total mark: 10 X 1 = 10

QUESTION 1:

Which one of the following design patterns should be used when we need to treat a group of objects
in a similar way as a single object? ​
a.​ Singleton Pattern
b.​ Composite Pattern
c.​ Facade Pattern
d.​ Observer Pattern
e.​ State Pattern

Correct Answer: b. Composite Pattern


Detailed Solution:

While treating a group of objects in a similar way as a single object, a composite pattern is used.
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

QUESTION 2:

Consider the following Java AWT class hierarchy

Observe that the containers can contain basic components such as buttons, canvas, and also some containers.
Which design pattern has been used?
a.​ Façade
b.​ Observer
c.​ Composite
d.​ Singleton
e.​ State

Correct Answer: c. Composite


Detailed Solution:
From the class association in the given diagram, it can be said that a Composite pattern can be used.
Here the container class is composed of components.
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

QUESTION 3:

Which one of the following class relationships best represented using the composite pattern?
a.​ A Zoo contains a Set Exhibit, an Exhibit contains a Set Animal, and an Animal contains a number
of properties about that individual animal. To get information about a particular Animal, a client
would write program statement such as: Zoo.getExhibit("Penguins").getPenguin("Tux").getAge();
b.​ Dalmatian is a subclass of Dog, which is a subclass of Mammal, which is a subclass of Animal.
Each subclass overrides some methods while using the inherited version of others, for shared
behaviour and distinct behaviour respectively.
c.​ An e-mail contains text, image, video, and other attachments, the attachments in turn can contain
text, image, video, and other attachments
d.​ GeometricShape is an Interface class and is implemented by Square, Circle, Sphere, and
Dodecahedron. Though they have the same public interface and can all be used anywhere a
GeometricShape is required, they otherwise have no relationship and do not depend on each other.
e.​ The class Food is the base class for PeanutButterAndJellySandwich, which contains objects of type
Bread, PeanutButter, and Jelly. Bread contains Flour and Salt, and Jelly contains Fruit and Sugar. All
of these objects are Food objects themselves.

Correct Answer: c. An e-mail contains text, image, video, and other attachments, the attachments in turn
can contain text, image, video, and other attachments.
e. The class Food is the base class for PeanutButterAndJellySandwich, which contains
objects of type Bread, PeanutButter, and Jelly. Bread contains Flour and Salt, and Jelly
contains Fruit and Sugar. All of these objects are Food objects themselves.

Detailed Solution:
A composite pattern can describe a scenario where an e-mail contains text, image, video, and other
attachments, the attachments in turn can contain text, image, video, and other attachments, and the class
Food is the base class for PeanutButterAndJellySandwich, which contains objects of type Bread,
PeanutButter, and Jelly. Bread contains Flour and Salt, and Jelly contains Fruit and Sugar. All of these
objects are Food objects themselves.
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

QUESTION 4:

Consider the following problem faced by a designer while designing an application: “An object may contain
other objects which may either be a group or some individual object.” He came up with the following
design. Which one of the following is the main shortcoming of his design?

​ ​ ​

a.​ The client has to treat the individual objects and groups separately.
b.​ Restricts the containment relationship among objects to a single level only
c.​ Restricts the composites to contain the same number and types of objects
d.​ Violates Liskov Substitution Principle (LSP)
e.​ Violates dependency inversion principle

Correct Answer: d. Violates Liskov Substitution Principle (LSP)

Detailed Solution:
GroupObject is inheriting from IndividualObject, but it does not behave like an individual object. A
GroupObject manages a list of objects, while IndividualObject represents a single entity.
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

QUESTION 5:

Consider the following problem faced by a designer while designing an application: “An object may contain
other objects which may either be a group or some individual object.” He came up with the following
design. Which one of the following are shortcomings of this design?

a.​ Client code must treat primitive and container classes different
b.​ Difficult to add new types of Leaf.
c.​ Only single level of depth possible
d.​ Construction of a new type of composite using a new type of leaf nodes is troublesome
e.​ Difficult to add new Leaf objects to the Composite

Correct Answer: a. Client code must treat primitive and container classes different
b. Difficult to add new types of Leaf.
c. Only single level of depth possible
Detailed Solution:

In the given description and the diagram, the client code must treat primitive and container classes
differently, it is also difficult to add new types of leaf to the leaf class. Therefore, only a single
depth is possible.
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

QUESTION 6:

Suppose you have a class that accepts and returns length measures in British Imperial units (e.g. feet, miles,
etc.). However, in a certain application that you are developing, you need to use length measures in metric
units. Which one of the following design pattern would be most appropriate for this.
a.​ Adapter
b.​ Decorator
c.​ Delegation
d.​ Proxy
e.​ Bridge
f.​ MVC

Correct Answer: a. Adapter

Detailed Solution:

The Adapter Pattern is used to convert one interface into another expected by the client.
In this case, the existing class uses British Imperial units, but the application requires metric units.
The Adapter will translate values between these unit systems without modifying the original class.

QUESTION 7:

Which design pattern would you apply if you would need when an application refers to a local object but
gets the response computed by a remote object?
a.​ Adapter
b.​ Flyweight
c.​ Proxy
d.​ Facade
e.​ Decorator

Correct Answer: c. Proxy


Detailed Solution:

The Proxy Pattern is used when an application interacts with an object as if it were local, but the
actual computation or data comes from a remote object. It acts as a placeholder or intermediary that
controls access to the remote object.
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

QUESTION 8:

Which of the following describes the Adapter pattern correctly?


a.​ This pattern builds a complex object using simple objects using a step by step approach.
b.​ This pattern addresses efficiently creating duplicate objects.
c.​ This pattern works as a bridge between two incompatible interfaces.
d.​ This pattern is used when we need to decouple an abstraction from its implementation so
that the two can vary independently.

Correct Answer: c. This pattern works as a bridge between two incompatible interfaces.
Detailed Solution:

The Adapter Pattern is used to make two incompatible interfaces work together. It converts one
interface into another that the client expects. It is often used when integrating legacy code or
third-party libraries with new applications.

QUESTION 9:

Which of the following describes the Bridge pattern correctly?

a.​ This pattern builds a complex object using simple objects using a step by step approach.
b.​ This pattern addresses efficiently creating duplicate objects.
c.​ This pattern is used when it is necessary to prevent creation of objects directly to reduce
dependencies in the design.
d.​ This pattern allows objects with incompatible interfaces to collaborate.
e.​ This pattern is used when we need to decouple an abstraction from its implementation so
that the two can vary independently.

Correct Answer: e. This pattern is used when we need to decouple an abstraction from its
implementation so that the two can vary independently.
Detailed Solution:
The Bridge Pattern is used to separate an abstraction from its implementation so that both can
evolve independently without affecting each other.
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

QUESTION 10:

In the observer pattern, why does the problem of dangling references occur?

a.​ A concrete observer may die unexpectedly


b.​ The concrete subject may die unexpectedly
c.​ The concrete subject may fail to invoke the detach method
d.​ A concrete subject may get created unexpectedly
e.​ A concrete observer may get created unexpectedly

Correct Answer: a. A concrete observer may die unexpectedly


Detailed Solution:

The problem of dangling references occur because a concrete observer may die unexpectedely.

************END**********
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

Object Oriented System Development Using UML, Jav and Patterns


Assignment- 12
TYPE OF QUESTION: MCQ/MSQ
Number of questions: 10​ Total mark: 10 X 1 = 10

QUESTION 1:

Suppose in a certain application, we need a group of objects having the same interface to be nested
in a chain structure. Clients should be able to treat individual objects and the decorating objects in
the same way. Which one of the following class structures should be used?

a.​ A
b.​ B
c.​ C
d.​ D
e.​ Both A and B

Correct Answer: d. D
Detailed Solution:

The given description in the question indicates a composite pattern for which the diagram D is the
correct option.
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

QUESTION 2:

Which one of the following is FALSE about the decorator pattern?


a.​ The decorated object and the decorator objects share the same interface
b.​ The decorated object contains the decorator objects
c.​ Using the decorator pattern, the behaviour of a class can modified at run-time
d.​ An object can be decorated by multiple instances of the same decorator object
e.​ The decorated object has a different interface compared to the decorator object

Correct Answer: b. The decorated object contains the decorator objects


​ ​ e. The decorated object has a different interface compared to the decorator object
Detailed Solution:
In the Decorator Pattern, both the decorated object and the decorator objects share the same
interface.

QUESTION 3:

Consider the following Java statement:


Stream aStream = new CompressingStream(new ASCII7Stream(new FileStream(
"fileName.dat")));
Which one is the decorated object?
a.​ CompressingStream
b.​ ASCII7Stream
c.​ FileStream( "fileName.dat")
d.​ Both CompressingStream and ASCII7Stream
e.​ aStream

Correct Answer: c. FileStream( "fileName.dat")


Detailed Solution:
In the Decorator Pattern, the decorated object is the one being wrapped and extended by decorators.
FileStream("fileName.dat") is the original object (base component).
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

QUESTION 4:

Which of the following statements are FALSE about the decorator pattern?
a.​ Multiple instances of a single decorator class can decorate an object
b.​ A decorator of a decorated object can be deleted at runtime
c.​ A decorator class is usually inherited from the decorated class
d.​ A decorator may define additional methods that are not present in the decorated interface
e.​ When any of a set of functionalities of an object are required to be turned on or off at runtime , it
can be achieved using much less number of classes and objects using the decorator pattern as
compared to providing all the required functionalities in a single class and implementing a
mechanism to turn these off as required.

Correct Answer: c. A decorator class is usually inherited from the decorated class
e. When any of a set of functionalities of an object are required to be turned on or off at
runtime , it can be achieved using much less number of classes and objects using the
decorator pattern as compared to providing all the required functionalities in a single class
and implementing a mechanism to turn these off as required.

Detailed Solution:
Decorators do not inherit from the decorated class; instead, they implement the same interface as the
decorated class. When any of a set of functionalities of an object are required to be turned on or off at
runtime, every new functionality requires a separate decorator class.
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

QUESTION 5:

Which one of the following is false about the iterators associated with Java collection classes?
a.​ Multiple iterators can traverse the same collection without affecting each other
b.​ Multiple iterators may implement different types of traversal of the same collection
c.​ The iterator maintains a reference of the aggregate
d.​ The aggregate maintains a reference of its iterator

Correct Answer: d. The aggregate maintains a reference of its iterator

Detailed Solution:
In Java, iterators hold a reference to the collection they traverse, but collections do not track or
store iterators. Each call to iterator() creates a new, independent iterator, and the collection does not
manage them.

QUESTION 6:

Which of the following is the return type of the hasNext() method of an iterator?
a.​ Integer
b.​ Double
c.​ Boolean
d.​ Collection Object
e.​ Reference to collection object

Correct Answer: c.Boolean

Detailed Solution:

The hasNext() method of an Iterator in Java returns a boolean value. It checks if there are more
elements to iterate over in the collection.
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

QUESTION 7:

Which one of the following is true of the Java Collection Iterators?


a.​ next() returns a clone of the next object
b.​ next() returns a reference to the next object
c.​ next() returns an integer representing the index of the next element but does not increment the index
d.​ next() returns an integer representing the index of the next element and also increments the index
e.​ next() does not return anything and only increments the index

Correct Answer: b. next() returns a reference to the next object

Detailed Solution:

The next() method in Java's Iterator interface returns a reference to the next element in the
collection, not a clone or an index.

QUESTION 8:

Which of the following are true of the Java CopyOnWriteArrayList class?


a.​ Implements the List Interface
b.​ Derived from ArrayList class
c.​ Whenever client performs a write, a copy of the concerned ArrayList object is made for that client
d.​ Implements the List Interface and derived from ArrayList class
e.​ Holds a reference to an ArrayList object

Correct Answer: a. Implements the List Interface


​ ​ c. Whenever client performs a write, a copy of the concerned ArrayList object is made
for that client
​ ​ e. Holds a reference to an ArrayList object

Detailed Solution:

The Java CopyOnWriteArrayList class implements the list interface, a copy of the concerned
ArrayList object is created for that client whenever the client performs a write operation, it also
holds a reference to an ArrayList object.
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

QUESTION 9:

For which of the following Java classes you cannot directly create an Iterator?
a.​ Set
b.​ ArrayList
c.​ List
d.​ HashMap
e.​ HashTable

Correct Answer: d. HashMap


e. HashTable
Detailed Solution:

Iterator can not be created for HashMap and HashTable. However, you can create an iterator for its
key set (keySet()), value collection (values()), or entry set (entrySet()).
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

QUESTION 10:

Which one of the following is the correct class structure of the Proxy pattern?

a.​ A
b.​ B
c.​ C
d.​ D
e.​ Both B and C

Correct Answer: a. A
Detailed Solution:

Diagram A correctly represents a proxy pattern.

************END**********

You might also like