Menu

[Solved] Package Practical03vets Import Javautilarraydeque Import Javautilpriorityqueue Import Java Q37198202

Start of Checkpoint 24 The Tasks Wombats that have the same severity level are grouped together and are retrieved from the qu

iv. if the users enters PROCEsS then the queue should be processed/emptied. v. add a try-catch your main method to catch the

package practical03vets;

import java.util.ArrayDeque;
import java.util.PriorityQueue;
import java.util.Queue;

/**
*
* @author 彭
*/
public class Wombat implements Comparable<Wombat> {

/**
* @param args the command line arguments
*/
private String name;
private int severity;
private double time;
// default constructor
public Wombat()
{
name = “”;
severity = 0;
time = 0.0;
}
// paramterized constructor
public Wombat(String name, int severity, double time)
{
this.name = name;
this.severity = severity;
this.time = time;
}
// getter and setter methods
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getSeverity() {
return severity;
}
public void setSeverity(int severity) {
this.severity = severity;
}
public double getTime() {
return time;
}
public void setTime(double time) {
this.time = time;
}
@Override
public String toString()
{
return (getName() + “, ” + getSeverity() + “, ” + getTime());
}
public static void main(String[] args){
//implemented priority queue
//Queue<Wombat> wQueue = new ArrayDeque<>();
PriorityQueue<Wombat> wQueue = newPriorityQueue<>();
wQueue.add(new Wombat(“Fluffy”, 5, 10.5));
wQueue.add(new Wombat(“Socks”, 10, 11.3));
wQueue.add(new Wombat(“Barry”, 10, 10.8));
wQueue.add(new Wombat(“Jobe”, 3, 12.0));
wQueue.add(new Wombat(“Ginger”, 15, 3.2));
  
// polling de-queue to print all the Wombats’ details
while(!wQueue.isEmpty())
{
System.out.println(wQueue.poll().toString());//poll移除并返问队列头部的元素
}
System.out.println();
}

@Override
public int compareTo(Wombat o) {
//throw new UnsupportedOperationException(“Not supported yet.”);//To change body of generated methods, choose Tools |Templates.
int severity = ((Wombat) o).getSeverity();
return severity – this.severity; // sorts the severity indescending order
}
  
}

this is the previous checkpoint, please according to this

Start of Checkpoint 24 The Tasks Wombats that have the same severity level are grouped together and are retrieved from the queue in any order (from the APl: “ties are broken arbitrarily”). Wombats with the same severity should order so that the Wombat with the earliest time should have a higher priority. Modify the compareTo method to operate in this way. The output from the original set of Wombats should now be (note the order of Barry and Socks) 1. Ginger, 15, 3.2 Barry, 10, 10.8 Socks, 10, 11.3 Fluffy, 6, 12.0 Jobe, 5, 10.5 2. Some Wombats, such as Ginger, may try to jump the queue by have a severity higher than the maximum of 10. To counter this, create a new exception that is raised when an out of bounds severity is detected i. create a new class that extends the Exception class called severityoutofBoundsException ii. in the Wombat constructor check the that the value of severity is greater than o and less than 11, that is in the range [1 10] ii. if severity is out of bounds throw an instance of your newly created exception class iv. add the necessary throws clauses to your methods v. If you still have Ginger in your list of Wombats you should receive an exception similar to the following Exception in thread “main” practical03vet.SeverityOutOfBoundsException: Severity out of bounds at practical03vet.Wombat.<init>(Wombat.java:22) at practical03vet.Practical03Vet.main(Practical03Vet.java:28) Java Result: 1 3. To make the application more usable get Wombat data from the user via the keyboard i. add a scanner object to read from the keyboard (system.in) ii. keep reading from the keyboard until the user enters ouIT ii use another scanner object to extract the name, severity, and time from each line entered (hint use .next, .nextInt , and.nextDouble)) iv. if the users enters PROCEsS then the queue should be processed/emptied. v. add a try-catch your main method to catch the out of bounds exception. Print an informative message and continue accepting user input. Example output is shown below. User Input in bold Sweeps 4 10.3 Fluffy 9 11.3 Socks 9 10.3 Ginger 15 4.5 Severity it not within 1-10 PROCESS Socks, 9, 10.3 Fluffy, 9, 11.3 sweeps, 4, 10.3 QUIT Show transcribed image text Start of Checkpoint 24 The Tasks Wombats that have the same severity level are grouped together and are retrieved from the queue in any order (from the APl: “ties are broken arbitrarily”). Wombats with the same severity should order so that the Wombat with the earliest time should have a higher priority. Modify the compareTo method to operate in this way. The output from the original set of Wombats should now be (note the order of Barry and Socks) 1. Ginger, 15, 3.2 Barry, 10, 10.8 Socks, 10, 11.3 Fluffy, 6, 12.0 Jobe, 5, 10.5 2. Some Wombats, such as Ginger, may try to jump the queue by have a severity higher than the maximum of 10. To counter this, create a new exception that is raised when an out of bounds severity is detected i. create a new class that extends the Exception class called severityoutofBoundsException ii. in the Wombat constructor check the that the value of severity is greater than o and less than 11, that is in the range [1 10] ii. if severity is out of bounds throw an instance of your newly created exception class iv. add the necessary throws clauses to your methods v. If you still have Ginger in your list of Wombats you should receive an exception similar to the following Exception in thread “main” practical03vet.SeverityOutOfBoundsException: Severity out of bounds at practical03vet.Wombat.(Wombat.java:22) at practical03vet.Practical03Vet.main(Practical03Vet.java:28) Java Result: 1 3. To make the application more usable get Wombat data from the user via the keyboard i. add a scanner object to read from the keyboard (system.in) ii. keep reading from the keyboard until the user enters ouIT ii use another scanner object to extract the name, severity, and time from each line entered (hint use .next, .nextInt , and.nextDouble))
iv. if the users enters PROCEsS then the queue should be processed/emptied. v. add a try-catch your main method to catch the out of bounds exception. Print an informative message and continue accepting user input. Example output is shown below. User Input in bold Sweeps 4 10.3 Fluffy 9 11.3 Socks 9 10.3 Ginger 15 4.5 Severity it not within 1-10 PROCESS Socks, 9, 10.3 Fluffy, 9, 11.3 sweeps, 4, 10.3 QUIT

Expert Answer


Answer to package practical03vets; import java.util.ArrayDeque; import java.util.PriorityQueue; import java.util.Queue; /** * * @a… . . .

OR


Leave a Reply

Your email address will not be published. Required fields are marked *