Question

In: Computer Science

Primary Concepts: Priority Queues and Polymorphism Primary Concepts Priority Queues Object-Oriented Frameworks Inheritance and Polymorphism Please...

Primary Concepts: Priority Queues and Polymorphism

Primary Concepts

Priority Queues

Object-Oriented Frameworks

Inheritance and Polymorphism

Please read this Specification Document


Corresponding Discussion Forum

Important Design Requirement

Your design must be based on Modularity and Separation of Concerns.

Remember that interfaces represent behavior, while classes represent implementation.

The Priority Queue Data Structure and the Simulation Framework implementations must be based on "Information Hiding" and "Encapsulation".

The Software Gurus Bar is a client of the Simulation Framework.

The Simulation Framework is a client of the Priority Queue.

The Priority Queue neither knows about the Simulation Framework nor about the Software Gurus Bar.

The Simulation Framework knows about the Priority Queue (through its API), but it doesn't know about the Software Gurus Bar.

The Software Gurus Bar Application knows about the Simulation Framework through its Interface (API), but it doesn't know about the Priority Queue.

Page/Slide 11 of the above Specification Document gives a partial perspective about the Design.

The code should be written in JAVA

Solutions

Expert Solution

package DS;

import java.util.*;

public class PriorityQueueDriver

{

public static void main(String[] pyari)

{

Scanner in = new Scanner(System.in);

// Creating Priority queue parameterized constructor

// with initial capacity is 8 and a StudentComparator

// instance as its parameters

PriorityQueue<MyStudent> pq = new

PriorityQueue<MyStudent>

(8, new MyStudentComparator());

  

// Creates a Student object using

// parameterized constructor

// and adds the student object to priority queue  

pq.add(new MyStudent("Pyari", 99.98));

pq.add(new MyStudent("Sasmita", 87.62));

pq.add(new MyStudent("Ram", 66.22));

pq.add(new MyStudent("Manvi", 94.36));

pq.add(new MyStudent("Tnvi", 84.36));

  

// Printing names of students in priority order,poll()

// method is used to access the head element of queue

System.out.println("Students served in their " +

"priority order of total mark.");

  

// Loops till queue is not empty

while (!pq.isEmpty())

System.out.println(pq.poll().getName());

}// End of main method

}// End of driver class PriorityQueueDriver

// Defines a class MyStudentComparator implementing

// Comparator interface

class MyStudentComparator implements Comparator<MyStudent>

{

// Overriding compare() method of Comparator  

// for descending order of total

public int compare(MyStudent firstStu, MyStudent secondStu)

{

// Checks if first student total mark is less than

// second student total mark then return 1

if (firstStu.getTotal() < secondStu.getTotal())

return 1;

// Otherwise checks if first student total mark

// is greater than second student total mark

// then return -1

else if (firstStu.getTotal() > secondStu.getTotal())

return -1;

// Otherwise both are equal return 0

return 0;

}// End of method

} // End of class MyStudentComparator

// Defines a class student to store student information

class MyStudent

{

// To stores name and total mark

private String name;

private double total;

  

// Parameterized student constructor to assign

// parameter values to instance variables

public MyStudent(String na, double tot)

{

name = na;

total = tot;

}// End of parameterized constructor

// Method to return name

public String getName()

{

return name;

}// End of method

  

// Method to return total

public double getTotal()

{

return total;

}// End of method

}// End of class Student

Sample Output:

Students served in their priority order of total mark.
Pyari
Manvi
Sasmita
Tnvi
Ram


Related Solutions

What are the object oriented concepts and which all object oriented concepts are used in the...
What are the object oriented concepts and which all object oriented concepts are used in the given program? Consider the following code and explain how each of the object oriented concepts are applied in the given program. (CO1) class Vehicle { string brand; public: void honk(); void honk(int); }; void Vehicle::honk() { cout << "Tuut, tuut! \n" ; } void Vehicle::honk(int x) { for(int i=0;i<x;i++) cout << "Tuut, tuut! \n" ; } int main() { Vehicle V1; V1.honk(); V1.honk(3); }
Based on what you know about object oriented programming, inheritance, and polymorphism, why do you think...
Based on what you know about object oriented programming, inheritance, and polymorphism, why do you think it is not possible to write code like this in Java: public class X extends Y, Z { // ... } ...but can write code like this: public class A implements B, C { //... }
OOP involves use of the following concepts: inheritance, polymorphism, and encapsulation. What are your definitions of...
OOP involves use of the following concepts: inheritance, polymorphism, and encapsulation. What are your definitions of these terms? Why are they important? Does a program necessarily suffer if one or more of these items are absent?
i need a full explanation in details Object Oriented Programming Principles Principles Polymorphism Inheritence Encapsulation Abstraction...
i need a full explanation in details Object Oriented Programming Principles Principles Polymorphism Inheritence Encapsulation Abstraction Class Object Method Message Passing
Using the various Object Oriented Programming concepts and skills learnt in this course, design and develop...
Using the various Object Oriented Programming concepts and skills learnt in this course, design and develop a Java Application to compute an individual student’s GPA and store the records in a database. The application should have two components i.e. The student and the course components. The following should be the minimal operations on the course component: – Set course information – Print course information – Show credit hours – Show course number The following should be the minimal operations on...
Abstraction is a key part of object-oriented programming and the concepts apply particularly well to classes....
Abstraction is a key part of object-oriented programming and the concepts apply particularly well to classes. How would the same concepts apply to data structures and how we tend to define and think of ADTs?
Abstraction is a key part of object-oriented programming and the concepts apply particularly well to classes....
Abstraction is a key part of object-oriented programming and the concepts apply particularly well to classes. How would the same concepts apply to data structures and how we tend to define and think of ADTs?
What is different between procedural and object-oriented programming? Match each of the following OOP concepts with...
What is different between procedural and object-oriented programming? Match each of the following OOP concepts with its example/description. Question 2 options: 12345678 Providing a way for an entity to behave in several ways OR providing multiple entities to be treated in a similar way 12345678 A key way of saving having to retype a lot of code for similar but different objects 12345678 The removal of non-essential information 12345678 Allowing which function to be called by an object to be...
PLEASE DO IN C++ Create an object-oriented program that initially allows the user to save customer...
PLEASE DO IN C++ Create an object-oriented program that initially allows the user to save customer information in the list and to search for a customer by specifying the customer’s ID. Sample Run Customer Information Management System --------------------------------------------------------------- CUSTOMER DATA ENTRY: Full Name (First, Last): Jenny Ha Company: Convergent Laser Technologies Street: 1000 International Ave City: Oakland State: CA Zip Code: 94506 ID: 100 Continue Your Data Entry? (y/n): y Full Name (First, Last): Bill Martinez Company: Cisco Systems Street:...
Make a simple game using C++ which implements all about Object Oriented Programming (Please make an...
Make a simple game using C++ which implements all about Object Oriented Programming (Please make an explanation which of each part in it)
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT