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

The second photo it has the array that u supposed to use in the actual program A

ID: 3734904 • Letter: T

Question

The second photo it has the array that u supposed to use in the actual program Account Validation (AccountNumberSearch.iava)l Create a program that allows the user to enter an account number and prints if the number entered exists in the array provided in the source code Your program must: First sort the array into descending order. You must implement a bubble sort, insertion sort, or selection sort algorithm. Do not use an external class like the Arrays object. o o Then, prompt the user to enter a seven-digit account number. Implement a binary search to determine if the number the user entered exists in the array. Again, do not use an external class like the Arrays object. o If it does exist, print that the account number is valid and end the program. Otherwise, print that the account number is invalid and allow the user to try again o Sample Input/Output Account does not exist. Try again Please enter an account number: 5347659 The account is valdo, e sure to use comments to) d riimant uni ir end

Explanation / Answer

AccountNumberSearch.java

import java.util.Scanner;

public class AccountNumberSearch {

public static void main(String[] args) {

int[] accountNumbers = {7151016, 2330468, 1761406, 1731214,5071218, 1984090, 3922623, 7265960,99823999,5347659,3229601, 5607213,6370765,7189003,4179842,5928341,2986639,7169441,9087029,6702898};

bubbleSort(accountNumbers);

Scanner scan = new Scanner(System.in);

System.out.println("Please enter an account number:");

int key = scan.nextInt();

while(binarySearch(accountNumbers, key) == -1) {

System.out.println("Account does not exist. Try again");

System.out.println("Please enter an account number:");

key = scan.nextInt();

}

System.out.println("The account is valid");

}

public static int binarySearch(int[] inputArr, int key) {

int stepsCount = 0;

int start = 0;

int end = inputArr.length - 1;

while (start <= end) {

stepsCount++;

int mid = (start + end) / 2;

if (key == inputArr[mid]) {

return mid;

}

if (key < inputArr[mid]) {

end = mid - 1;

} else {

start = mid + 1;

}

}

return -1;

}

public static void bubbleSort(int[] array) {

int n = array.length;

int temp;

for (int i = 0; i < n; i++) {

int j = 1;

while (j < (n - i)) {

if (array[j - 1] > array[j]) {

// swap the elements!

temp = array[j - 1];

array[j - 1] = array[j];

array[j] = temp;

}

j++;

}

}

}

}

Output:

Please enter an account number:
1111111
Account does not exist. Try again
Please enter an account number:
5347659
The account is valid

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