Question: Need help writing the actionPerformedEvent outlined in code below. SoylentQueue class is associated with SoylentDataItem class. For increased clarity, I am providing the code for

Need help writing the actionPerformedEvent outlined in code below. SoylentQueue class is associated with SoylentDataItem class. For increased clarity, I am providing the code for both classes. Standard library PriorityQueue cannot be used. Most of my issues with this problem has been with which data structure to use to implement priority queue. Also provdied is a UML diagram of how these classes relate with each other.

***in java...obviously

//you will notice that only the method header for shuffleListModel() is provided, however

//it should not interfere

//Standard library PriorityQueue cannot be used

public class SoylentQueue {

private DefaultListModel dlm;

private ArrayList processedCattle;

private int timeDelay;

private Timer t;

private ArrayList nameList;

public SoylentQueue(int timeDelay) {

dlm = new DefaultListModel();

nameList = new ArrayList();

readNames();

processedCattle = new ArrayList();

this.timeDelay = timeDelay;

}

public DefaultListModel getDataModel() {

return dlm;

}

public void runSimulation() {

t = new Timer(timeDelay, new EventGenerator());

t.start();

}

public ArrayList getProcessed() {

return processedCattle;

}

public void shuffleListModel() {

//TODO Sort the default list model so all the elements are in the proper priority

//Do NOT make a new DefaultListModel - this will break relationship between this model

//and the JList!!!

}

private void readNames() {

Scanner s;

try {

s = new Scanner(new File("cattleNameList.txt"));

while (s.hasNextLine()) {

nameList.add(s.nextLine().trim());}

} catch (FileNotFoundException e) {

System.out.println("Do not forget to include the nameList!");

System.exit(0);

}}

private class EventGenerator implements ActionListener{

@Override

public void actionPerformed(ActionEvent e) {

System.out.println("This currently does nothing");

//First, generate a random priority, 1 to 10

//Then, generate a new SoylentDataItem with that priority

//1) Select a random name from the nameList

//2) Generate a random ID between 100 and 10000, not allowing duplicates

//It is up to you how to prevent duplicates

//3)Age should be generated between 18 and 38

SoylentDataItem newItem = null;

//Finally, add the new SoylentDataItem to the model and shuffle the list model

dlm.addElement(newItem);

shuffleListModel();

//Further, change it so that the timer has a new delay - between 3 to 8 seconds

//for a new cattle to arrive

}

}

//The unfinished toString() methods should not interfere

public class SoylentDataItem {

private int cattleID;

private int cattlePriority;

private String cattleName;

private int cattleAge;

public SoylentDataItem(int priority, String name, int id, int age){

this.cattlePriority = priority;

this.cattleName = name;

this.cattleID = id;

this.cattleAge = age;

}

public String detailsString() {

/*TODO Generate a detail string for the cattle, including all of their fields,

* displayable in the JTextArea on the main GUI.

* You may add newlines to this String as needed for output formatting

*/

return null;

}

public String outputString() {

/*TODO generate a detail string for the cattle, including all of their fields,

* to go on one line - this will be used as output to the processing file

*

*/

return null;

}

public String toString() {

return "Cattle:" + cattleID;

}

}

UML----------------------------------------->

Need help writing the actionPerformedEvent outlined in code below. SoylentQueue class is

GSoylentQueue (default package) nCellRenderer a dlm: DefaultListModel C EventGenerator (default package) GSoylentDataltem (default package) predessedlte a cattlelD: int a cattlePriority: int a cattleName: String a cattleAge: int FSoylentDataltem(int,String,int,int) O detailsString0:String o outputsString0:String o toStringo String EventGeneratoro o actionPerformed(ActionEvent) void GSoylentQueue (default package) nCellRenderer a dlm: DefaultListModel C EventGenerator (default package) GSoylentDataltem (default package) predessedlte a cattlelD: int a cattlePriority: int a cattleName: String a cattleAge: int FSoylentDataltem(int,String,int,int) O detailsString0:String o outputsString0:String o toStringo String EventGeneratoro o actionPerformed(ActionEvent) void

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!