
Complete the findMax() method that returns the largest value in array nums.
Ex: If array nums contains:
2 4 6 8 10 7 5 3
the findMax() method returns:
10
Note: During development, array nums is filled with 10 pseudo-random integers in main() using the fillRandomly() method with a seed value of 7. When submitted, different seed values will be used to generate arrays of different size for the test cases. Refer to the textbook section on Random numbers to learn more about pseudo-random numbers.
Code:
import java.util.*;
public class Numbers {
private int[] nums;
public int findMax() {
/* Type your code here. */
}
public void setNums(int[] nums) {
this.nums = nums;
}
public int[] getNums() {
return nums;
}
// Fill array nums with pseudo-random integers (0-999) with a seed value
public void fillRandomly(int seed, int size) {
Random rand = new Random(seed);
nums = new int[size];
for(int i=0; i<nums.length; i++) {
nums[i] = rand.nextInt(1000);
}
}
public static void main(String[] args) {
Numbers numObject = new Numbers();
int [] nums = {2, 4, 6, 8, 10, 7, 5, 3};
numObject.setNums(nums);
System.out.println(Arrays.toString(numObject.getNums())); // Prints content of array
System.out.println(numObject.findMax()); // findMax() should return 10
numObject.fillRandomly(7, 10); // Fill nums with 10 pseudo-random nmubers using seed value 7
System.out.println(Arrays.toString(numObject.getNums())); // Prints content of array: [236, 164, 485, 44, 380, 254, 968, 649, 850, 534]
System.out.println(numObject.findMax()); // findMax() should return 968
}
}

Trending nowThis is a popular solution!
Step by stepSolved in 2 steps with 1 images

- Create a 1D integer array of size 17. Fill each index with a random value ranging from 1 to 359 inclusive. You will then design and implement the Random Sort algorithm using the following methods: Create a method called check_if_sorted (). It should take in a 1D integer array and return a boolean value. It should return TRUE if the array is sorted in nondescending order, and FALSE otherwise. Hint: If you compare elements in the array and a pair is in the wrong order, that would mean the array is not in non-descending order. Create a method called shuffleArray (). It should take in a 1D integer array and return a 1D integer array. Shuffle the array so that the values are in random different indexes, and return altered array. Hint: There are many approaches to solve this problem – making a second array in the shuffleArray () method might be part of the answer. Create a method called PrintArray (). It should take in a 1D integer array and return nothing. Simply print the current values…arrow_forwardALert dont submit AI generated answer.arrow_forwardRefer to the following method that finds the smallest value in an array. /** Precondition: arr is initialized with int values. * Oparam arr the array to be processed Greturn the smallest value in arr public static int findMin(int[] arr) { int min = /* some value */; int index = 0; while (index < arr.length) { if (arr [index] < min) min = arr [index]; index++; } return min; } Which replacement(s) for /* some value */ will always result in correct execu- tion of the findMin method? I Integer.MIN_VALUE II Integer.MAX_VALUE III arr [0] (A) I only (B) II only (C) III only (D) I and III only (E) II and III onlyarrow_forward
- please read the directions carefullyarrow_forwardI need this program in java please. #Given Arrayarray=[1,1,1,2,2,2,2,2,4,5,5,6,6,6] #Insert valuevalue=3 index=0for x in array: if value<x: #inserting to the array in the position index array.insert(index,value) print ("Output :",array) break #Incrementing position by 1 index=index+1arrow_forwardGiven the below 2 arrays: int arr1[] = { 9,8,7,6,5,4,3,2,1,0 }; int arr2[] = { 99, 89, 79, 69, 59 }; Write a program to replace 79 in arr2 with 4 from arr1. Print the final arr2 using Arrays.toString() method. Hint: Use System.arraycopy() methodNote: For all these programs, please submit the program’s .java file and screenshot of output.arrow_forward
- Method Details: public static java.lang.String getArrayString(int[] array, char separator) Return a string where each array entry (except the last one) is followed by the specified separator. An empty string will be return if the array has no elements. Parameters: array - separator - Returns: stringThrows:java.lang.IllegalArgumentException - When a null array parameter is providedarrow_forwardThe running time for the ____ method is O(1) for Array implementation. Question 12 options: __str__ __getitem__(index) pop(index) insert(index, item)arrow_forwardJava coding Can you create a remove method that removes and returns an element from an index in an array? Thanks.arrow_forward
- Computer Networking: A Top-Down Approach (7th Edi...Computer EngineeringISBN:9780133594140Author:James Kurose, Keith RossPublisher:PEARSONComputer Organization and Design MIPS Edition, Fi...Computer EngineeringISBN:9780124077263Author:David A. Patterson, John L. HennessyPublisher:Elsevier ScienceNetwork+ Guide to Networks (MindTap Course List)Computer EngineeringISBN:9781337569330Author:Jill West, Tamara Dean, Jean AndrewsPublisher:Cengage Learning
- Concepts of Database ManagementComputer EngineeringISBN:9781337093422Author:Joy L. Starks, Philip J. Pratt, Mary Z. LastPublisher:Cengage LearningPrelude to ProgrammingComputer EngineeringISBN:9780133750423Author:VENIT, StewartPublisher:Pearson EducationSc Business Data Communications and Networking, T...Computer EngineeringISBN:9781119368830Author:FITZGERALDPublisher:WILEY





