Faculty of ScienceDepartment of ComputingFinal Examinati.docx

M

Faculty of Science Department of Computing Final Examination 2013 Unit: COMP229 Object Oriented Programming Practices Release Date: 9:00am, November 15, 2013 Due Date: 11:45pm, November 19, 2013 Total Number of Questions: Six (6) Total Marks: Sixty Four (68) Instructions: Answer ALL questions. All references to program code or behaviour refer to the Java language. All answers to questions that ask for code must be written using Java. Every attempt has been made to make questions unambiguous. However, if you are not sure what a question is asking, make some reasonable assumption and state it at the beginning of your answer. COMP229 Object Oriented Programming Practices, November 2013 Question 1 (Design Patterns, 5 marks) The template method pattern and the strategy pattern both abstract some computation in the form of methods. What defining characteristic distinguishes the template method patern from the strategy pattern? Explain your answer. [5 marks] Question 2 (Concurrency, 12 marks) Consider the following class definition. This class is considered to be in an inconsistent state if the isConsistent() method returns falsefalsefalse; publicpublicpublic classclassclass Foo { longlonglong mValue; longlonglong mValueTimesTwo; /** * Sets the state of our object. * * Pauses briefly between setting the first and second * values in order to increase the probability that the * object will be interrogated while in an inconsistent * state. * * @param pValue the value to update the current state with , */ publicpublicpublic synchronizedsynchronizedsynchronized voidvoidvoid setValues(longlonglong pValue) { mValue = pValue; doPause (3); mValueTimesTwo = pValue * 2; } /** * Checks to see if the current state of our object is * consistent. * * @return true if it is. */ publicpublicpublic synchronizedsynchronizedsynchronized booleanbooleanboolean isConsistent () { returnreturnreturn (mValue * 2 == mValueTimesTwo ); } /** * Utility routine - pauses our thread by calling * sleep and supressing any InterruptedException. */ privateprivateprivate staticstaticstatic voidvoidvoid doPause(longlonglong pPause) { trytrytry { Thread.sleep(pPause ); } catchcatchcatch (InterruptedException e) { e.printStackTrace (); } } } Page 1 of 5 COMP229 Object Oriented Programming Practices, November 2013 a. Imagine a hypothetical version of Java where the object lock is replaced by a method lock. Under this system a call to a synchronised method would assign a lock for that method to the calling thread. No other thread could then call this method because the lock is already allocated. However, other methods of the same object could still be called. Upon the method completing, the lock is released. Under this system, is it possible to put an instance of the Foo class into an inconsistant state? If so, give a code example which could create this situation and explain how it does so. If not, explain how the method lock preven ...

Faculty of Science
Department of Computing
Final Examination 2013
Unit: COMP229 Object Oriented Programming Practices
Release Date: 9:00am, November 15, 2013
Due Date: 11:45pm, November 19, 2013
Total Number
of Questions: Six (6)
Total Marks: Sixty Four (68)
Instructions: Answer ALL questions.
All references to program code or behaviour refer to the Java
language.
All answers to questions that ask for code must be written using
Java.
Every attempt has been made to make questions unambiguous.
However, if
you are not sure what a question is asking, make some
reasonable assumption
and state it at the beginning of your answer.
COMP229 Object Oriented Programming Practices, November
2013
Question 1 (Design Patterns, 5 marks)
The template method pattern and the strategy pattern both
abstract some computation in
the form of methods. What defining characteristic distinguishes
the template method patern
from the strategy pattern? Explain your answer. [5 marks]
Question 2 (Concurrency, 12 marks)
Consider the following class definition. This class is considered
to be in an inconsistent state
if the isConsistent() method returns falsefalsefalse;
publicpublicpublic classclassclass Foo {
longlonglong mValue;
longlonglong mValueTimesTwo;
/**
* Sets the state of our object.
*
* Pauses briefly between setting the first and second
* values in order to increase the probability that the
* object will be interrogated while in an inconsistent
* state.
*
* @param pValue the value to update the current state with ,
*/
publicpublicpublic synchronizedsynchronizedsynchronized
voidvoidvoid setValues(longlonglong pValue) {
mValue = pValue;
doPause (3);
mValueTimesTwo = pValue * 2;
}
/**
* Checks to see if the current state of our object is
* consistent.
*
* @return true if it is.
*/
publicpublicpublic synchronizedsynchronizedsynchronized
booleanbooleanboolean isConsistent () {
returnreturnreturn (mValue * 2 == mValueTimesTwo );
}
/**
* Utility routine - pauses our thread by calling
* sleep and supressing any InterruptedException.
*/
privateprivateprivate staticstaticstatic voidvoidvoid
doPause(longlonglong pPause) {
trytrytry {
Thread.sleep(pPause );
} catchcatchcatch (InterruptedException e) {
e.printStackTrace ();
}
}
}
Page 1 of 5
COMP229 Object Oriented Programming Practices, November
2013
a. Imagine a hypothetical version of Java where the object lock
is replaced by a method
lock. Under this system a call to a synchronised method would
assign a lock for that
method to the calling thread. No other thread could then call
this method because
the lock is already allocated. However, other methods of the
same object could still
be called. Upon the method completing, the lock is released.
Under this system, is it
possible to put an instance of the Foo class into an inconsistant
state? If so, give a code
example which could create this situation and explain how it
does so. If not, explain
how the method lock prevents the possibility of inconsistent
state. [7 marks]
b. Provide one possible motivation for choosing this
hypothetical method lock over an
object lock. Explain your answer. [5 marks]
Question 3 (Generics, 15 marks)
Consider the following interface definition
/**
* This is an interface which abstracts the concept of a
* function. The interface has methods for a number of
* possible function call styles.
*
* @param <T> The type over which these functions work.
**/
publicpublicpublic interfaceinterfaceinterface Functions <T> {
/**
* A function which does not return a value
*
* @param in The parameter to this function
**/
publicpublicpublic abstractabstractabstract voidvoidvoid doIt(T
in);
/**
* A function which turns a T into an integer
*
* @param in The parameter to this function
**/
publicpublicpublic abstractabstractabstract intintint calculate(T
in);
/**
* A function which turns a T into an String
*
* @param in The parameter to this function
**/
publicpublicpublic abstractabstractabstract String show(T in);
/**
* A function which creates a T based on an integer
*
* @param in The parameter to this function
**/
publicpublicpublic abstractabstractabstract T generate(intintint
in);
/**
* This function , called "transform" returns a value of the same
type
* as the parameter it was given.
Page 2 of 5
COMP229 Object Oriented Programming Practices, November
2013
*
* @param in The parameter to this function
* @return A value of the same type as the input parameter
**/
// FIXME: Write this method signature
}
a. This interface is part of an implementation of a design
pattern. Which design pattern
is it from? Give the standard class diagram for the pattern and
identify which part of
the pattern is being implemented with the above interface. [6
marks]
b. How does this instance of the pattern differ from the standard
version? [2 marks]
c. The final method signature has been left out. Write what you
think that signature
should be. [7 marks]
Question 4 (Refactoring, 16 marks)
Consider the following class definition. It is not necessary that
you know anything about the
system from which this class was taken, nor is it necessary to
know anything about the classes
Expr, Number or Boolean.
publicpublicpublic classclassclass Infer <T> {
Expr <T> expr;
publicpublicpublic Infer(Expr <T> e){
expr = e;
}
/**
* @param inferenceType The type of inference to perform.
* 0 is simple inference , 1 is polymorphic inference ,
* 2 is explicit inference.
**/
publicpublicpublic booleanbooleanboolean doInference(intintint
inferenceType ){
ififif (inferenceType == 0)
ififif (expr.isVal ())
ififif (expr.isDefined ())
returnreturnreturn truetruetrue;
elseelseelse
returnreturnreturn falsefalsefalse;
elseelseelse ififif (expr.isPlus ()){
returnreturnreturn (newnewnew Infer <Number >(expr.left )).
doInference(inferenceType)
&& (newnewnew Infer <Number >(expr.right )).
doInference(inferenceType );
}
elseelseelse ififif (expr.isMinus ()){
returnreturnreturn (newnewnew Infer <Number >(expr.left )).
doInference(inferenceType)
&& (newnewnew Infer <Number >(expr.right )).
doInference(inferenceType );
}
elseelseelse ififif(expr.isAnd ()){
returnreturnreturn (newnewnew Infer <Boolean >(expr.left )).
doInference(inferenceType)
&& (newnewnew Infer <Boolean >(expr.right )).
doInference(inferenceType );
}
elseelseelse ififif(inferenceType == 1)
ififif (expr.isVal ())
Page 3 of 5
COMP229 Object Oriented Programming Practices, November
2013
ififif (expr.isDefined ())
returnreturnreturn falsefalsefalse;
elseelseelse
returnreturnreturn truetruetrue;
elseelseelse ififif (expr.isPlus ()){
returnreturnreturn (newnewnew Infer <Number >(expr.left )).
doInference(inferenceType)
&& (newnewnew Infer <Number >(expr.right )).
doInference(inferenceType );
}
elseelseelse ififif (expr.isMinus ()){
returnreturnreturn (newnewnew Infer <Number >(expr.left )).
doInference(inferenceType)
&& (newnewnew Infer <Number >(expr.right )).
doInference(inferenceType );
}
elseelseelse ififif(expr.isAnd ()){
returnreturnreturn (newnewnew Infer <Boolean >(expr.left )).
doInference(inferenceType)
&& (newnewnew Infer <Boolean >(expr.right )).
doInference(inferenceType );
}
elseelseelse
returnreturnreturn truetruetrue;
}
}
a. Identify as many code smells as you can in the above class.
Hint: There are at least
two. [6 marks]
b. Refactor the class to remove all the code smells you
identified. Give the full definition
of your refactored class and an explanation of the refactorings
you performed.
[10 marks]
Question 5 (Design Patterns, 8 marks)
(a) There is something wrong with the following instance of the
Template Method pattern.
Explain what is wrong. Modify the system so that it conforms to
the pattern. Explain
each of the changes you made to the system. Draw the class
diagram for your modified
system. [8 marks]
Page 4 of 5
COMP229 Object Oriented Programming Practices, November
2013
Question 6 (Testing, 12 marks)
(a) The following diagram shows the classes used in a
calculator application. This cal-
culator application can do addition, multiplication, powers,
logarithms, factorials and
permutations. Some of these calculations can take a long time
on the low-powered de-
vice on which it is designed to run. For this reason, the
calculator takes each calculation
it is asked to do and sends it over the internet to a
supercomputer for computation as
well as attempting to calculate it locally. If the supercomputer
returns the result faster
than the program can calculate it, it uses that result.
Furthermore, the computer on
which this application is running has a large amount of memory,
so the application will
store all the calculations it has already performed in a database.
If it is asked to do
a calculation it has done before, it uses the value it has stored in
the database. This
database can store 100,000 results before it is full and when it
is full the calculator will
have to do any new calculations every time they are requested.
At least the database class will need to be stubbed with mock
objects for testing be-
cause you need to test for empty, partially full, and completely
full databases. Which
other classes do you think will need to be stubbed with mock
objects for testing the
application? For each class you identify explain why you think
that class needs mocking
and at least three different mocked behaviours you will need.
[12 marks]
END OF EXAMINATION
Page 5 of 5
• 2- Topic Selection
Please post the topic you plan to explore. Include why you
selected it and how it impacts your profession.
Your submission should be at least 250 words after which you
must comment to at least two of your peers.
At the end of the discussion, you will be asked to craft a 150
word reflection on what you have learned through this
conversation and post it to the Weekly Reflection Journal. The
more active you are in this part of the discussion, the more you
will have to draw from in your reflection, so get involved, be
active, help out your classmates when they need it, and, most of
all, enjoy the conversation
• 3- Discipline Areas (Bodies of Knowledge)
The following topic(s) will demonstrate what the discussion is
about, but feel free to branch off or expand on the topics. At the
end of the discussion, you will be asked to craft a 150 word
reflection on what you have learned through this conversation
and post it to the Weekly Reflection Journal. The more active
you are in this part of the discussion, the more you will have to
draw from in your reflection, so get involved, be active, help
out your classmates when they need it, and, most of all, enjoy
the conversation.
Your research paper must address a profession-related issue
from at least two discipline perspectives. Please discuss the
following questions about your proposed project:
• How do the two areas you have selected relate to the
issue?
• How do they appear to overlap?
• What challenges have you encountered so far in
finding information relevant to your topic and how will you
address those challenges? After you have posted your
discussion, please comment to at least two of your peers.
•
• 4- Discoveries (So Far)
The following topic(s) will demonstrate what the discussion is
about, but feel free to branch off or expand on the topics. At the
end of the discussion, you will be asked to craft a 150 word
reflection on what you have learned through this conversation
and post it to the Weekly Reflection Journal. The more active
you are in this part of the discussion, the more you will have to
draw from in your reflection, so get involved, be active, help
out your classmates when they need it, and, most of all, enjoy
the conversation.
Using the mind mapping and article evaluations completed in
W3, discuss two things that surprised you regarding your topic.
Additionally, are you on track with your topic or have you
discovered that you may need to make some changes? Why or
why not? Please respond to at least two of your colleagues
• 5- Self-Evaluation of Your Paper
The following topic(s) will demonstrate what the discussion is
about, but feel free to branch off or expand on the topics. At the
end of the discussion, you will be asked to craft a 150 word
reflection on what you have learned through this conversation
and post it to the Weekly Reflection Journal. The more active
you are in this part of the discussion, the more you will have to
draw from in your reflection, so get involved, be active, help
out your classmates when they need it, and, most of all, enjoy
the conversation.
Using the checklist on p. 130 of the text, evaluate your first
draft. Discuss the strengths and weaknesses you found regarding
your own writing and how you plan to build upon and/or
improve what you discovered. Please respond (or give advice)
to at least two of your peers.
• 6- Enhancing the Paper
The following topic(s) will demonstrate what the discussion is
about, but feel free to branch off or expand on the topics. At the
end of the discussion, you will be asked to craft a 150 word
reflection on what you have learned through this conversation
and post it to the Weekly Reflection Journal. The more active
you are in this part of the discussion, the more you will have to
draw from in your reflection, so get involved, be active, help
out your classmates when they need it, and, most of all, enjoy
the conversation.
Having written the first draft of your paper (and using the
article review worksheet completed in W3), please discuss the
following issues related to your topic:
• What are some potential ethical issues that must be
considered?
• How might this issue impact different communities
from diverse perspectives? (For example, are there differences
based on age, gender, economics, political, ethnic, religious,
educational or geographic?) Please respond to at least two of
your peers.
•
• 7- Using My Research
The following topic(s) will demonstrate what the discussion is
about, but feel free to branch off or expand on the topics. At the
end of the discussion, you will be asked to craft a 150 word
reflection on what you have learned through this conversation
and post it to the Weekly Reflection Journal. The more active
you are in this part of the discussion, the more you will have to
draw from in your reflection, so get involved, be active, help
out your classmates when they need it, and, most of all, enjoy
the conversation.
Discuss how (or if) what you have discovered has (or will)
change your role within the communities in which you are a
member. Why or why not? Please respond to at least two of
your colleagues.
• 8- Abstract of Paper
The following topic(s) will demonstrate what the discussion is
about, but feel free to branch off or expand on the topics. At the
end of the discussion, you will be asked to craft a 150 word
reflection on what you have learned through this conversation
and post it to the Weekly Reflection Journal. The more active
you are in this part of the discussion, the more you will have to
draw from in your reflection, so get involved, be active, help
out your classmates when they need it, and, most of all, enjoy
the conversation.
Please summarize the findings of your paper and discuss how
you will use what you have discovered in your profession and in
the future.

Recomendados

Martin Chapman: Research Overview, 2017 von
Martin Chapman: Research Overview, 2017Martin Chapman: Research Overview, 2017
Martin Chapman: Research Overview, 2017Martin Chapman
337 views54 Folien
Desing pattern prototype-Factory Method, Prototype and Builder von
Desing pattern prototype-Factory Method, Prototype and Builder Desing pattern prototype-Factory Method, Prototype and Builder
Desing pattern prototype-Factory Method, Prototype and Builder paramisoft
1.9K views26 Folien
Unit testing - A&BP CC von
Unit testing - A&BP CCUnit testing - A&BP CC
Unit testing - A&BP CCJWORKS powered by Ordina
722 views113 Folien
Patterns in Python von
Patterns in PythonPatterns in Python
Patterns in Pythondn
3.3K views48 Folien
Ecs 10 programming assignment 4 loopapalooza von
Ecs 10 programming assignment 4   loopapaloozaEcs 10 programming assignment 4   loopapalooza
Ecs 10 programming assignment 4 loopapaloozaJenniferBall44
184 views12 Folien
TDD And Refactoring von
TDD And RefactoringTDD And Refactoring
TDD And RefactoringNaresh Jain
7.4K views34 Folien

Más contenido relacionado

Similar a Faculty of ScienceDepartment of ComputingFinal Examinati.docx

Mastering Python lesson 4_functions_parameters_arguments von
Mastering Python lesson 4_functions_parameters_argumentsMastering Python lesson 4_functions_parameters_arguments
Mastering Python lesson 4_functions_parameters_argumentsRuth Marvin
438 views30 Folien
CIS 407 STUDY Inspiring Innovation--cis407study.com von
CIS 407 STUDY Inspiring Innovation--cis407study.comCIS 407 STUDY Inspiring Innovation--cis407study.com
CIS 407 STUDY Inspiring Innovation--cis407study.comKeatonJennings91
16 views25 Folien
C basic questions&amp;ansrs by shiva kumar kella von
C basic questions&amp;ansrs by shiva kumar kellaC basic questions&amp;ansrs by shiva kumar kella
C basic questions&amp;ansrs by shiva kumar kellaManoj Kumar kothagulla
161 views16 Folien
Exercise1[5points]Create the following classe von
Exercise1[5points]Create the following classeExercise1[5points]Create the following classe
Exercise1[5points]Create the following classemecklenburgstrelitzh
4 views14 Folien
A brief overview of java frameworks von
A brief overview of java frameworksA brief overview of java frameworks
A brief overview of java frameworksMD Sayem Ahmed
14.4K views42 Folien
Question 1 1 pts Skip to question text.As part of a bank account.docx von
Question 1 1 pts Skip to question text.As part of a bank account.docxQuestion 1 1 pts Skip to question text.As part of a bank account.docx
Question 1 1 pts Skip to question text.As part of a bank account.docxamrit47
2 views13 Folien

Similar a Faculty of ScienceDepartment of ComputingFinal Examinati.docx(20)

Mastering Python lesson 4_functions_parameters_arguments von Ruth Marvin
Mastering Python lesson 4_functions_parameters_argumentsMastering Python lesson 4_functions_parameters_arguments
Mastering Python lesson 4_functions_parameters_arguments
Ruth Marvin438 views
CIS 407 STUDY Inspiring Innovation--cis407study.com von KeatonJennings91
CIS 407 STUDY Inspiring Innovation--cis407study.comCIS 407 STUDY Inspiring Innovation--cis407study.com
CIS 407 STUDY Inspiring Innovation--cis407study.com
KeatonJennings9116 views
A brief overview of java frameworks von MD Sayem Ahmed
A brief overview of java frameworksA brief overview of java frameworks
A brief overview of java frameworks
MD Sayem Ahmed14.4K views
Question 1 1 pts Skip to question text.As part of a bank account.docx von amrit47
Question 1 1 pts Skip to question text.As part of a bank account.docxQuestion 1 1 pts Skip to question text.As part of a bank account.docx
Question 1 1 pts Skip to question text.As part of a bank account.docx
amrit472 views
Chapter 6 - Object-Oriented ProgrammingObject-oriented pro.docx von edward6king79409
Chapter 6 - Object-Oriented ProgrammingObject-oriented pro.docxChapter 6 - Object-Oriented ProgrammingObject-oriented pro.docx
Chapter 6 - Object-Oriented ProgrammingObject-oriented pro.docx
Python mocking intro von Hans Jones
Python mocking introPython mocking intro
Python mocking intro
Hans Jones13 views
New Ideas for Old Code - Greach von HamletDRC
New Ideas for Old Code - GreachNew Ideas for Old Code - Greach
New Ideas for Old Code - Greach
HamletDRC1.1K views
Object Oriented Programming (OOP) Introduction von SamuelAnsong6
Object Oriented Programming (OOP) IntroductionObject Oriented Programming (OOP) Introduction
Object Oriented Programming (OOP) Introduction
SamuelAnsong641 views
IRJET- Implementation and Unittests of AWS, Google Storage (Cloud) and Am... von IRJET Journal
IRJET-  	  Implementation and Unittests of AWS, Google Storage (Cloud) and Am...IRJET-  	  Implementation and Unittests of AWS, Google Storage (Cloud) and Am...
IRJET- Implementation and Unittests of AWS, Google Storage (Cloud) and Am...
IRJET Journal13 views
Refactoring von nkaluva
RefactoringRefactoring
Refactoring
nkaluva511 views
OverviewAssignment 1 Hypothetical Machine SimulatorCSci 43.docx von honey690131
OverviewAssignment 1  Hypothetical Machine SimulatorCSci 43.docxOverviewAssignment 1  Hypothetical Machine SimulatorCSci 43.docx
OverviewAssignment 1 Hypothetical Machine SimulatorCSci 43.docx
honey6901315 views
Refactoring Tips by Martin Fowler von Igor Crvenov
Refactoring Tips by Martin FowlerRefactoring Tips by Martin Fowler
Refactoring Tips by Martin Fowler
Igor Crvenov24.1K views
BTE 320-498 Summer 2017 Take Home Exam (200 poi.docx von AASTHA76
BTE 320-498 Summer 2017 Take Home Exam (200 poi.docxBTE 320-498 Summer 2017 Take Home Exam (200 poi.docx
BTE 320-498 Summer 2017 Take Home Exam (200 poi.docx
AASTHA762 views
A350103 von aijbm
A350103A350103
A350103
aijbm17 views
Question 1 briefly respond to all the following questions. make von YASHU40
Question 1 briefly respond to all the following questions. make Question 1 briefly respond to all the following questions. make
Question 1 briefly respond to all the following questions. make
YASHU4097 views
Generators & Decorators.pptx von IrfanShaik98
Generators & Decorators.pptxGenerators & Decorators.pptx
Generators & Decorators.pptx
IrfanShaik9826 views

Más de mydrynan

CSIS 341Project Grading RubricCriteriaLevels of Achievem.docx von
CSIS 341Project Grading RubricCriteriaLevels of Achievem.docxCSIS 341Project Grading RubricCriteriaLevels of Achievem.docx
CSIS 341Project Grading RubricCriteriaLevels of Achievem.docxmydrynan
11 views2 Folien
CSIA 413 Cybersecurity Policy, Plans, and Programs.docx von
CSIA 413 Cybersecurity Policy, Plans, and Programs.docxCSIA 413 Cybersecurity Policy, Plans, and Programs.docx
CSIA 413 Cybersecurity Policy, Plans, and Programs.docxmydrynan
7 views9 Folien
CSIA 300 Cybersecurity for Leaders and ManagersResearch Report #1.docx von
CSIA 300 Cybersecurity for Leaders and ManagersResearch Report #1.docxCSIA 300 Cybersecurity for Leaders and ManagersResearch Report #1.docx
CSIA 300 Cybersecurity for Leaders and ManagersResearch Report #1.docxmydrynan
10 views4 Folien
CSIS 100CSIS 100 - Discussion Board Topic #1One of the object.docx von
CSIS 100CSIS 100 - Discussion Board Topic #1One of the object.docxCSIS 100CSIS 100 - Discussion Board Topic #1One of the object.docx
CSIS 100CSIS 100 - Discussion Board Topic #1One of the object.docxmydrynan
5 views543 Folien
CSI Paper Grading Rubric- (worth a possible 100 points) .docx von
CSI Paper Grading Rubric- (worth a possible 100 points)   .docxCSI Paper Grading Rubric- (worth a possible 100 points)   .docx
CSI Paper Grading Rubric- (worth a possible 100 points) .docxmydrynan
4 views4 Folien
CSIA 413 Cybersecurity Policy, Plans, and ProgramsProject #4 IT .docx von
CSIA 413 Cybersecurity Policy, Plans, and ProgramsProject #4 IT .docxCSIA 413 Cybersecurity Policy, Plans, and ProgramsProject #4 IT .docx
CSIA 413 Cybersecurity Policy, Plans, and ProgramsProject #4 IT .docxmydrynan
14 views4 Folien

Más de mydrynan(20)

CSIS 341Project Grading RubricCriteriaLevels of Achievem.docx von mydrynan
CSIS 341Project Grading RubricCriteriaLevels of Achievem.docxCSIS 341Project Grading RubricCriteriaLevels of Achievem.docx
CSIS 341Project Grading RubricCriteriaLevels of Achievem.docx
mydrynan11 views
CSIA 413 Cybersecurity Policy, Plans, and Programs.docx von mydrynan
CSIA 413 Cybersecurity Policy, Plans, and Programs.docxCSIA 413 Cybersecurity Policy, Plans, and Programs.docx
CSIA 413 Cybersecurity Policy, Plans, and Programs.docx
mydrynan7 views
CSIA 300 Cybersecurity for Leaders and ManagersResearch Report #1.docx von mydrynan
CSIA 300 Cybersecurity for Leaders and ManagersResearch Report #1.docxCSIA 300 Cybersecurity for Leaders and ManagersResearch Report #1.docx
CSIA 300 Cybersecurity for Leaders and ManagersResearch Report #1.docx
mydrynan10 views
CSIS 100CSIS 100 - Discussion Board Topic #1One of the object.docx von mydrynan
CSIS 100CSIS 100 - Discussion Board Topic #1One of the object.docxCSIS 100CSIS 100 - Discussion Board Topic #1One of the object.docx
CSIS 100CSIS 100 - Discussion Board Topic #1One of the object.docx
mydrynan5 views
CSI Paper Grading Rubric- (worth a possible 100 points) .docx von mydrynan
CSI Paper Grading Rubric- (worth a possible 100 points)   .docxCSI Paper Grading Rubric- (worth a possible 100 points)   .docx
CSI Paper Grading Rubric- (worth a possible 100 points) .docx
mydrynan4 views
CSIA 413 Cybersecurity Policy, Plans, and ProgramsProject #4 IT .docx von mydrynan
CSIA 413 Cybersecurity Policy, Plans, and ProgramsProject #4 IT .docxCSIA 413 Cybersecurity Policy, Plans, and ProgramsProject #4 IT .docx
CSIA 413 Cybersecurity Policy, Plans, and ProgramsProject #4 IT .docx
mydrynan14 views
CSIA 300 Cybersecurity for Leaders and ManagersCase Study #2 Dat.docx von mydrynan
CSIA 300 Cybersecurity for Leaders and ManagersCase Study #2 Dat.docxCSIA 300 Cybersecurity for Leaders and ManagersCase Study #2 Dat.docx
CSIA 300 Cybersecurity for Leaders and ManagersCase Study #2 Dat.docx
mydrynan2 views
CSE422 Section 002 – Computer Networking Fall 2018 Go-Ba.docx von mydrynan
CSE422 Section 002 – Computer Networking Fall 2018 Go-Ba.docxCSE422 Section 002 – Computer Networking Fall 2018 Go-Ba.docx
CSE422 Section 002 – Computer Networking Fall 2018 Go-Ba.docx
mydrynan2 views
CSE2CSE5ALG– Algorithms and Data Structures – 2020 Assignme.docx von mydrynan
CSE2CSE5ALG– Algorithms and Data Structures – 2020 Assignme.docxCSE2CSE5ALG– Algorithms and Data Structures – 2020 Assignme.docx
CSE2CSE5ALG– Algorithms and Data Structures – 2020 Assignme.docx
mydrynan8 views
CSE422 Section 002 – Computer Networking Fall 2018 Ho.docx von mydrynan
CSE422 Section 002 – Computer Networking Fall 2018  Ho.docxCSE422 Section 002 – Computer Networking Fall 2018  Ho.docx
CSE422 Section 002 – Computer Networking Fall 2018 Ho.docx
mydrynan10 views
CSD 212 Case Study #2NOTE DO NOT submit your completed assign.docx von mydrynan
CSD 212 Case Study #2NOTE DO NOT submit your completed assign.docxCSD 212 Case Study #2NOTE DO NOT submit your completed assign.docx
CSD 212 Case Study #2NOTE DO NOT submit your completed assign.docx
mydrynan8 views
CSCI  132  Practical  Unix  and  Programming   .docx von mydrynan
CSCI  132  Practical  Unix  and  Programming   .docxCSCI  132  Practical  Unix  and  Programming   .docx
CSCI  132  Practical  Unix  and  Programming   .docx
mydrynan6 views
CSdue   New York, December 7 at 11 pm1.10deductionThe o.docx von mydrynan
CSdue   New York, December 7 at 11 pm1.10deductionThe o.docxCSdue   New York, December 7 at 11 pm1.10deductionThe o.docx
CSdue   New York, December 7 at 11 pm1.10deductionThe o.docx
mydrynan2 views
CSCI 714 Software Project Planning and EstimationLec.docx von mydrynan
CSCI 714 Software Project Planning and EstimationLec.docxCSCI 714 Software Project Planning and EstimationLec.docx
CSCI 714 Software Project Planning and EstimationLec.docx
mydrynan4 views
CSCI 611 Lab Rubric (100 pts)CriteriaLevels of Achievement.docx von mydrynan
CSCI 611 Lab Rubric (100 pts)CriteriaLevels of Achievement.docxCSCI 611 Lab Rubric (100 pts)CriteriaLevels of Achievement.docx
CSCI 611 Lab Rubric (100 pts)CriteriaLevels of Achievement.docx
mydrynan2 views
CSCI 561Research Paper Topic Proposal and Outline Instructions.docx von mydrynan
CSCI 561Research Paper Topic Proposal and Outline Instructions.docxCSCI 561Research Paper Topic Proposal and Outline Instructions.docx
CSCI 561Research Paper Topic Proposal and Outline Instructions.docx
mydrynan2 views
CSCI 490503 - Professional Reflection Assignment 30 Points.docx von mydrynan
CSCI 490503 - Professional Reflection Assignment     30 Points.docxCSCI 490503 - Professional Reflection Assignment     30 Points.docx
CSCI 490503 - Professional Reflection Assignment 30 Points.docx
mydrynan2 views
CSCI 561 DB Standardized Rubric50 PointsCriteriaLevels of .docx von mydrynan
CSCI 561 DB Standardized Rubric50 PointsCriteriaLevels of .docxCSCI 561 DB Standardized Rubric50 PointsCriteriaLevels of .docx
CSCI 561 DB Standardized Rubric50 PointsCriteriaLevels of .docx
mydrynan2 views
CSCI 415 TERM PAPER TOPICS SELECTION – Fall 2019 Due Monday, S.docx von mydrynan
CSCI 415 TERM PAPER TOPICS SELECTION – Fall 2019 Due Monday, S.docxCSCI 415 TERM PAPER TOPICS SELECTION – Fall 2019 Due Monday, S.docx
CSCI 415 TERM PAPER TOPICS SELECTION – Fall 2019 Due Monday, S.docx
mydrynan2 views
CSCI 415 TERM PAPER TOPICS SELECTION – Spring 2019Due Monday, Fe.docx von mydrynan
CSCI 415 TERM PAPER TOPICS SELECTION – Spring 2019Due Monday, Fe.docxCSCI 415 TERM PAPER TOPICS SELECTION – Spring 2019Due Monday, Fe.docx
CSCI 415 TERM PAPER TOPICS SELECTION – Spring 2019Due Monday, Fe.docx
mydrynan2 views

Último

ISO/IEC 27001 and ISO/IEC 27005: Managing AI Risks Effectively von
ISO/IEC 27001 and ISO/IEC 27005: Managing AI Risks EffectivelyISO/IEC 27001 and ISO/IEC 27005: Managing AI Risks Effectively
ISO/IEC 27001 and ISO/IEC 27005: Managing AI Risks EffectivelyPECB
623 views18 Folien
Gross Anatomy of the Liver von
Gross Anatomy of the LiverGross Anatomy of the Liver
Gross Anatomy of the Liverobaje godwin sunday
61 views12 Folien
Structure and Functions of Cell.pdf von
Structure and Functions of Cell.pdfStructure and Functions of Cell.pdf
Structure and Functions of Cell.pdfNithya Murugan
719 views10 Folien
The basics - information, data, technology and systems.pdf von
The basics - information, data, technology and systems.pdfThe basics - information, data, technology and systems.pdf
The basics - information, data, technology and systems.pdfJonathanCovena1
146 views1 Folie
Education and Diversity.pptx von
Education and Diversity.pptxEducation and Diversity.pptx
Education and Diversity.pptxDrHafizKosar
193 views16 Folien
Recap of our Class von
Recap of our ClassRecap of our Class
Recap of our ClassCorinne Weisgerber
88 views15 Folien

Último(20)

ISO/IEC 27001 and ISO/IEC 27005: Managing AI Risks Effectively von PECB
ISO/IEC 27001 and ISO/IEC 27005: Managing AI Risks EffectivelyISO/IEC 27001 and ISO/IEC 27005: Managing AI Risks Effectively
ISO/IEC 27001 and ISO/IEC 27005: Managing AI Risks Effectively
PECB 623 views
Structure and Functions of Cell.pdf von Nithya Murugan
Structure and Functions of Cell.pdfStructure and Functions of Cell.pdf
Structure and Functions of Cell.pdf
Nithya Murugan719 views
The basics - information, data, technology and systems.pdf von JonathanCovena1
The basics - information, data, technology and systems.pdfThe basics - information, data, technology and systems.pdf
The basics - information, data, technology and systems.pdf
JonathanCovena1146 views
Education and Diversity.pptx von DrHafizKosar
Education and Diversity.pptxEducation and Diversity.pptx
Education and Diversity.pptx
DrHafizKosar193 views
Drama KS5 Breakdown von WestHatch
Drama KS5 BreakdownDrama KS5 Breakdown
Drama KS5 Breakdown
WestHatch98 views
Psychology KS4 von WestHatch
Psychology KS4Psychology KS4
Psychology KS4
WestHatch98 views
Use of Probiotics in Aquaculture.pptx von AKSHAY MANDAL
Use of Probiotics in Aquaculture.pptxUse of Probiotics in Aquaculture.pptx
Use of Probiotics in Aquaculture.pptx
AKSHAY MANDAL119 views
Psychology KS5 von WestHatch
Psychology KS5Psychology KS5
Psychology KS5
WestHatch119 views
Dance KS5 Breakdown von WestHatch
Dance KS5 BreakdownDance KS5 Breakdown
Dance KS5 Breakdown
WestHatch99 views
The Accursed House by Émile Gaboriau von DivyaSheta
The Accursed House  by Émile GaboriauThe Accursed House  by Émile Gaboriau
The Accursed House by Émile Gaboriau
DivyaSheta223 views
REPRESENTATION - GAUNTLET.pptx von iammrhaywood
REPRESENTATION - GAUNTLET.pptxREPRESENTATION - GAUNTLET.pptx
REPRESENTATION - GAUNTLET.pptx
iammrhaywood138 views
Narration lesson plan von TARIQ KHAN
Narration lesson planNarration lesson plan
Narration lesson plan
TARIQ KHAN61 views

Faculty of ScienceDepartment of ComputingFinal Examinati.docx

  • 1. Faculty of Science Department of Computing Final Examination 2013 Unit: COMP229 Object Oriented Programming Practices Release Date: 9:00am, November 15, 2013 Due Date: 11:45pm, November 19, 2013 Total Number of Questions: Six (6) Total Marks: Sixty Four (68) Instructions: Answer ALL questions. All references to program code or behaviour refer to the Java language. All answers to questions that ask for code must be written using Java. Every attempt has been made to make questions unambiguous. However, if you are not sure what a question is asking, make some reasonable assumption and state it at the beginning of your answer. COMP229 Object Oriented Programming Practices, November
  • 2. 2013 Question 1 (Design Patterns, 5 marks) The template method pattern and the strategy pattern both abstract some computation in the form of methods. What defining characteristic distinguishes the template method patern from the strategy pattern? Explain your answer. [5 marks] Question 2 (Concurrency, 12 marks) Consider the following class definition. This class is considered to be in an inconsistent state if the isConsistent() method returns falsefalsefalse; publicpublicpublic classclassclass Foo { longlonglong mValue; longlonglong mValueTimesTwo; /** * Sets the state of our object. * * Pauses briefly between setting the first and second * values in order to increase the probability that the * object will be interrogated while in an inconsistent * state.
  • 3. * * @param pValue the value to update the current state with , */ publicpublicpublic synchronizedsynchronizedsynchronized voidvoidvoid setValues(longlonglong pValue) { mValue = pValue; doPause (3); mValueTimesTwo = pValue * 2; } /** * Checks to see if the current state of our object is * consistent. * * @return true if it is. */ publicpublicpublic synchronizedsynchronizedsynchronized booleanbooleanboolean isConsistent () { returnreturnreturn (mValue * 2 == mValueTimesTwo ); }
  • 4. /** * Utility routine - pauses our thread by calling * sleep and supressing any InterruptedException. */ privateprivateprivate staticstaticstatic voidvoidvoid doPause(longlonglong pPause) { trytrytry { Thread.sleep(pPause ); } catchcatchcatch (InterruptedException e) { e.printStackTrace (); } } } Page 1 of 5 COMP229 Object Oriented Programming Practices, November 2013 a. Imagine a hypothetical version of Java where the object lock is replaced by a method lock. Under this system a call to a synchronised method would assign a lock for that
  • 5. method to the calling thread. No other thread could then call this method because the lock is already allocated. However, other methods of the same object could still be called. Upon the method completing, the lock is released. Under this system, is it possible to put an instance of the Foo class into an inconsistant state? If so, give a code example which could create this situation and explain how it does so. If not, explain how the method lock prevents the possibility of inconsistent state. [7 marks] b. Provide one possible motivation for choosing this hypothetical method lock over an object lock. Explain your answer. [5 marks] Question 3 (Generics, 15 marks) Consider the following interface definition /** * This is an interface which abstracts the concept of a * function. The interface has methods for a number of * possible function call styles. * * @param <T> The type over which these functions work. **/ publicpublicpublic interfaceinterfaceinterface Functions <T> {
  • 6. /** * A function which does not return a value * * @param in The parameter to this function **/ publicpublicpublic abstractabstractabstract voidvoidvoid doIt(T in); /** * A function which turns a T into an integer * * @param in The parameter to this function **/ publicpublicpublic abstractabstractabstract intintint calculate(T in); /** * A function which turns a T into an String * * @param in The parameter to this function **/
  • 7. publicpublicpublic abstractabstractabstract String show(T in); /** * A function which creates a T based on an integer * * @param in The parameter to this function **/ publicpublicpublic abstractabstractabstract T generate(intintint in); /** * This function , called "transform" returns a value of the same type * as the parameter it was given. Page 2 of 5 COMP229 Object Oriented Programming Practices, November 2013 * * @param in The parameter to this function * @return A value of the same type as the input parameter
  • 8. **/ // FIXME: Write this method signature } a. This interface is part of an implementation of a design pattern. Which design pattern is it from? Give the standard class diagram for the pattern and identify which part of the pattern is being implemented with the above interface. [6 marks] b. How does this instance of the pattern differ from the standard version? [2 marks] c. The final method signature has been left out. Write what you think that signature should be. [7 marks] Question 4 (Refactoring, 16 marks) Consider the following class definition. It is not necessary that you know anything about the system from which this class was taken, nor is it necessary to know anything about the classes Expr, Number or Boolean. publicpublicpublic classclassclass Infer <T> { Expr <T> expr; publicpublicpublic Infer(Expr <T> e){ expr = e;
  • 9. } /** * @param inferenceType The type of inference to perform. * 0 is simple inference , 1 is polymorphic inference , * 2 is explicit inference. **/ publicpublicpublic booleanbooleanboolean doInference(intintint inferenceType ){ ififif (inferenceType == 0) ififif (expr.isVal ()) ififif (expr.isDefined ()) returnreturnreturn truetruetrue; elseelseelse returnreturnreturn falsefalsefalse; elseelseelse ififif (expr.isPlus ()){ returnreturnreturn (newnewnew Infer <Number >(expr.left )). doInference(inferenceType) && (newnewnew Infer <Number >(expr.right )). doInference(inferenceType ); }
  • 10. elseelseelse ififif (expr.isMinus ()){ returnreturnreturn (newnewnew Infer <Number >(expr.left )). doInference(inferenceType) && (newnewnew Infer <Number >(expr.right )). doInference(inferenceType ); } elseelseelse ififif(expr.isAnd ()){ returnreturnreturn (newnewnew Infer <Boolean >(expr.left )). doInference(inferenceType) && (newnewnew Infer <Boolean >(expr.right )). doInference(inferenceType ); } elseelseelse ififif(inferenceType == 1) ififif (expr.isVal ()) Page 3 of 5 COMP229 Object Oriented Programming Practices, November 2013 ififif (expr.isDefined ()) returnreturnreturn falsefalsefalse;
  • 11. elseelseelse returnreturnreturn truetruetrue; elseelseelse ififif (expr.isPlus ()){ returnreturnreturn (newnewnew Infer <Number >(expr.left )). doInference(inferenceType) && (newnewnew Infer <Number >(expr.right )). doInference(inferenceType ); } elseelseelse ififif (expr.isMinus ()){ returnreturnreturn (newnewnew Infer <Number >(expr.left )). doInference(inferenceType) && (newnewnew Infer <Number >(expr.right )). doInference(inferenceType ); } elseelseelse ififif(expr.isAnd ()){ returnreturnreturn (newnewnew Infer <Boolean >(expr.left )). doInference(inferenceType) && (newnewnew Infer <Boolean >(expr.right )). doInference(inferenceType ); } elseelseelse
  • 12. returnreturnreturn truetruetrue; } } a. Identify as many code smells as you can in the above class. Hint: There are at least two. [6 marks] b. Refactor the class to remove all the code smells you identified. Give the full definition of your refactored class and an explanation of the refactorings you performed. [10 marks] Question 5 (Design Patterns, 8 marks) (a) There is something wrong with the following instance of the Template Method pattern. Explain what is wrong. Modify the system so that it conforms to the pattern. Explain each of the changes you made to the system. Draw the class diagram for your modified system. [8 marks] Page 4 of 5 COMP229 Object Oriented Programming Practices, November 2013 Question 6 (Testing, 12 marks)
  • 13. (a) The following diagram shows the classes used in a calculator application. This cal- culator application can do addition, multiplication, powers, logarithms, factorials and permutations. Some of these calculations can take a long time on the low-powered de- vice on which it is designed to run. For this reason, the calculator takes each calculation it is asked to do and sends it over the internet to a supercomputer for computation as well as attempting to calculate it locally. If the supercomputer returns the result faster than the program can calculate it, it uses that result. Furthermore, the computer on which this application is running has a large amount of memory, so the application will store all the calculations it has already performed in a database. If it is asked to do a calculation it has done before, it uses the value it has stored in the database. This database can store 100,000 results before it is full and when it is full the calculator will have to do any new calculations every time they are requested. At least the database class will need to be stubbed with mock objects for testing be- cause you need to test for empty, partially full, and completely full databases. Which other classes do you think will need to be stubbed with mock objects for testing the application? For each class you identify explain why you think that class needs mocking and at least three different mocked behaviours you will need. [12 marks]
  • 14. END OF EXAMINATION Page 5 of 5 • 2- Topic Selection Please post the topic you plan to explore. Include why you selected it and how it impacts your profession. Your submission should be at least 250 words after which you must comment to at least two of your peers. At the end of the discussion, you will be asked to craft a 150 word reflection on what you have learned through this conversation and post it to the Weekly Reflection Journal. The more active you are in this part of the discussion, the more you will have to draw from in your reflection, so get involved, be active, help out your classmates when they need it, and, most of all, enjoy the conversation • 3- Discipline Areas (Bodies of Knowledge) The following topic(s) will demonstrate what the discussion is about, but feel free to branch off or expand on the topics. At the end of the discussion, you will be asked to craft a 150 word reflection on what you have learned through this conversation and post it to the Weekly Reflection Journal. The more active you are in this part of the discussion, the more you will have to draw from in your reflection, so get involved, be active, help out your classmates when they need it, and, most of all, enjoy the conversation. Your research paper must address a profession-related issue from at least two discipline perspectives. Please discuss the following questions about your proposed project: • How do the two areas you have selected relate to the issue? • How do they appear to overlap? • What challenges have you encountered so far in finding information relevant to your topic and how will you address those challenges? After you have posted your
  • 15. discussion, please comment to at least two of your peers. • • 4- Discoveries (So Far) The following topic(s) will demonstrate what the discussion is about, but feel free to branch off or expand on the topics. At the end of the discussion, you will be asked to craft a 150 word reflection on what you have learned through this conversation and post it to the Weekly Reflection Journal. The more active you are in this part of the discussion, the more you will have to draw from in your reflection, so get involved, be active, help out your classmates when they need it, and, most of all, enjoy the conversation. Using the mind mapping and article evaluations completed in W3, discuss two things that surprised you regarding your topic. Additionally, are you on track with your topic or have you discovered that you may need to make some changes? Why or why not? Please respond to at least two of your colleagues • 5- Self-Evaluation of Your Paper The following topic(s) will demonstrate what the discussion is about, but feel free to branch off or expand on the topics. At the end of the discussion, you will be asked to craft a 150 word reflection on what you have learned through this conversation and post it to the Weekly Reflection Journal. The more active you are in this part of the discussion, the more you will have to draw from in your reflection, so get involved, be active, help out your classmates when they need it, and, most of all, enjoy the conversation. Using the checklist on p. 130 of the text, evaluate your first draft. Discuss the strengths and weaknesses you found regarding your own writing and how you plan to build upon and/or improve what you discovered. Please respond (or give advice) to at least two of your peers. • 6- Enhancing the Paper The following topic(s) will demonstrate what the discussion is about, but feel free to branch off or expand on the topics. At the
  • 16. end of the discussion, you will be asked to craft a 150 word reflection on what you have learned through this conversation and post it to the Weekly Reflection Journal. The more active you are in this part of the discussion, the more you will have to draw from in your reflection, so get involved, be active, help out your classmates when they need it, and, most of all, enjoy the conversation. Having written the first draft of your paper (and using the article review worksheet completed in W3), please discuss the following issues related to your topic: • What are some potential ethical issues that must be considered? • How might this issue impact different communities from diverse perspectives? (For example, are there differences based on age, gender, economics, political, ethnic, religious, educational or geographic?) Please respond to at least two of your peers. • • 7- Using My Research The following topic(s) will demonstrate what the discussion is about, but feel free to branch off or expand on the topics. At the end of the discussion, you will be asked to craft a 150 word reflection on what you have learned through this conversation and post it to the Weekly Reflection Journal. The more active you are in this part of the discussion, the more you will have to draw from in your reflection, so get involved, be active, help out your classmates when they need it, and, most of all, enjoy the conversation. Discuss how (or if) what you have discovered has (or will) change your role within the communities in which you are a member. Why or why not? Please respond to at least two of your colleagues. • 8- Abstract of Paper The following topic(s) will demonstrate what the discussion is
  • 17. about, but feel free to branch off or expand on the topics. At the end of the discussion, you will be asked to craft a 150 word reflection on what you have learned through this conversation and post it to the Weekly Reflection Journal. The more active you are in this part of the discussion, the more you will have to draw from in your reflection, so get involved, be active, help out your classmates when they need it, and, most of all, enjoy the conversation. Please summarize the findings of your paper and discuss how you will use what you have discovered in your profession and in the future.