Follow the steps below to create a concrete class SortedArray with required instance variables and methods. a. Make sure that the SortedArray class inherits from Array. b. Declare a private instance variables: int m_index which saves the index of the next open slot in the underlying array. This variable is used in the two methods that you are required to implement. Create a constructor that takes one parameter int cap. C. d. The constructor should call the constructor of the super class and initialize the instance variable properly. e. Create an int method getMedian () that returns the median of the underlying array. If the array has even number of elements, return the lower one in the middle. f. Override the insert method so it inserts a number into the underlying array, keeping it sorted in increasing order. Note: Don't forget to add the @Override keyword!

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
100%
18. You are given the following class definition:
public abstract class Array {
protected int[] m_array;
public Array (int cap) {
m array new int [cap];
}
public abstract void insert (int v);
}
Follow the steps below to create a concrete class SortedArray with required instance variables and
methods.
a. Make sure that the SortedArray class inherits from Array.
b. Declare a private instance variables: int m_index which saves the index of the next open slot
in the underlying array. This variable is used in the two methods that you are required to implement.
Create a constructor that takes one parameter int cap.
C.
d. The constructor should call the constructor of the super class and initialize the instance variable
properly.
e. Create an int method getMedian () that returns the median of the underlying array. If the array
has even number of elements, return the lower one in the middle.
f.
Override the insert method so it inserts a number into the underlying array, keeping it sorted in
increasing order. Note: Don't forget to add the @Override keyword!
Transcribed Image Text:18. You are given the following class definition: public abstract class Array { protected int[] m_array; public Array (int cap) { m array new int [cap]; } public abstract void insert (int v); } Follow the steps below to create a concrete class SortedArray with required instance variables and methods. a. Make sure that the SortedArray class inherits from Array. b. Declare a private instance variables: int m_index which saves the index of the next open slot in the underlying array. This variable is used in the two methods that you are required to implement. Create a constructor that takes one parameter int cap. C. d. The constructor should call the constructor of the super class and initialize the instance variable properly. e. Create an int method getMedian () that returns the median of the underlying array. If the array has even number of elements, return the lower one in the middle. f. Override the insert method so it inserts a number into the underlying array, keeping it sorted in increasing order. Note: Don't forget to add the @Override keyword!
Expert Solution
steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY