Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Need help on java H/W. Thanks Use Object Orientated Programming, Classes, method

ID: 3833814 • Letter: N

Question

Need help on java H/W. Thanks

Use Object Orientated Programming, Classes, methods, and arrays. Create an array that holds 10 random integers between 1-100. Create the array inside the class. Create a method that will fill the array with 10 random integers. Create a method that will return the largest integer in the array. Create a method that will return the smallest integer in the array. Use method naming conventions. Main should only be used to execute methods created in the class. Whiteboard / Pseudocode Solution (Attach Pseudocode, Source Code, and Output Below.) Advance implementation use an arraylist to solve problem.

Explanation / Answer

import java.util.Random;


public class ArrayExample {
public static Random rn = new Random();
public static void fillArray(int [] array)
{
for(int i = 0; i < array.length; i++)
{
array[i] = rn.nextInt(100) + 1;
}
}
  
public static int largest(int [] array)
{
int max = array[0];
for(int i = 1; i < array.length; i++)
{
if(max < array[i])
max = array[i];
}
return max;
}
  
public static int smallest(int [] array)
{
int min = array[0];
for(int i = 1; i < array.length; i++)
{
if(min > array[i])
min = array[i];
}
return min;
}
  
public static void main(String[] args)
{
int[] array = new int[10];
fillArray(array);
System.out.println("Largest : " + largest(array));
System.out.println("Smallest : " + smallest(array));
  
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote