Java Priority Queue

In computer science, a priority queue is an abstract data type which is like a regular queue, but where additionally each element has a "priority" associated with it. In a priority queue, an element with high priority is served before an element with low priority. - Wikipedia In this problem we will test your knowledge on Java Priority Queue. There are a number of students in a school who wait to be served. Two types of events, ENTER and SERVED, can take place which are described below.

View Solution →

Java Inheritance I

Using inheritance, one class can acquire the properties of others. Consider the following Animal class: class Animal{ void walk(){ System.out.println("I am walking"); } } This class has only one method, walk. Next, we want to create a Bird class that also has a fly method. We do this using extends keyword: class Bird extends Animal { void fly() { System.out.println("I am flying"); } } Finally, we can create a Bird object that can both fly and walk.

View Solution →

Java Inheritance II

Write the following code in your editor below: 1.A class named Arithmetic with a method named add that takes integers as parameters and returns an integer denoting their sum. 2.A class named Adder that inherits from a superclass named Arithmetic. Your classes should not be be public. Input Format You are not responsible for reading any input from stdin; a locked code stub will test your submission by calling the add method on an Adder object and passing it 2 integer parameters. Outp

View Solution →

Java Abstract Class

A Java abstract class is a class that can't be instantiated. That means you cannot create new instances of an abstract class. It works as a base for subclasses. You should learn about Java Inheritance before attempting this challenge. Following is an example of abstract class: abstract class Book{ String title; abstract void setTitle(String s); String getTitle(){ return title; } } If you try to create an instance of this class like the following line you will g

View Solution →

Java Interface

A Java interface can only contain method signatures and fields. The interface can be used to achieve polymorphism. In this problem, you will practice your knowledge on interfaces. You are given an interface AdvancedArithmetic which contains a method signature int divisor_sum(int n). You need to write a class called MyCalculator which implements the interface. divisorSum function just takes an integer as input and return the sum of all its divisors. For example divisors of 6 are 1, 2, 3 and 6,

View Solution →