Computer Networking: A Top-Down Approach (7th Edition)
Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN: 9780133594140
Author: James Kurose, Keith Ross
Publisher: PEARSON
Bartleby Related Questions Icon

Related questions

Question
100%

Study the Table class and write a JUnit test class TableTest.java to test the Table class as
follows. Submit the test class and screen captures showing pass of all the tests. Either JUnit4
or JUnit 5 in any IDE may be used.

a. Create a table and put 10 entries of your choice (e.g., testTable.put(1, “testA”)).

Below is the code for pbulic class Table : 

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) // The key exists in the table.
{
answer=data[index];
keys[index]=null;
data[index]=null;
manyItems--;
}
return answer;
}
}

Expert Solution
Check Mark
Still need help?
Follow-up Questions
Read through expert solutions to related follow-up questions below.
Follow-up Question

Study the Table class and write a JUnit test class TableTest.java to test the Table class as follows. Submit the test class and screen captures showing pass of all the tests. Either JUnit4 or JUnit 5 in any IDE may be used.

>>Table class code is in previous question

a. Test findIndex() for an non-existing entry.
b. Test findIndex() for an existing entry.
c. Test put() for an non-existing entry.
d. Test put() for an existing entry
e. Test put() for a new entry putting into the full table.

Solution
Bartleby Expert
by Bartleby Expert
SEE SOLUTION
Follow-up Questions
Read through expert solutions to related follow-up questions below.
Follow-up Question

Study the Table class and write a JUnit test class TableTest.java to test the Table class as follows. Submit the test class and screen captures showing pass of all the tests. Either JUnit4 or JUnit 5 in any IDE may be used.

>>Table class code is in previous question

a. Test findIndex() for an non-existing entry.
b. Test findIndex() for an existing entry.
c. Test put() for an non-existing entry.
d. Test put() for an existing entry
e. Test put() for a new entry putting into the full table.

Solution
Bartleby Expert
by Bartleby Expert
SEE SOLUTION
Knowledge Booster
Background pattern image
Computer Engineering
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-engineering and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Computer Networking: A Top-Down Approach (7th Edi...
Computer Engineering
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:PEARSON
Text book image
Computer Organization and Design MIPS Edition, Fi...
Computer Engineering
ISBN:9780124077263
Author:David A. Patterson, John L. Hennessy
Publisher:Elsevier Science
Text book image
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:9781337569330
Author:Jill West, Tamara Dean, Jean Andrews
Publisher:Cengage Learning
Text book image
Concepts of Database Management
Computer Engineering
ISBN:9781337093422
Author:Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:Cengage Learning
Text book image
Prelude to Programming
Computer Engineering
ISBN:9780133750423
Author:VENIT, Stewart
Publisher:Pearson Education
Text book image
Sc Business Data Communications and Networking, T...
Computer Engineering
ISBN:9781119368830
Author:FITZGERALD
Publisher:WILEY