Answered step by step
Verified Expert Solution
Link Copied!
Question
1 Approved Answer

Write a JAVA program and include these methods. The method header is given. Invoke these methods from the main method. In the main you are

Write a JAVA program and include these methods.  The method header is given.  Invoke these methods from the main method. In the main you are to declare and create 2 integer arrays and 1 String array.

     int[] arr1 = new int[10];

     int[] arr2= new int[20];

     String [] names=new String[5];

 

For names -  use a loop and prompt and read in the user’s input to populate the array.

For arr1 – you are to write a for loop and prompt the user to enter an integer value.

For arr2 – you are to write a for loop that uses the random number generator to populate the array with integers between 1 and 100.

Then invoke the following static methods:

  • printArray on arr1  
    • printArray(arr1)
  • printArray on arr2
  • printArray on names
    • printArray(names)
  • average on arr1  
    • System.out.println(“The average of arr1 is “ + average(arr1)
  • average on arr2
  • oneBigName on names
    • System.out.println(“One Big String returns “ + oneBigString(names)
  • call times10 and then printArray on arr1
    • int [] newArray=times10(arr1);
    • printArray(newArray);
  • call times10 and then printArray on arr2
  • call sumEvens on arr1
    • System.out.println(“Call sum Evens on arr1 “ + sumEvens(arr1));
  • call sumEvens on arr2
  • call sumOddIndexArray on arr1
  • call sumOddIndexArray on arr2

 

In the main method you are to invoke each of these static methods. Invoke one time using arr1 and another time using arr2

a)public static void printArray( int [] arr)

 Method receives an array of integers and prints them out on one line separated by a space

b) public static void printArray(String [] a)

Method receives an array of Strings and prints them out on different lines

c)  public static double average (int [] a) – write a method that returns the average value of an array of ints

d) public static String oneBigName(String [] a)

This method returns a String that is all the names in the String array concatenated together

e)public static int[] times10( int [] arr)

Method receives an array and RETURNS an integer array that has the same values*10 of the array passed. The main method should print out the returned array. You should not modify the argument – make a new array and return that new array. Examples – you pass {1,2,3} – what is returned s {10,20,30}

 

f) public static int sumEvens(int[]arr)
Method receives an integer array and return the sum of just theeven values in the array

 

g) public static int sumOddIndexArray( int [] arr)

Method receives an integer array returns the sum of  values at the odd index locations( example sum of arr1[1], arr1[3], arr1[5]...)

 

Sample output -

 

Print array Arr1 is :
23 34 67 89 44 56 23 67 1 34
Print array Arr2 is :
82 65 84 90 46 77 42 68 14 47 64 14 54 66 65 47 70 61 32 83

Print array names is

Sally

John

Don

Sue

Mike

The average of arr1 is ___

The average of arr2 is ___

OneBigName returns SallyJohnDonSueMike

Calling times10 on arr1 and then printarray
230 340 670 890 440 560 230 670 10 340
Calling times10 on arr2 and then printarray
820 650 840 900 460 770 420 680 140 470 640 140 540 660 650 470 700 610 320 830

Call sumEven on arr1 168
Call sumEven on arr2 726
Call sum odd index on arr1 270
Call sum odd index on arr2 618

Step by Step Solution

3.55 Rating (155 Votes )

There are 3 Steps involved in it

Step: 1

Here is a Java program that includes the specified methods and invokes them using the arrays arr1 arr2 and names as described import javautilRandom im... blur-text-image
Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Income Tax Fundamentals 2013

Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill

31st Edition

1111972516, 978-1285586618, 1285586611, 978-1285613109, 978-1111972516

More Books

Students explore these related Programming questions