Question

You must create a Java class named TenArrayMethods in a file named TenArrayMethods.java. This class must...

You must create a Java class named TenArrayMethods in a file named TenArrayMethods.java. This class must include all the following described methods. Each of these methods should be public and static.Write a method named getFirst, that takes an Array of int as an argument and returns the value of the first element of the array. NO array lists.

Write a method named getLast, that takes an Array of int as an argument and returns the value of the last element of the array.

Write a method named getAllButFirst, that takes an Array of int as an argument and returns a new array with all of the values in the argument array except the first value.

Write a method named getIndexOfMin, that takes an Array of int as an argument and returns the index of the least value in the array.

Write a method named getIndexOfMax, that takes an Array of int as an argument and returns the index of the largest value in the array.

Write a method named swapByIndex, that takes three arguments. The first argument is an Array of int, and the second and third arguments are int indexes. This method will swap the values at the two given index arguments in the array, and return the array.

Write a method named removeAtIndex, that takes two arguments. The first argument is an Array of int, and the second argument is an int index. This method create a new array with all of the values in the argument array except the value at the argument index.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

If you have any doubts, please give me comment...

public class TenArrayMethods{

public static int getFirst(int arr[]){

return arr[0];

}

public static int getLast(int arr[]){

return arr[arr.length-1];

}

public static int[] getAllButFirst(int arr[]){

int n_arr[] = new int[arr.length-1];

for(int i=1; i<arr.length; i++){

n_arr[i-1] = arr[i];

}

return n_arr;

}

public static int getIndexOfMin(int arr[]){

int min_ind = 0;

for(int i=0; i<arr.length; i++){

if(arr[min_ind]>arr[i])

min_ind = arr[i];

}

return min_ind;

}

public static int getIndexOfMax(int arr[]){

int max_ind = 0;

for(int i=0; i<arr.length; i++){

if(arr[max_ind]>arr[i])

max_ind = arr[i];

}

return max_ind;

}

public static int[] swapByIndex(int arr[], int ind1, int ind2){

int t = arr[ind1];

arr[ind1] = arr[ind2];

arr[ind2] = t;

return arr;

}

public static int[] removeAtIndex(int arr[], int ind){

int n_arr[] = new int[arr.length-1];

for(int i=0; i<arr.length; i++){

if(i>=ind)

n_arr[i-1] = arr[i];

else

n_arr[i] = arr[i];

}

return n_arr;

}

}

Add a comment
Know the answer?
Add Answer to:
You must create a Java class named TenArrayMethods in a file named TenArrayMethods.java. This class must...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Assignment 06 – Ten Array Methods You must work in alone on this assignment. Do not...

    Assignment 06 – Ten Array Methods You must work in alone on this assignment. Do not use any Java language features we have not cover so far in this course. Assignment Objectives After completing this assignment the student should be able to:  Declare and instantiate arrays  Access array elements by index  Use loops and decisions to manipulate arrays and array elements  Write methods that manipulate arrays  Write methods that take array arguments  Write methods...

  • JAVA HELP (ARRAYS) Assignment Create a class named Module4 containing the following data members and methods...

    JAVA HELP (ARRAYS) Assignment Create a class named Module4 containing the following data members and methods (note that all data members and methods are for objects unless specified as being for the entire class) 1) Data members: none 2) Methods a. A method named displayContents that accepts an array of type int and prints their values to the b. A method named cemoveNegatives that accepts an array of type int, copies all its non-negative the new array should be the...

  • You will turn in a java file named "MyMethods.java". It will contain one class named "MyMethods". That class will contain three methods. These methods must be in JOptionPane and must c...

    You will turn in a java file named "MyMethods.java". It will contain one class named "MyMethods". That class will contain three methods. These methods must be in JOptionPane and must contain: getAnInt will return a value of type int, and take as an argument a string to prompt the user. The actual prompt presented to the user should include not only the string argument, but also the information that the user may press Cancel or enter an empty string to...

  • Programming 5_1: Create a Java class named <YourName>5_1 In this class create a main method...

    Programming 5_1: Create a Java class named <YourName>5_1 In this class create a main method, but for now leave it empty. Then write a Java method getAverage which takes an array of integers as it’s argument. The method calculate the average of all the elements in the array, and returns that average. The method should work for an array of integers of any length greater than or equal to one. The method signature is shown below: public static double getAverage(...

  • 5. (40 Points) Write a complete Java class named ArrayMethods that implements the methods listed below....

    5. (40 Points) Write a complete Java class named ArrayMethods that implements the methods listed below. All the methods accept the following parameters: Parameters: intar An array of int values. int firstIndex The index of the first element to include in the sum. int lastIndex The index of the last element to include in the sum. Please note that all methods must verify the validity of first Index and lastIndex. public static int sum(int[] arr, int first Index, int lastIndex)...

  • Create a Java file named Ch6Asg.java that contains a public class named Ch6Asg containing a main()...

    Create a Java file named Ch6Asg.java that contains a public class named Ch6Asg containing a main() method. Within the same file, create another class named Employee, and do not declare it public. Create a field for each of the following pieces of information: employee name, employee number, hourly pay rate, and overtime rate. Create accessor and mutator methods for each field. The mutator method for the hourly pay rate should require the value to be greater than zero. If it...

  • please help with this. You must create a sales tracking program named SalesTracking.java. This program must...

    please help with this. You must create a sales tracking program named SalesTracking.java. This program must track monthly sales as well as compute average yearly sales, total sales for the year, and which month had the highest sales and which month had the lowest sales. The program should prompt the user for the sales for each month starting with January. After all the monthly sales have been entered, your program should have methods that do the following. getSales(): This method...

  • This assignment will continue our hardware store system. You will turn in a java file named...

    This assignment will continue our hardware store system. You will turn in a java file named "MyMethods.java". It will contain one class named "MyMethods". That class will contain three methods. These methods must be exactly as specified (including method names): getAnInt will return a value of type int, and take as an argument a string to prompt the user. The actual prompt presented to the user should include not only the string argument, but also the information that the user...

  • Your text has an example of LinkedList class. Convert the class so that the Link objects have a s...

    Your text has an example of LinkedList class. Convert the class so that the Link objects have a single long instance variable -- call it "data" -- and the Link instance variable.. Step 2 Then add the following capabilities to the class. A constructor that takes an array of longs as an argument. The contents of the array are use to create Link objects that become objects in the LinkedList. A "search" method that takes a long argument and returns...

  • Create a class House with the private fields: numberOfUnits of the type int, yearBuilt of the...

    Create a class House with the private fields: numberOfUnits of the type int, yearBuilt of the type int, assessedPrice of the type double. A constructor for this class should have three arguments for initializing these fields. Add accessors and mutators for all fields except a mutator for yearBuilt, and the method toString. Create a class StreetHouse which extends House and has additional fields: streetNumber of the type int, homeowner of the type String, and two neighbors: leftNeighbor and rightNeighbor, both...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT