Question: Recursion on array of Mountain objects Write an application with three classes. First class named Mountain has two instance variables: name of String type and
Recursion on array of Mountain objects Write an application with three classes. First class named Mountain has two instance variables: name of String type and elevation of int type. It has constructor that initializes instance variables and has getter method to get each data. Second class named Recursion has the following three recursive methods: // PRECONDITION n is non-negative integer denoting actual number of mountains in the list. // Method returns sum of elevations of all n mountains in the list. int sumElevationsRec (Mountain[l list, int n) // PRECONDITION n is non-negative integer denoting the number of occupied positions in the // list. Method returns String of all Mountain objects in the list. String toString (Mountain[] list, int n) // PRECONDITION n is non-negative integer denoting the number of occupied positions in the // array list. Method returns true is mountains in the list are sorted by their elevation from // smallest to largest, and false otherwise. boolean issorted (Mountain [] list, int n) Third class Tester has main method in it. In the main method declare an array m of Mountain type and populate it with 5 Mountain objects of your choice by using initializer list. Invoke each of the three methods from class Recursion (by passing array m and its length as actual parameters). Program outcome must provide English explanation which method is invoked, what is the result, and/or what the method does
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
