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
File: SFSUOneStop.java
File: SFSUOneStopClient.java
File: Student.java
Complete Output for Part E:
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:
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:
SFSUOneStop.java:
SFSUOneStopClient.java (Not modified):
************************************************ Screenshots of sample output ************************************************
Hope this helps you and would suffice your requirement.
Hi, can you help me with Part E? Please use Java language. So for this Part,...