this is an assignement question from software engineering course and its a text book question..need help with the assignement as soon as possible!! please!and the textbook is fundamentals of software engineering second addition by carlo ghezzi and mehdi
Assignment 2: Chapter 5, Design Patterns, and
Testing CSI 5390
Individual Assignment
Due: November 20 (Wednesday), 2019
5.11. Modify the specification given by the FSM of figure 5.15 by considering the case
where temperature and pressure each have two different associated signals, one indicating
a slight deviation from the acceptable value and the other a dangerous deviation from the
acceptable value. In the latter case, the system must be shut off immediately. (1 point)
5.16. Use the foregoing PH extension to describe a message dispatcher that works along
the following lines: The dispatcher receives messages from two different channels and
the checks the parity of each message. If the parity is wrong, it sends a “nack” (negative
acknowledgement” through a reply channel (there is one such channel for each input
channel); if the parity is right, it places the received message into a buffer. The buffer
may store 10 messages. When the buffer is full, the dispatcher sends the whole contents
of the buffer to a processing unit through another channel. No message can be placed
into a full buffer. (1 point)
5.22. Give an alternative specification for lighting up a button using PNs augmented with
priorities, instead of timed PNs. Discuss the differences between the two representations.
(1 point)
5.30. Give a logic specification for a program that reads in a sequence of n + 1 values and
checks whether the first value also appears in the next n input values. (0.5 points)
1. Design {a,b}*{baaa} in a deterministic FSM. Use the tool demonstrated in class to verify your design for the following strings: (1 point)
baaa, aabbbaaa, bbaabaaa, baaaaabb, baaaabbaa
Turn in the resulting screen shots of these strings.
2. Build the Petri Net (PN) in Figure 5.36 using the PIPE tool demonstrated in class. Simulate the PN for the following scenario: “The elevator is at Floor 4, and the external
down button on Floor 8 is pressed. The elevator then starts moving towards Floor 8.
When the elevator is about to reach Floor 5, the internal button for Floor 5 is pressed. The
elevator stops at Floor 5 to serve after Δt seconds from the departure of Floor 4. After serving Floor 5, the internal button for Floor 5 is reset, but the down button on floor 8 is
still on”. Submit the markings that simulate the elevator moving including the final marking when the elevator stopped at the floor 5. Capture the screen for each marking as
the token moves. The PN must integrate the position, internal button, and external button
modules. (1.5 point)
3. The following diagrams show a model for a pretty printing application. Refactor the class diagram and sequence diagram using the Visitor design pattern. Justify pros and
cons of the refactored model (2.5 point).
4. The following code is a Table class for hashing. Study the code and write a JUnit test class (named TableTest.java) to test the findIndex() and put() methods in the Table
class. Check if there exists any error in the methods using Junit4.
a. Create a table and put 10 entries of your choice (e.g., testTable.put(1, “testA”)). b. Test findIndex() for an non-existing entry. c. Test findIndex() for an existing entry. d. Test put() for an non-existing entry. e. Test put() for an existing entry f. Test put() for a new entry putting into the full table. g. Test teardown by initializing the table to null.
All the statements in the findIndex() and put() method must be covered (i.e., code
coverage must be 100%) using Emma which is a code coverage tool (available at
http://marketplace.eclipse.org/content/eclemma-java-code-coverage). Use Emma as a
plug-in in your IDE (e.g., Eclipse, NetBeans, IntelliJ). Submit the test class and
screen captures showing execution traces without failure and the result of the 100%
coverage. (1.5 points)
public class Table
{
private int manyItems;
private Object[ ] keys;
private Object[ ] data;
private boolean[ ] hasBeenUsed;
public Table(int capacity){
if (capacity <= 0)
throw new IllegalArgumentException("Capacity is negative");
keys = new Object[capacity];
data = new Object[capacity];
hasBeenUsed = new boolean[capacity];
}
public boolean containsKey(Object key){
return findIndex(key) != -1;
}
public int findIndex(Object key){
int count = 0;
int i = hash(key);
while (count <= data.length && hasBeenUsed[i]){
if (key.equals(keys[i]))
return i;
count++;
i = nextIndex(i);
}
return -1;
}
public Object get(Object key){
int index = findIndex(key);
if (index == -1)
return null;
else
return data[index];
}
private int hash(Object key){
return Math.abs(key.hashCode( )) % data.length;
}
private int nextIndex(int i){
if (i+1 == data.length)
return 0;
else
return i+1;
}
public Object put(Object key, Object element){
int index = findIndex(key);
Object answer;
if (index != -1){ // The key is already in the table.
answer = data[index];
data[index] = element;
return answer;
}
else if (manyItems < data.length){ // The key is not yet in this Table.
index = hash(key);
while (keys[index] != null)
index = nextIndex(index);
keys[index] = key;
data[index] = element;
hasBeenUsed[index] = true;
manyItems++;
return null;
}
else{ // The table is full.
throw new IllegalStateException("Table is full.");
}
}
public Object remove(Object key){
int index = findIndex(key);
Object answer = null;
if (index != -1)
{
answer = data[index];
keys[index] = null;
data[index] = null;
manyItems--;
}
return answer;
}
}
Sample Screenshot