Question

Hi, can you help me with Part E? Please use Java language. So for this Part, you will be given 3 files of starter code that is already done for you. All you have to do is to add on to it in order to produce the exact output shown in the pictures below. Please only add on to the code, but not change any of them. Out of the 3 given files, 1 of them is already completed. The pictures below will include the problem, the code in pictures as well as code in the text form just to make it easier for you to copy and paste. The first image does not show the full output, I will include the full output in a picture below.

Files that already done no changes needed:

1.SFSUOneStopClient.java

PART E - Priority Queue, 15 points The San Francisco State Universitys One Stop Student Services Center asks us to recommend@ Source Packages Part B2 Part D Part E SFSUOne Stop.java SFSUOneStopClient.java Student.java The_Complete_Sample_Run.pdf _Li

File: SFSUOneStop.java

SFSUOneStop.java package assignment03PartE; /** * Part E * */ import java.util.PriorityQueue; public class SFSUOneStop {File: SFSUOneStopClient.java

package assignment03PartE; /** * * Part E * * Please do not change any code in this file. * * import java.util. PriorityQueueFile: Student.java

Student.java package assignment03PartE; /** * Part E * */ public final class Student implements Comparable Student> {

Complete Output for Part E:

SFSU ONE STOP STUDENT SERVICES CENTER Priority: default Mickey Minnie Milo Goofy Daisy Pluto Donald Mouse Mouse Dog ofy Dog 1

2.30 3.10 3.90 Priority: number-of-big-questions Goofy Dog 1007 Donald Duck 1006 Minnie Mouse 1001 Daisy Duck 1003 Mickey Mou

The Code in Text form: SFSUOneStop.java

package assignment03PartE;

/**
*
* Part E
*
*/

import java.util.PriorityQueue;

public class SFSUOneStop {
  
}

The code in Text form: SFSUOneStopClient.java

package assignment03PartE;

/**
*
* Part E
*
* Please do not change any code in this file.
*
*/

import java.util.PriorityQueue;

public class SFSUOneStopClient {

public static void main(String[] args) {

System.out.println("-------------------------------------------------------------");
System.out.println("\t\t\t SFSU ONE STOP STUDENT SERVICES CENTER");
System.out.println("-------------------------------------------------------------");

Student[] students = {
new Student("Mickey", "Mouse", 1002, 3.7, 1, 17),
new Student("Minnie", "Mouse", 1001, 3.9, 10, 15),
new Student("Goofy", "Dog", 1007, 2.3, 17, 1),
new Student("Pluto", "Dog", 1005, 3.7, 7, 17),
new Student("Milo", "Dog", 1004, 3.7, 7, 17),
new Student("Donald", "Duck", 1006, 3.1, 5, 2),
new Student("Daisy", "Duck", 1003, 1.7, 1, 17),
};

PriorityQueue<Student> oneStopPQ = new PriorityQueue<Student>();

for (String priority : Student.getPriorities()) {
Student.setCompareToPriority(priority);
if (!oneStopPQ.isEmpty()) {
oneStopPQ.clear();
}
for (Student student : students) {
oneStopPQ.add(student);
}
SFSUOneStop.display(oneStopPQ, priority);
}

oneStopPQ.clear();
}
}

The code in Text form: Student.java

package assignment03PartE;

/**
*
* Part E
*
*/

public final class Student implements Comparable<Student> {

}

Notes:

PRIORITY QUEUE 222 223 224 225 226 227 import java.util. PriorityQueue; public class PriorityQueueDemol { 228 public static v

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Please rate the answer and do comment in case of any query. Thanks.

The order of elements in the priority queue is a bit different in my output than the one shown in the output here, but the sorting order is maintained., i.e. when sorted by last name,

First 3 values in the ouput here are "Goofy Dog", "Milo Dog" and "Pluto Dog"

but in my output they are "Goofy Dog", "Pluto Dog" and "Milo Dog"

************************************************************* Code *************************************************************

Student.java:

import java.util.*;

public final class Student implements Comparable<Student> {
   private String firstname;
   private String lastname;
   private int id;
   private double gpa;
   private int smallQuestions;
   private int bigQuestions;
   private static String priority;
  
   // Contructor to initialize the instance variables
   public Student(String firstname, String lastname, int id, double gpa, int smallQuestions, int bigQuestions) {
       this.firstname = firstname;
       this.lastname = lastname;
       this.id = id;
       this.gpa = gpa;
       this.smallQuestions = smallQuestions;
       this.bigQuestions = bigQuestions;
   }
  
   // List of priorities
   public static List<String> getPriorities() {
       List<String> priorities = Arrays.asList("default", "first-name", "last-name", "student-id",
           "gpa", "number-of-small-questions", "number-of-big-questions", "number-of-small-and-big-questions");
       return priorities;
   }
  
   // Setting the priority
   public static void setCompareToPriority(String p) {
       priority = p;
   }
  
   // Cmparing the student objects based on the priority set above
   @Override
   public int compareTo(Student s) {
       if(priority.equals("first-name"))
           return this.firstname.compareTo(s.firstname);
       if(priority.equals("last-name"))
           return this.lastname.compareTo(s.lastname);
       if(priority.equals("student-id"))
           return Integer.valueOf(this.id).compareTo(Integer.valueOf(s.id));
       if(priority.equals("gpa"))
           return Double.valueOf(this.gpa).compareTo(s.gpa);
       if(priority.equals("number-of-small-questions"))
           return Integer.valueOf(this.smallQuestions).compareTo(s.smallQuestions);
       if(priority.equals("number-of-big-questions"))
           return Integer.valueOf(this.bigQuestions).compareTo(s.bigQuestions);
       if(priority.equals("number-of-small-and-big-questions"))
           return Integer.valueOf(this.smallQuestions + this.bigQuestions).compareTo(s.smallQuestions + s.bigQuestions);
       return 0;
   }
  
   // toString() method to display the instance variables of Student
   @Override
   public String toString() {
       return "\t\t" + firstname + "\t" + lastname + "\t" + id + "\t" + String.format("%.2f", gpa) + "\t" + smallQuestions + "\t" + bigQuestions;
   }
}

SFSUOneStop.java:

import java.util.PriorityQueue;

public class SFSUOneStop {
  
   // Displaying the values in priority queue
   public static void display(PriorityQueue<Student> oneStopPQ, String priority) {
       System.out.println("Priority: " + priority);
      
       // Looping until the queue is empty
       while (!oneStopPQ.isEmpty())
           // Removing the element with highest priority
           // from the queue and displaying it
           System.out.println(oneStopPQ.poll());
       System.out.println();
   }
}

SFSUOneStopClient.java (Not modified):

import java.util.PriorityQueue;

public class SFSUOneStopClient {

   public static void main(String[] args) {

       System.out.println("-------------------------------------------------------------");
       System.out.println("\t\t SFSU ONE STOP STUDENT SERVICES CENTER");
       System.out.println("-------------------------------------------------------------");

       Student[] students = {
           new Student("Mickey", "Mouse", 1002, 3.7, 1, 17),
           new Student("Minnie", "Mouse", 1001, 3.9, 10, 15),
           new Student("Goofy", "Dog", 1007, 2.3, 17, 1),
           new Student("Pluto", "Dog", 1005, 3.7, 7, 17),
           new Student("Milo", "Dog", 1004, 3.7, 7, 17),
           new Student("Donald", "Duck", 1006, 3.1, 5, 2),
           new Student("Daisy", "Duck", 1003, 1.7, 1, 17),
       };

       PriorityQueue<Student> oneStopPQ = new PriorityQueue<Student>();

       for (String priority : Student.getPriorities()) {
           Student.setCompareToPriority(priority);
           if (!oneStopPQ.isEmpty()) {
               oneStopPQ.clear();
           }
           for (Student student : students) {
               oneStopPQ.add(student);
           }
           SFSUOneStop.display(oneStopPQ, priority);
       }

       oneStopPQ.clear();
   }
}

************************************************ Screenshots of the code ************************************************

Student.java:

import java.util.*; public final class Student implements Comparable<Student> { private String firstname; private String last

return Integer.valueof(this.id) .compareTo (Integer.valueof(s.id)); if (priority.equals(gpa)) return Double.valueof(this.gp

SFSUOneStop.java:

import java.util. PriorityQueue; 3 public class SFSUOneStop { // Displaying the values in priority queue public static void d

SFSUOneStopClient.java (Not modified):

import java.util. PriorityQueue; public class SFSUOneStopclient { public static void main(String[] args) { - - - - - - - - -

************************************************ Screenshots of sample output ************************************************

. C:\Windows\System32\cmd.exe C:\chg\2020-04-19>javac Student.java C:\chg 2020-04-19>javac SFSUOneStop.java C:\chg 2020-04-19

Hope this helps you and would suffice your requirement.

Add a comment
Know the answer?
Add Answer to:
Hi, can you help me with Part E? Please use Java language. So for this Part,...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT