This is java (1) Write a performance driver client program, PQtester.java, that
ID: 3598589 • Letter: T
Question
This is java
(1) Write a performance driver client program, PQtester.java, that uses insert to add N elements to a priority queue, then uses remove the maximum to remove half the keys, then uses insert to fill it up again, then uses remove the maximum to remove all the keys. Use MaxPQ from the algs4.jar.
Write your driver to do this multiple times on random sequences of keys, with N varying from small to large. Do a few runs for each value of N, so you can compute an average, and get a sense of reproducibility. Your driver should measure the time taken for each run, and print-out or plot the average running times. I suggest using System.nanoTime() to capture runtime.
Show your table of run times in the README. What are reasonable values of "small" and "large" values of N?
Explanation / Answer
package com;
import java.util.Scanner;
public class WeekandActivity {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Parents visiting :");
String pvisit=sc.nextLine();
Scanner sc1 = new Scanner(System.in);
System.out.println("is weather good :");
String wgood=sc1.nextLine();
Scanner sc2 = new Scanner(System.in);
System.out.println("are you rich :");
String rich=sc2.nextLine();
String finalDecision=myDecision(pvisit,wgood,rich);
System.out.println(finalDecision);
}
public static String myDecision(String parentVisit,String wheterGood,String ImRich){
String result="";
if(parentVisit.equalsIgnoreCase("yes") && wheterGood.equalsIgnoreCase("yes") && !ImRich.equalsIgnoreCase("yes")){
result="go to the cinema";
}
else if(!parentVisit.equalsIgnoreCase("yes") && wheterGood.equalsIgnoreCase("yes") && ImRich.equalsIgnoreCase("yes")){
result ="I'll go shopping ";
}
else if(!parentVisit.equalsIgnoreCase("yes") && wheterGood.equalsIgnoreCase("yes") && !ImRich.equalsIgnoreCase("yes")){
result="go to the cinema";
}
else if (!parentVisit.equalsIgnoreCase("yes") && !wheterGood.equalsIgnoreCase("yes") && ImRich.equalsIgnoreCase("yes")){
result="go to the cinema";
}
else if (!parentVisit.equalsIgnoreCase("yes") && !wheterGood.equalsIgnoreCase("yes") && !ImRich.equalsIgnoreCase("yes")){
result ="I'll stay in";
}
else if(parentVisit.equalsIgnoreCase("yes") && wheterGood.equalsIgnoreCase("yes") && ImRich.equalsIgnoreCase("yes")){
result ="I'll go shopping ";
}
else if(parentVisit.equalsIgnoreCase("yes") && !wheterGood.equalsIgnoreCase("yes") && ImRich.equalsIgnoreCase("yes")){
result ="go to the cinema";
}
else if(parentVisit.equalsIgnoreCase("yes") && !wheterGood.equalsIgnoreCase("yes") && !ImRich.equalsIgnoreCase("yes")){
result ="I'll stay in";
}
return result;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.