Java代写-AUGUST 2020
时间:2021-01-13
EXAMINER : Mr Sebastian Coope
DEPARTMENT: Computer Science











AUGUST 2020 EXAMINATIONS ANSWERS



COMP319 : SOFTWARE ENGINEERING II
ANSWERS ANSWERS ANSWERS



TIME ALLOWED : Two and a Half Hours



INSTRUCTIONS TO CANDIDATES

Answer ALL questions in Section A

(Section A is worth 70%)

Answer One question from Section B

(Section B is worth 30%)

You MAY use a calculator in this exam

If you attempt to answer more than the required number of questions in Section B the
marks awarded for the excess questions will be discarded starting with the lowest mark.
PAPER CODE NO.
COMP 319
August 2020 The University of Liverpool

Paper Code : COMP319 Page 2 of 9



Page 1 of 4b

Answer ALL questions in the exam

A1 Look at the following description for a Java class used as a document checker.
The class is used to open and process documents in a number of different
formats, for example docx or ASCII text.
For each document it needs to be able to:
a) Count the words in the document
b) Spell check the document returning a list of the words that it thinks are in
error and for each word its line and column number in the document.
The code should support the following methods and attributes:

String lines[]; // Attribute contents of the document
void open(String documentFileName)
// Tries to open the document for processing
// It then processes the document into an array of
// Strings, in attribute lines (see above)
// each string is a line in the document

// This will throw an exception if the file does not exist
// It will throw an exception if the file is in the wrong format

tnt countWords() // Returns the number of words in the document

SpellingMistakes [] spellcheck() // Spell checks the document and returns

// the mistakes

SpellingMistake is a class partially defined as follows

public class SpellingMistake {
private String word;
private int row;
print int column;
}

You should complete this class with constructors, getters and setters as part of
your solution.








August 2020 The University of Liverpool

Paper Code : COMP319 Page 3 of 9




i) Explain with the aid of class diagrams and simple code examples how
the Factory pattern could be used to design this code. In your answer
include a description of the Factory pattern [10 Marks], class diagrams
showing your solution [15 Marks] and code examples in Java [15
Marks[. The code examples do not have to show the internal workings
of the methods. For your example assume there are 3 document
formats, pdf, docx and txt. Your factory should produce a different
concrete class for each format. Make sure your solution correctly
follows the Myers open/closed principle.
You will need in your solution, an interface definition, an abstract class
definition and 3 concrete class definitions.

Marking crtieria
Collect description of Factory pattern.
[10 Marks[
Correct class diagram showing correct location of methods given in
question. Diagram needs to show correct interface [5 Marks], correct
abstract class definition including getInstance methods and correct
definition for concrete classes. [5 Marks]
Good code including correct placement of final keywords to ensure
correct closure and good use of open extension. [15 Marks]

Description of Factory pattern
The factory pattern is used then an objects exact type is no know at compile time but
will ideally be decided later on at run time. [2 Marks[ Consider the example of
processing an image file to create an image object in memory. The image file could be
in PNG image, JPG image or a BMP
image format. Since the ideally you need to use an appropriate class for each of these
images,
so you code might look like this.
ImageBMP image1=new ImageBMP(“image1.bmp”);
ImagePNG image2=new ImagePNG(“image1.png”);
ImageJPG image1=new ImageJPG(“image1.jpg”);
[4 Marks[
This code is clumsy and of course will not work if we don’t know the type of the image
file before the program is running.
The answer to this problem is to create an abstract class which supports the general
interface
of Images but is not specific to any particular type. So it will have methods such as
getWidth
and getHeight which will apply to all image files.
abstract class Image() {
private int width,height;
int getWidth() {
return(width);
}
August 2020 The University of Liverpool

Paper Code : COMP319 Page 4 of 9
int getHeight() {
return(height);
}
}
[2 Marks[







COMP319 University of Liverpool Notes





The image types will inherit from this super class, for example.
public class ImagePNG extends Image {
}
public class ImageJPG extends Image {
}
To create the class, a static method is added to the Image abstract class.
public abstract class Image {
private int height,width;

public int getWidth() {
return(width);
}

public int getHeight() {
return(height);
}

public static Image getInstance(String fileName) throws Exception {
if (fileName.endsWith(".png")) {
return( (Image)new ImagePNG(fileName));
}
if (fileName.endsWith(".bmp")) {
return( (Image)new ImageBMP(fileName));
}
if (fileName.endsWith(".jpg")) {
return( (Image)new ImageJPG(fileName));
}


throw new Exception("File type not supported for "+fileName);

}
August 2020 The University of Liverpool

Paper Code : COMP319 Page 5 of 9

}
[2 Marks]
Class diagram for document checker 15 Marks in total

























Code examples

public interface IDocumentChecker { // 3 Marks
public void open(String filename) throws Exception FileNotFound,
BadFormatException;
public int countWords();
public SpellingMistake [] spellcheck();
}

public abstract class DocumentChecker implements IDocumentChecker { // 6 Marks

protected String lines[[; // stores content of document

protected DocumentChecker(String fname) {
open(fname);
}

protected processDocument(FileInputStream fis) throws BadFormatException;


public final void open(String filename) throws Exception FileNotFound,
IDocumentChecker 3 Marks
+open() : void
+countWords(): int
spellcheck() : SpellingMistake[]


i
DocumentChecker 6 Marks
-lines : String []
+open(String fname) void
+icountWords() int
+spellcheck() : SpellingMistake[];
+getInstance() : DocumentChecker





DocumentCheckerDoc
1 Mark DocumentCheckerText
1 Mark
DocumentCheckerPDF
1 Mark
SpellingMistake 3 Marks

-word : String
-row : int
=column : int


August 2020 The University of Liverpool

Paper Code : COMP319 Page 6 of 9
BadFormatException {
FileInputStream fis=new FileInputStream(filename);
ProcessDocument(fis); // concreate class parses document

}

public static IDocumentChecker getInstance(String filename) {
if (filename.endsWith(“.pdf”) {
return(new DocumentCheckerPDF(filename);
}
if (filename.endsWith(“.doc”) {
return(new DocumentCheckerDoc(filename);
}
if (filename.endsWith(“.txt”) {
return(new DocumentCheckerTex(filename);
}

}
}

public class DocumentCheckerPDF extends DocumentChecker { // 1 Mark
processDocument(FileinputStream fis) throws BadFormatException {
// TO DO method body parse PDF document
}
protected DocumentCheckerPDF(String fname) {
super(fname);
}

}

public class DocumentCheckerTex extends DocumentChecker { // 1 Mark
processDocument(FileinputStream fis) throws BadFormatException {
// TO DO method body parse ASCII document
}
protected DocumentCheckerTex(String fname) {
super(fname);
}

}

public class DocumentCheckerDoc extends DocumentChecker { // 1 Mark
processDocument(FileinputStream fis) throws BadFormatException {
// TO DO method body parse Doc document
}

protected DocumentCheckerDoc(String fname) {
super(fname);
}
}
public class SpellingMistake { // 3 Marks
August 2020 The University of Liverpool

Paper Code : COMP319 Page 7 of 9
private String word;
private int row;
private int column;

public String getWord() {
return(word);
}
public int getRow() {
return(row);
}
public int getColumn() {
return(column);
}
public SpellingMistake(String w,int r, int c) {
word=w;row=r;column=c;
}

}




A2 You have been asked by your manager to improve the cost estimation
approach for the software development department. Often the estimates are
widely under the actual time or a lot over it. He has told you he has heard about
EQF and Poker planning. Write a short summary of the how these can be used
to applied to improve the estimation approach in the department.
(Maximum word count 300 words)
[30 Marks]
Correct description of what EQF is and how it can be applied to measuring
and improving estimation. [15 Marks]
Estimation quality factor is a technique used to determine the quality of your
estimation.
High estimation factors means a very accurate estimate with little deviation
from the actual delivery time of the project. So an EQF of greater than 10
means that on average the estimates will be less than 10% different the actual
project.
To calculate EQF we measure the average deviance of the estimates from the
actual delivery time. We when divide the final delivery time by this average
deviance. So for example if the delivery time was 10 weeks and we had the
following estimations, 5, 9 and 12 weeks. The deviances would be 5, 1 and 2
and the average would be 8/3 or 2.33333. To ge the EQF we divide 10 by this
number to get 3.75.
Low EQF could be the result of a wide range of factors including: Poor
estimation skills
Lack of knowledge about the project when the estimation was done
Pressure from others to produce for example a low estimate (pressure from
management). By measuring the EQF we can measure how well we are
performing that which techniques are improving are performance.

August 2020 The University of Liverpool

Paper Code : COMP319 Page 8 of 9

Correct description of Poker planning and explanation of how it can be
used to improve classical estimation techniques. For full marks have clear
commentary on problems of under and over estimation issues. [15 Marks]
Poker planning
What is poker planning?
Poker planning is a cost estimation technique which uses the combined knowledge of
a group of people working together to generate estimates. It is commonly used by
Agile developers and SCRUM
teams. Each member of development team given pack of cards with numbers on,
(sometimes playing cards are used) . Then project manager explains the project and
the team can then ask questions to clarify and assumptions with the project and
discuss any possible risks. Then each
member picks a card from their pack as their estimate and puts it face down, then all
members show their cards at the same time. The members with the lowest and highest
estimation members are then given a chance to justify their decision to the whole
group. The whole process continues until a consensus is reached, typically the
developer(s) who will be responsible for the project, will get a
larger share of the vote than others.

Benefits and anchoring
Planning poker has been found to help avoid problem called anchoring. Anchoring is
where in an
open discussion some members of the team may strongly advocate a particular time
estimate and
this persuades other team members to follow their lead. Low anchors i.e. low
estimations will
generally come from sales marketing or other product owners. High anchors
(sometimes overly
pessimistic) will generally come from development team members. A study on
planning poker [K.
Molokken-Ostvold and N.C. Haugen] has found that estimates were less optimistic
and more
accurate than ones obtained through the simple combination of individual estimates
for the same
tasks.


A3 Write a short summary reviewing the evidence on the usefulness of Pair
programming. For this exam you can limit your review to the following
researchers Laurie Williams, Jo Erskine Hannay and Arisholm, Gallis and
Sjøberg.
(Maximum word count 300 words) [30 Marks[

Looking at the research shows fairly inconclusive results for pair programming in
terms of its benefits, we can compare studies of Arisholm, Gallis and Sjøberg
and Laurie Williams of the University of Utah.
The Williams et al. 2000 study showed that using pair programming there was a
decrease in time to
develop between 15% and 30% but this did require an increase in effort (programmer
August 2020 The University of Liverpool

Paper Code : COMP319 Page 9 of 9
hours) between
15 to 60% with an increased in correctness of 15%. The improvement in correctness
would be important
for projects with highly critical quality criteria such as safety critical applications for
example in a
healthcare environment or vehicle control.
Arisholm, Gallis and Sjøberg carried out research to determine how effective pair
programming was in
different contexts, for example with complex and relatively simple problems and with
different
combinations of staff skilling. They used a fixed set of problems and split the
developers into a pairing
group and a single programming group. They found that for most tasks the time taken
was not
significantly different when using a pair programming on average 84%, the amount
of time was reduced
but not by a large amount on average a reduction of 8%, however if the pairs were
junior the increase in
effort was much larger and the 111% and the time taken was larger as well.
There was however a positive outcome in terms of correct solutions found overall of
7% and 73% for
juniors.
One of the most interesting studies was a meta-analysis of many studies carried out
by Jo E. Hannay et
al. This showed small reductions in time (depending on the task complexity, less
complex tasks have an
improved time greater than complex tasks. They also showed that pair programming
produces higher
quality results for more complex problems. They also discovered a research bias in
favour of
pair-programming by some of the leading researchers in the area.



































































































































































































































































































































































































































































































essay、essay代写