Please answer in java, thank you.

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899604
Joined: Mon Aug 02, 2021 8:13 am

Please answer in java, thank you.

Post by answerhappygod »

Please answer in java, thank you.
Please Answer In Java Thank You 1
Please Answer In Java Thank You 1 (10.39 KiB) Viewed 37 times
Use Final Exam.java as your starting point Implement the five subroutines, as described in the comments. Each subroutine is worth 8 points. HINT: It might be easier to start at the bottom and work your way up.

import java.util.Arrays; public class FinalExam { // main() // // [2p] Creates an array of five random doubles between and 10. 1/ [2p] Prints the array to standard output (HINT: use Arrays.toString(). // [2p] Sorts the array using the selectionSort() function below. // [2] Prints the sorted array to standard output. // Erase this line and put your main() subroutine here. 1111 // selectionSort) // // [1p] input : an array of doubles "a". // [1] output: an array of doubles "a". // // [6] Uses the functions fromTo(), indexOfMax(), and swap() to execute a // Selection Sort, in which the largest element is repeatedly moved to 1/ the end of the array, and the largest index under consideration is // reduced by one. // // HINT: You may consult section 7.4.4 in our textbook, but do not simply // copy the code from that section. Your implementation of selectionsort // must call the functions fromTo(), indexOfMax(), and swap() to receive // points. // Erase this line and put your selectionSort() subroutine here. // fromTo // // [3p] input : two integers "m" and "n", and an array of doubles "a". // (1p] output: an array of doubles "b". // [4p] Gets an array that starts at a[m] and stops at a[n), and also // includes all of the elements in between (in their original order). // In other words, this function returns the input array "a", but only // from index "m" up to (and including) index "n". // // HINT: The length of the output array "b" is n - m + 1. // Erase this line and put your fromTo() subroutine here.

// indexOfMax) // 1/ [10] input : an array of doubles. 1/ [1p] output: an integer. // // [6p] Returns the INDEX of the maximal element of an array. // Erase this line and put your indexOfMax() subroutine here. // swap // [3p] input : two integers "m" and "n", and an array of doubles "a". // [10] output: an array of doubles "a". // // [4] Interchanges the elements a[m] and a[n), so that a[m] is where a[n] used to be, and a[n] is where a[m] used to be. // // HINT: You will need to define a temporary variable in order to // interchange the two elements of the array. // Erase this line and put your swap() subroutine here. }
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply