Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Fill in the ??? in the code: import java.io.*; import java.util.*; public class Lists { static final int QUESIZE = 20; // size of the

Fill in the ??? in the code:

import java.io.*;

import java.util.*;

public class Lists

{

static final int QUESIZE = 20; // size of the processing queue

static final int THROTTLE = 5; // number of transactions to load into the queue at a time

static Transaction initQue = new Transaction(); // used to initialize the Queue.

public static void main(String[] args) throws IOException

{

ListVars v = new ListVars(); // a list of variables used throughout the program

Transaction[] transQue = new Transaction[QUESIZE]; // array used for transaction queue

/* Arrays.fill(transQue, initQue); /* since the contents of the queue are objects, each member points to an instantiation

of the Transaction class, so an instance must be associated with each queue Member.

This can be done with a loop, or using the fill static method of the Arrays class. */

????? // Use a loop to initialize the transaction queue

{

?????

}

String iRec; // used to hold the input record from the productdata file

Scanner iRecScan; // scanner to scan for data in iRec

File iData = new File("productdata.txt");

Scanner iDataScan = new Scanner(iData); // scanner to scan for data from iData

File iTrans = new File("transactions.txt");

Scanner iTranScan = new Scanner(iTrans); // scanner to scan for data in iTrans

if (iDataScan.hasNext()) // While there are records to read from iData

{ // read the 1st record, thus starting the doubly linked list

iRecScan = new Scanner(iDataScan.nextLine()); // and set up parsing of the record using a Scanner

v.????? = new Record(); // create the first list member (the next and prev pointers remain null for 1st record

v.????? .productID = iRecScan.nextInt();

v.????? .prodType = iRecScan.next();

v.dllBegin = v.????? ; // the beginning of the list and

v.dllEnd = v.????? ; // the end of the list point to the 1st member

v.dllCount++;

while (iDataScan.hasNext()) // While there are more records to load

{

iRec = iDataScan.nextLine(); // save the record in the work String iRec

iRecScan = new Scanner(iRec); // set up parsing of the record

v.current = new ?????; // create a new member to add to the list

v.dllEnd.next = v.?????; // point the previous end of the list to this new member

v.current.prev = v.?????; // point the new member to the previous end of the list

v.current.productID = iRecScan.nextInt();

v.current.prodType = iRecScan.next();

v.dllCount++;

v.dllEnd = v.?????; // save this member's address as the new end of the list

// (recall that the identifier of an object simply holds the address of the object)

}

}

while (iTranScan.hasNext()) // While there are more transactions to load

{

loadQue(iTranScan, transQue, v); // load the trans queue with "THROTTLE" trans at a time

procQue(transQue, v); // process any unprocessed trans in the trans queue

}

// PRINT Doubly Linked List

v.current = ?????; // point to the beginning of the list

while (v.current != null) // if you're pointing to a member, print it

{

System.out.println("ID = " + v.current.productID + "; Prod Type = " + v.current.prodType + ".");

v.current = ??????; // point to the next list member; a null will indicate you're at the end of the list

}

System.out.println("Total members = " + v.dllCount);

iDataScan.close();

iTranScan.close();

} // E n d M A I N

static void loadQue(Scanner iTranScan, ????? transQue, ListVars v) throws IOException

{

int transCt; // trans count processed in the current run of this method

transCt = 0;

do

{

transQue[v.?????] = new Transaction(); // the queue is an array of Transaction objects, so must instantiate a new object

transQue[v.?????].transID = iTranScan.nextInt();

transQue[v.?????].transType = iTranScan.next();

transCt++;

System.out.println("Trans ID "+ transQue[v.queAddNx].transID + " Trans Type: "+transQue[v.queAddNx].transType + ".");

v.????? = (v.queAddNx < QUESIZE - 1) ? ++v.queAddNx : 0; /* point to next entry to add into; If already pointing to the last

array element (QUESIZE - 1), then point back to index 0. */

System.out.println("v.queAddNx = " + v.queAddNx);

}

while (iTranScan.hasNext() && (transCt < THROTTLE )); // exit the loop if you hit end of file or the throttle limit

v.????? += transCt; // accumulate all trans loaded in all runs of this method

} // E n d l o a d Q u e

static void procQue(Transaction[] transQue, ListVars v)

{

int x;

for (x=0; x < QUESIZE; x++)

System.out.println("Trans ID "+ transQue[x].transID + " Trans Type: "+ transQue[x].transType + ".");

System.out.println("Total Transaction Count = "+ v.transCt + ".");

while (transQue[v.?????].transID != -1) // While there is another transaction to process

{

//

// Process the transaction type HERE

//

// THEN do the following

transQue[v.?????].transID = -1; // use -1 to mark the queue member as processed

v.queProcNx = (v.queProcNx < QUESIZE - 1) ? ++v.queProcNx : 0; /* If the pointer to the next entry to process increments to

the last element (QUESIZE - 1), then back to 0. */

}

} // E n d p r o c Q u e

} // E n d C L A S S

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Concepts of Database Management

Authors: Philip J. Pratt, Joseph J. Adamski

7th edition

978-1111825911, 1111825912, 978-1133684374, 1133684378, 978-111182591

More Books

Students also viewed these Databases questions

Question

Lying on the shelf, Ruby saw the seashell.

Answered: 1 week ago