Answered step by step
Verified Expert Solution
Question
1 Approved Answer
import java.io . BufferedReader; import java.io . IOException; import java.io . InputStreamReader; import java.util.LinkedList; class Student { public String Name; public Student ( String name
import java.ioBufferedReader;
import java.ioIOException;
import java.ioInputStreamReader;
import java.util.LinkedList;
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: dOCCUPANCYTHRESHOLD: fOCCUPANCYRATIO: f "SIZE: dSLOTCOUNT: 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 to the
private double calculateOccupancyRatio Write your code here...
if the calculated occupancy ratio is more than occupancyThreshold
private boolean needToRehash Code here
Create a new HashTable with the newSlotCount
private void rehashint newSlotCount Code here
Use the provided function nextPrime to find the next new slotCount
@Override
public void addStudent student Code here
@Override
public void removeStudent student Code here
@Override
public boolean containsStudent student Code here
@Override
public int getSize Write your code here..
@Override
public boolean isEmpty Code here
@Override
public void print 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;
Inputwords like SLOTCOUNT,LOADFACTOR will be included in the code
OPERATIONCOUNT SLOTCOUNT LOADFACTOR OCCUPANCYTHRESHOLD
addNoah;
addOliver;
addSamuel;
addHenry;
addDavid;
addVictoria;
addAudrey;
print;
Sample Output
LOADFACTOR: OCCUPANCYTHRESHOLD: OCCUPANCYRATIO: SIZE: SLOTCOUNT: inside here will need to be printed too
: Noah Oliver Samuel null
: null
: null
: Henry David Victoria Audrey null
: null
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started