Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Need help in coding for Java program. Here is instructions and some source code. Please include comments whenever possible thank you. Side note from Teacher:

Need help in coding for Java program. Here is instructions and some source code. Please include comments whenever possible thank you.

Side note from Teacher:

#2 MinDistance

Please keep in mind that this method is finding the minimum distance for all consecutive pairs of the target in the input array. There may be many pairs with this minimum distance. You will need to check the distance of EVERY consecutive pair of the target value.

For example, if the input was [1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,2] and the target was 2, there are 11 consecutive pairs of 2s in the array and you have to check all of them before you know that the min distance is actually zero (the very last pair).

public class MinDistance{

public static int distance(byte target, byte[] numbers){

image text in transcribed/* purpose: determine the minimal distance between any

* two instances of target in the numbers array

* input : target is the number we are looking for

* numbers is an array of numbers

* output : the method returns

* o) the minimal distance between any two instances

* of target in the numbers array, if there are

* at least two instances of target present, or

* o) -2 if target is not in the numbers array, or

* o) -1 if target appears only once in the numbers array

*/

return -12345;

}

/*

main method can be used for basic test cases. Modify the method to add

more test cases. Your main method will NOT be graded. But, be sure it does

cause your class to not compile.

*/

public static void main(String[] args){

byte[] N = {5 , 3 , 7 , 2 , 3 , 4 , 4 , 7 , 3 , -1 , 3 , 4 , 7 , 5};

System.out.println( distance((byte)5, N));

System.out.println( distance((byte)4, N));

System.out.println( distance((byte)7, N));

System.out.println( distance((byte)3, N));

System.out.println( distance((byte)2, N));

System.out.println( distance((byte)13, N));

}

}

1: Arrays " In the provided MinDistance.java file, complete the distance method. For a given target value, the method returns the minimal distance between any two instances of the target in the input array of numbers defined The distance between two umbers in the array is between them. Consider the following array of numbens to be thenmber of array cells 5372 34 47 3 -1 3 47 5 The distance between the two 5's in the array is 12. The distance between the first two 4's in the array is 0. The minimal distance between any two 3's is 1. The minimal distance between any two 7's is 4. public static int distance(byte target, byte numbers) / purpose: determine the mininal distance betveen any two instances of target in the numbers array * inputtarget is the number ve are looking for numbers is an array of numbers output the method returns o) the minimal distance betveen any tuo instances of target in the nunbers array, if there are at least tuo inatances of target present, or o) -2 if target is not in the nunbers array, or o) -1 if target appears only once in the nunbers array Examples: Let N denote MinDistance-distance( 0bytes.S) w. MinDistance.distancet oyte)4. MinDistance .distance( 0byte)7. N) mure MinDistance.distancel (byte)3,1 MinDistance.distance( (byteo)2, N1 MinDistance. distance( (byte)1-2 the array shown above. 2: Sudoku Checker -In the provided file SudokuChecker. java, complete the following methods

Step by Step Solution

There are 3 Steps involved in it

Step: 1

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

Step: 3

blur-text-image

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

Fundamentals Of Database Management Systems

Authors: Mark L. Gillenson

3rd Edition

978-1119907466

More Books

Students also viewed these Databases questions

Question

Recognize the four core purposes service environments fulfill.

Answered: 1 week ago

Question

Know the three main dimensions of the service environment.

Answered: 1 week ago