Question: Write a java program (xxxxxp1.java where xxxxx is the first five characters of your last name and p1 is the project number) that contains the
Write a java program (xxxxxp1.java where xxxxx is the first five characters of your last name and p1 is the project number) that contains the following methods:
- A method that returns 2nd largest in an array with n elements.
- A method that prints (formatted) array elements 10 elements per line.
- A mergesort method that mergesorts array elements in descending order.
- A binary search method that searches x in a sorted array with n elements and returns its position if exist, -1 otherwise.
Please write your Last name, First name and Student ID at the beginning of your java file as well as at the beginning of the output.
Your main method should be as follow:
public static void main(String args[]) throws exception{
prt(" Program to: find 2nd largest, mergesort and binary search);
prt( Prepared by Last: , First: and Student ID: .");
prt(" Date: ");
try{
Scanner inf = new Scanner (System.in);
n = inf.nextInt(); // read no. of input
xxxxxp1 p1 = new xxxxxp1 (n);
read n integers and store them in array arr and print arr(formatted) 10 elements per line. (40 pts)
find 2nd largest and print it. (40 pts)
mergesort array arr and print arr(formatted) 10 elements per line. (80 pts)
k = inf.nextInt(); // read no. of elements to search
read k keys to search using binary search and print their position in array arr. (40 pts)
}catch (Exception e) {prt(" Exception " + e + " ");}
}// end main method
Please upload a single file containing your xxxxxp1.java program in canvas and make sure to print your name in the program as well is in the output.
To compile at the command prompt: javac xxxxxp1.java
To execute at the command prompt: java xxxxxp1 < anydatafile
NOTE: Projects will not be graded if:
Your complete project is not in a SINGLE xxxxxp1.java file, where xxxxxp1 is the first 5 characters of your last name and p1 is the project number.
It does not read input from System.in. i.e. command prompt.
OPTIAL:
Make your program generic (50 Pts).
Write a non recursive mergesort (50 pts).
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
