write that in java code Declare a variable named retVal of type List<PQEntry> Se
ID: 3573926 • Letter: W
Question
write that in java code Declare a variable named retVal of type List<PQEntry> Set retVal equal to a new instance of ArrayList<PQEntry> Declare a variable named lastAccept of type PQEntry Set lastAccept equal to null Declare a variable named mwatts of type int Set mwatts equal to 0 while mwatts < needAmount && pq is not empty do Set lastAccept equal to element returned when removing most important item in pq Increase the value of mwatts by lastAccept.mwattBid Add lastAccept to the end of retVal end while for-each PQEntry ent in retVal Set ent.payment equal to lastAccept.rate * ent.mwattBid end for-each if mwatts > needAmount Set lastAccept.payment equal to lastAccept.rate * (lastAccept.mwattBid - (mwatts - needAmount)) end if Return retVal end
Explanation / Answer
/* Prerequisite: Import java.util.Collection */ import java.util.Collection; /* Code begins here*/ List retVal; retVal=new ArrayList(); PQEntry lastAccept; lastAccept=NULL; int mwatts; mwatts=0; //The type of pq is not mentioned in the question while(mwattsneedAmount) { lastAccept.payment=lastAccept.rate*(lastAccept.mwattBid-(mwatts-needAmount)); } return retVal; /* Code ends here */ /*Declare a variable named retVal of type List*/ List retVal; /*Set retVal equal to a new instance of ArrayList*/ retVal=new ArrayList(); /*Declare a variable named lastAccept of type PQEntry*/ PQEntry lastAccept; /*Set lastAccept equal to null*/ lastAccept=NULL; /*Declare a variable named mwatts of type int*/ int mwatts; /*Set mwatts equal to 0*/ mwatts=0; /*while mwatts needAmount) { /*Set lastAccept.payment equal to lastAccept.rate * (lastAccept.mwattBid - (mwatts - needAmount))*/ lastAccept.payment=lastAccept.rate*(lastAccept.mwattBid-(mwatts-needAmount)); } /*Return retVal*/ return retVal;Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.