Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

COM00016C

2020-2021

Computer Science

Software 2 - Practical

1        (70 marks)     Object Oriented Programming

The code must be written in the provided file PouleSheet.java. Failing to do so may result in a mark of 0%.

The aim of the question is to implement a class simulating a fencing poule sheet. An example of an empty poule sheet for four competitors is shown in Figure 1.

 

Figure 1: Example of an empty fencing poule sheet for four competitors.

The columns are as follow:

  Name contains the name of the competitor

  # contains the number, allocated to each competitor in this poule,

  V contains the numbers of victory for that competitor,

  HS contains the number of hits he scored against his/her opponents,

•  HR record the number of hits s/he received,

•  Diff is the difference between HS and HR, that is Dif f = HS - HR.

•  Pl. is the place or ranking of the competitor once all the poule’s bouts (matches) are finished.

The cells within columns 1 - 4 contain the number of hits a competitor scored against another

fencer. For example, if competitor #1 scored 3 hits against competitor #4, the cell in row numbered 1 and column numbered 4 contains the value 3.

(i)       [15 marks]     The class PouleSheet contains the following instance attributes with package

visibility:

•  int  pouleNumber is the poule number. During a competiton there might be more than one poule, so we need to number them.

•  int  pouleSize representing the number of competitors in the poule.

•  String[]  competitors an array containing the names of the competitors, with the name of the competitor #1 at index 0, competitor #2 at index 1, and so on.

•  int[][]  results records the number of hits a competitor scored against another fencer. The number of hits competitor #1 scored against competitor #4 is stored in       results[0][3].

(a)  [3 marks]     Implement the instance attributes of the class PouleSheet.             (b)  [2 marks]     Implement a public class constant int  HITS_FOR_WIN of value 5.

(c)  [10 marks]     Implement a public constructor having the following parameters:

•  an int  number representing the poule number,

  an int  size representing the number of competitors in this poule.

The constructor should initialise the instance attributes as follow.

•  the poule number to number.

  competitors should be of length size, and all values should be null.

•  results a 2D array of dimension size xsize, where all values are -1.

The constructor should throw an IllegalArgumentException if size< 3 or size> 8.

(ii)      [5 marks]     Implement the public method boolean  addCompetitor(String  name)  that adds the competitor to the next available slots. The method should return false if the       operation is unsuccessful, that is if the poule is already full or if the name is already in the poule. Otherwise, the method should return true.

(iii)     [10 marks]     Implement a checked exception InvalidScoreException. The class has two constructors, the default constructor that must call the super class default constructor.        Similarly, the second constructor has only one parameter of type String and must call the super class constructor having only a String parameter. You do not need to implement any method    other than the two constructors described in this question.

(iv)     [10 marks]     A competitor wins a bout when s/he is first to score HITS_FOR_WIN hits. In the completed poule sheet shown in Figure 2, it is recorded via the symbol V as the number of        needed hits may vary depending on the competition. For simplicity we use 5 hits in our problem. In the class PouleSheet implement the public method

void  recordBout(int  fencer1,  int  fencer2,  int  h1,  int  h2) which    records the result of a bout (a match) between fencer1 and fencer2 in the results      attribute. h1 is the number of hits fencer1 scored in that bout, and h2 is the number of hits  fencer2 scored. The method should throw an InvalidScoreException if the following occurs:

  h1 or h2 is negative or strictly greater than HITS_FOR_WIN.

  both h1 and h2 are equal to HITS_FOR_WIN.

  neither h1 or h2 is equal to HITS_FOR_WIN.

The method must throw an IllegalArgumentException if fencer1 equals fencer2, or if at least one of them is invalid (negative or greater or equal to pouleSize).

 

Figure 2: Example of a completed fencing poule sheet for four competitors.

(v)      [20 marks]     Once all the bouts have been completed, competitors are ranked using the following rules in the given order:

1.  The first index, for the initial classification, is the number of victories V. The fencer with the highest index will be ranked rst, The fencer with the second highest will be ranked         second and so on.

2.  In cases of equality in this first index, and to separate fencers with equal first indices, a second index will be established, using the formula Dif f = HS - HR, the difference between the total number of hits scored and hits received.

3.  In cases of equality of the two indices V and Dif f , the fencer who has scored most hits (HS) will be seeded highest.

4.  f) In cases of absolute equality between two or more fencers, their seeding order will be   decided by drawing lots. In other words the order between them will be decided randomly. For example, in Figure 2, Gabriel was randomly allocated third place and Charlotte was   allocated fourth place.

Implement the public method List  getRanking() that returns the ranking in the poule. The first element in the list is the competitor ranked first, the second element is the competitor ranked second, and so on. The method should return null if the poule is not        completed, that is there exists at least one bout that is not recorded in the results.

(vi)     [10 marks]     Write the Java Doc for the entire class SocialNetwork following the Google   Java Style Guide.

2        (20 marks)     Recursion

The code for this question must be written in the provided le

ManufacturingProcess.java.

Warning: if the implemented methods in this question are not recursive, a mark of 0 will be awarded for that part of the question.

The aim of this question is to evaluate the cost of transforming a manufacturing process PA into another manufacturing process PB. Each manufacturing process is composed of many

sub-processes. For simplicity, a manufacturing process is represented as an array of Strings, where each string is the name of a sub-process. For example a process composed of three  sub-processes is represented by an array such as {"P211",  "P011",  "P256"}.

We want to quantify how different the two processes are. There are three possible operations that can be performed, insertion, deletion and substitution. For example, let’s consider the     manufacturing processes PA = {P011,  P101,  P200,  P200,  P123,  P256} and       PB = {P311,  P101,  P200,  P200,  P101,  P256,  P004}. A minimal modification  script that transforms PA into PB is:

1.  substitution of P311 for P011,

2.  substitution of P101 for P123,

3.  insertion of P004 at the end.

Assuming that each operation has a cost of 1, the modification script has a total cost of 3.

This problem has optimal substructure. That means the problem can be broken down into       smaller, simple sub-problems”, which can be broken down into yet simpler sub-problems, and so on, until, finally, the solution becomes trivial.

Problem: Transform manufacturing process PA「1..m| into PB「1..n| by performing a series of change on PA「1..m|. Note, the indexation of processes here starts at 1.

Sub-problem: Transform a manufacturing sub-process PA「1..i| into PB「1..j| by performing a series of change on PA「1..i|, where i 5 m and j 5 n.

1.  We have reached the end of either manufacturing sub-process.

•  If PA is empty (i = 0), insert all remaining processes of manufacturing sub-process PB「1..n| into PA. The cost of this operation is equal to the number of processes left in PB .

•  If PB is empty (j = 0), remove all remaining processes of manufacturing sub-process PA「1..i|. The cost of this operation is equal to the number of processes left in PA .

2.  The last processes of manufacturing sub-processes PA「1..i| and PB「1..j| are the same. Nothing needs to be done we simply recurse for the remaining sub-processes, that is    PA「1..i - 1| and PB「1..j - 1|. As no modification is involved, the cost will be 0.

3.  The last processes of PA「1..i| and PB「1..j| are different. In that case return the minimum of the following operations with an added cost of 1, the cost of the actual operation:

•  Insert the last process of PB「1..j| into PA「1..i|. The size of PB「1..j| reduces by 1, and PA「1..i| remains the same.

•  Delete the last process of PA「1..i|. The size of PA「1..i| reduces by 1, and PB「1..j| remains the same.

•  Substitute (Replace) the current process PA「i| of PA by the current process PB「j| of PB. The size of both sub-processes reduces by 1.

In this approach, we look at the last process of each manufacturing processes (using indices i and j to define the last process of a sub-problem), we could have done something similar by   looking at the first processes instead.

As you can see, we can dene the problem recursively as:

i

 j

costi,j  =costi -1,j -1  1 +min .

,              ,

if j = 0 (deletions)

if i = 0 (insertions)

if PA「i| = PB「j| (do nothing)

costi -1,j         deletion

costi,j -1        .insertion

costi -1,j -1   substitution

(i)       [10 marks]     Implement a recursive public static method

minCost(String[]  pA,  String[]  pB) that returns the minimum cost of           transforming one manufacturing process into another. In this question we consider that all operations (deletion, substitution, and insertion) have a cost of 1 each.

(ii)      [10 marks]     Implement a recursive public static method

minCost(String[]  pA,  String[]  pB,  int  sub,  int  del,  int  ins)      that returns the minimum cost of changing one manufacturing process into another. However, in this question we consider that each type of operation has a different cost represented by the     parameters sub for substitution cost, del for deletion cost, and ins for insertion cost.