Please use java code.
Implement a test class named BatArray1Test that tests all the functionality of the following given 3 methods, including the invalid arguments:
1) commonEnd
Given two arrays of ints, a and b, return true if they have the
same first element or they have the same last element. This method
should return false if either array is empty or null.
2) midThree
Given an array of integers, return a new array of length 3 containing the elements from the middle of the array. This method should return null if the array length is even or less than 3.
3) maxTriple
Given an array of integers, look at the first, last, and middle values in the array, and return the largest value. This method should return 0 if the length of the array is even.
"Like" for any responses within 3 hours.
Note: Could you plz go through this code and let me
know if u need any changes in this.Thank You
_________________
// BatArray1Test.java
public class BatArray1Test {
public static void main(String[] args) {
int
array1[]={4,6,7,8,9,10,21};
int
array2[]={4,7,8,9,2,10,21};
if(commonEnd(array1,array2))
{
System.out.println("Both arrays having command End");
}
else
{
System.out.println("Both arrays not having command End");
}
int
midArray[]=midThree(array1);
if(midArray!=null)
{
for(int
i=0;i<midArray.length;i++)
{
System.out.println(midArray[i]+" ");
}
}
int
largest=maxTriple(array1);
if(largest!=0)
System.out.println("Largest Value
:"+largest);
}
private static int maxTriple(int[] array1) {
int max=0;
if(array1.length%2==0)
{
return 0;
}
else
{
max=array1[0];
if(max<array1[(array1.length/2)+1])
{
max=array1[(array1.length/2)+1];
}
if(max<array1[array1.length-1])
{
max=array1[array1.length-1];
}
}
return max;
}
private static int[] midThree(int[] array1) {
int arr[]=null;
if(array1.length%2==0 ||
array1.length<3)
{
return
arr;
}
else
{
arr=new
int[3];
arr[0]=array1[0];
arr[1]=array1[(array1.length/2)+1];
arr[2]=array1[array1.length-1];
}
return arr;
}
public static boolean commonEnd(int arr1[],int
arr2[])
{
boolean b=false;
if(arr1==null || arr2==null)
b=false;
else if(arr1.length==0 ||
arr2.length==0)
b=false;
if(arr1[0]==arr2[0] &&
arr1[arr1.length-1]==arr2[arr2.length-1])
b=true;
return b;
}
}
_________________________
Output:
Both arrays having command End
4
9
21
Largest Value :21
_______________Could you plz rate me well.Thank
You
Please use java code. Implement a test class named BatArray1Test that tests all the functionality of...
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(...
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...
Create a new ArrayPractice project in Eclipse and a class named ArrayPractice.java. Put everything that follows into the main method except the method arrayAverage. Create a 5 element array of doubles called grades that contains the following numbers in this order: 81.2, 92.5, 48.9, 78.8, and 45.5. Create a 7 element array of ints called numbers that contains the following numbers in this order: 12, 42, 33, 67, 92, 58, and 33. Create a 9 element array of Strings called...
Programming in java In this part of this Lab exercise, you will need to create a new class named ArrayShiftMult. This class carries out simple manipulation of an array. Then you should add a main method to this class to check that your code does what it is supposed to do. 1. Create a BlueJ project named LAB06 as follows: a. Open the P drive and create a folder named Blue), if it does not exist already. Under this folder,...
HW58.1. Array Merge Sort You've done merge (on Lists), so now it's time to do merge sort (on arrays). Create a public non-final class named Mergesort that extends Merge. Implement a public static method int[] mergesort(int[] values) that returns the input array of ints sorted in ascending order. You will want this method to be recursive, with the base case being an array with zero or one value. If the passed array is null you should return null. If the...
3. Write Java methods to accomplish each of the following Write a method named simpleAry which accepts and return nothing. It creates an array that can hold ten integers. Fill up each slot of the array with the number 113. Then, display the contents of the array on the screen. You must use a loop to put the values in the array and also to display them. Write a method named sury which accepts an array of type double with...
Java arrays Create method named repeatedN that takes two integer parameters named range and n and returns an integer array Method should return an integer array that has numbers 0 - range repeated in order n times If range is less than or equal to 0; return an array that has 0 repeated n times Create a second method named printArray that takes an integer array as a parameter. The method should print out every element on the same line...
Please help me with this code. Thank you Implement the following Java class: Vehicle Class should contain next instance variables: Integer numberOfWheels; Double engineCapacity; Boolean isElectric, String manufacturer; Array of integers productionYears; Supply your class with: Default constructor (which sets all variables to their respective default values) Constructor which accepts all the variables All the appropriate getters and setters (you may skip comments for this methods. Also, make sure that for engineCapacity setter method you check first if the vehicle...
please do all in C++ code, thank you. Worth 1 point Checkpoint 7.12 Write a statement that assigns the value 10 to the first elementof an array of integers named minutes. Type your program submission here Worth 1 point Checkpoint 7.14 Write a cout statement that will display contents of the second element of an array named courseNumbers Type your program submission here Submit Worth 1 point Checkpoint 7.15 Write a cin statement that will store the user's input in...
Intro to java project template with instructions below * IntegerSet.java */ /** * * @author StudentName */ public class IntegerSet { /** * Creates a new instance of IntegerSet */ // TODO: implement the constructor /** * Return a new IntegerSet containing the union of the two IntegerSet objects * passed as arguments */ // TODO: implement the union method /** * Return a new IntegerSet containing the intersection of the two IntegerSet objects * passed...