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

write this program in simple java launguge using arrays Write a program that use

ID: 3865945 • Letter: W

Question

write this program in simple java launguge using arrays

Write a program that uses four arrays in parallel to store information about clients in a veterinary clinic. To save time with data entry, the clinic will have only five clients.
Array of String that holds clients names.
Array of int that holds clients ID numbers,
Array of int that holds number of pets each client owns.
Array of double that holds the outstanding balance of each client.
1) Write the one loop that allows the user to enter the data for each of the arrays.    (be sure to use nextLine( ) to read in a full name).
2) Calculate and print the average number of pets. (The result is a double ie: 2.1).
3) Allow the user to enter a client id. Search the IDs array to locate the position of that client. If found, print that client’s name, number of pets and outstanding balance. If ID is not found, print a message stating that ID was no found.
4) Find and print the name and outstanding balance of client who has the largest outstanding balance.

please list code

Explanation / Answer

Below is your code. Let me know in comments if you have any issue: -

VetRecords.java

import java.util.Scanner;

public class VetRecords {

public static void main(String[] args) {

String[] clientNames = new String[5];

int[] clientIds = new int[5];

int[] numOfPetOwned = new int[5];

double[] outstandings = new double[5];

Scanner sc = new Scanner(System.in);

System.out.println("Please enter client details: ");

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

System.out.println("Please enter the client " + (i + 1) + " name: ");

clientNames[i] = sc.nextLine();

System.out.println("Please enter the client " + (i + 1) + " ID: ");

clientIds[i] = Integer.parseInt(sc.next());

System.out.println("Please enter the number of pets owned by client " + (i + 1));

numOfPetOwned[i] = Integer.parseInt(sc.next());

System.out.println("Please enter the outstanding amount of client " + (i + 1));

outstandings[i] = Double.parseDouble(sc.next());

sc.nextLine();

}

double sumNoPets = 0;

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

sumNoPets = sumNoPets + numOfPetOwned[i];

}

int searchID;

System.out.println(" Average number of pets owned = "+sumNoPets/numOfPetOwned.length);

System.out.print(" Please enter a client ID to search for: ");

searchID = Integer.parseInt(sc.next());

int i;

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

if(searchID == clientIds[i]) {

break;

}

}

if(i == clientIds.length) {

System.out.println("Client Id not found.");

} else {

System.out.println("Client Name: "+clientNames[i]);

System.out.println("Number of Pets: "+numOfPetOwned[i]);

System.out.println("Outstanding Balance: "+outstandings[i]);

}

System.out.println("Client with largest outstanding balance is: ");

int j;

double max = outstandings[0];

int maxJ = 0;

for (j = 1; j < outstandings.length; j++) {

if(outstandings[j] > max) {

maxJ = j;

}

}

System.out.println("Client name: "+clientNames[maxJ]);

System.out.println("Outstanding Amount: "+outstandings[maxJ]);

sc.close();

}

}

Sample Run: -

Please enter client details:
Please enter the client 1 name:
Sushil Kumar
Please enter the client 1 ID:
1
Please enter the number of pets owned by client 1
3
Please enter the outstanding amount of client 1
1000
Please enter the client 2 name:
Piyush
Please enter the client 2 ID:
2
Please enter the number of pets owned by client 2
5
Please enter the outstanding amount of client 2
20000
Please enter the client 3 name:
SushmitA
Please enter the client 3 ID:
3
Please enter the number of pets owned by client 3
2
Please enter the outstanding amount of client 3
1000
Please enter the client 4 name:
Siri
Please enter the client 4 ID:
4
Please enter the number of pets owned by client 4
1
Please enter the outstanding amount of client 4
10000
Please enter the client 5 name:
Manoj Kumar
Please enter the client 5 ID:
5
Please enter the number of pets owned by client 5
6
Please enter the outstanding amount of client 5
20000

Average number of pets owned = 3.4

Please enter a client ID to search for: 3
Client Name: SushmitA
Number of Pets: 2
Outstanding Balance: 1000.0
Client with largest outstanding balance is:
Client name: Manoj Kumar
Outstanding Amount: 20000.0