Question: / / This is a headscrather. import java.io . BufferedReader; import java.io . InputStreamReader; import java.util.LinkedList; import java.util.List; import java.util. class Student { public String
This is a headscrather.
import java.ioBufferedReader;
import java.ioInputStreamReader;
import java.util.LinkedList;
import java.util.List;
import java.util.
class Student
public String Name;
public StudentString name
this.Name name;
interface IHashTable
public void addStudent student;
public void removeStudent student;
public boolean containsStudent student;
public int getSize;
public boolean isEmpty;
public void print;
class HashTable implements IHashTable
private int size;
private double occupancyThreshold;
private int loadFactor;
private LinkedList hashTable null;
public HashTableint slotCount, int loadFactor, double occupancyThreshold
this.size ;
this.loadFactor loadFactor;
this.occupancyThreshold occupancyThreshold;
this.hashTable createHashTableslotCount;
private LinkedList createHashTableint slotCount
LinkedList hashTable new LinkedListslotCount;
for int i ; i slotCount; i
hashTablei new LinkedList;
return hashTable;
private int nextPrimeint n
boolean isPrime;
n;
while true
int sqrt int Math.sqrtn;
isPrime true;
for int i ; i sqrt; i
if n i
isPrime false;
if isPrime
return n;
else
n;
public void printState
String result String.format
"LOADFACTOR: d
"OCCUPANCYTHRESHOLD: f "OCCUPANCYRATIO: f "SIZE: d "SLOTCOUNT: d
this.loadFactor,
this.occupancyThreshold,
this.calculateOccupancyRatio
this.size,
this.hashTable.length;
System.out.printlnresult;
this.print;
private int getHashCodeStudent student, int slotCount Write your code here...
Return the ratio of total number of elements added to the HashTable
private double calculateOccupancyRatio Write your code here...
if the calculated occupancy ratio is more than occupancyThreshold
private boolean needToRehash Write your code here...
Create a new HashTable with the newSlotCount
private void rehashint newSlotCount Write your code here...
Use the provided function nextPrime to find the next new slotCount
@Override
public void addStudent student Write your code here...
@Override
public void removeStudent student Write your code here...
@Override
public boolean containsStudent student Write your code here...
@Override
public int getSize Write your code here..
@Override
public boolean isEmpty Write your code here...
@Override
public void print Write your code here...
class Solution
public static void mainString args throws IOException
BufferedReader bufferedReader new BufferedReadernew InputStreamReaderSystemin;
int OPERATIONCOUNT Integer.parseIntbufferedReaderreadLinereplaceAlls$
splittrim;
int SLOTCOUNT Integer.parseIntbufferedReaderreadLinereplaceAlls$
splittrim;
int LOADFACTOR Integer.parseIntbufferedReaderreadLinereplaceAlls$
splittrim;
float OCCUPANCYTHRESHOLD Float
parseFloatbufferedReaderreadLinereplaceAlls$
splittrim;
bufferedReader.readLine;
HashTable hashTable new HashTableSLOTCOUNT, LOADFACTOR,OCCUPANCYTHRESHOLD;
IntStream.range OPERATIONCOUNTforEachopCountItr
try
List theInput Stream.ofbufferedReaderreadLinereplaceAlls$splitcollecttoList;
String action theInput.get;
String argsString theInput.get;
argsString argsString.replaceAll;;
String arg null;
if argsStringlength
arg argsString.replaceAll;
ProcessInputshashTable action, arg;
catch IOException exception
throw new RuntimeExceptionexception;
;
bufferedReader.close;
private static void ProcessInputsHashTable hashTable, String action, String arg
switch action
case "add": hashTable.addnew Studentarg;
break;
case "remove":hashTable.removenew Studentarg;
break;
case "contains": boolean contains hashTable.containsnew Studentarg;
System.out.printlncontains;
break;
case "getSize":int size hashTable.getSize;
System.out.printlnsize;
break;
case "isEmpty":boolean isEmpty hashTable.isEmpty;
System.out.printlnisEmpty;
break;
case "print":hashTable.printState;
break;
Input
OPERATIONCOUNT
SLOTCOUNT
LOADFACTOR
OCCUPANCYTHRESHOLD
addAlice;addBob;addCharlotte;addCassidy;
print;
Output
LOADFACTOR: OCCUPANCYTHRESHOLD: OCCUPANCYRATIO: SIZE: SLOTCOUNT:
: Cassidy null
: Alice Charlotte null
: Bob null
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
