write this program in simple java launguge using arrays Write a program that use
ID: 3865944 • 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
import java.util.*
class Veternity_clinic
{
public static void main(String args[])
{
String[] client_names= new String[5];
Scanner sc = new Scanner(System.in);
int Client_id[]=new int[5];
int Pets[]=new int[5];
Double balance[]=new Double[5];
Double avg_pets=0,large=0;
int id,f=1,pos=0;
System.out.println("-----------------------------------------");
System.out.println("Enter The Details of 5 clients");
for(int i=1;i<=5;i++)
{
System.out.println("Enter The Details of "+i+" Client);
System.out.println("Enter The name of Client: ");
client_names[i]=sc.nextLine();
System.out.println("Enter The id of Client: ");
Client_id[i]=sc.nextInt();
System.out.println("Enter The pet of Client: ");
Pets[i]=sc.nextInt();
System.out.println("Enter The Outstanding Balance of Client: ");
balance[i]=sc.nextDouble();
}
System.out.println("-----------------------------------------");
for(int j=1;j<=5;j++)
{
avg_pets=avg_pets+Pets[j];
}
System.out.println("The Average Number of Pets is "+avg_pets);
System.out.println("-----------------------------------------");
System.out.println("Enter the Client id to search:");
id=sc.nextInt();
for(int k=1;k<=5;k++)
{
if(Client_id[k]==id)
{
f=0;
break;
}
}
if(f==0)
{
System.out.println("The Client Details are Found:");
System.out.println("The Client Name is:"+client_names[k]);
System.out.println("The pets of Client is:"+Pets[k]);
System.out.println("The OutStanding Balance of Client is:"+balance[k]);
}
}
else
{
System.out.println("The Client id Details are Not Found:");
}
System.out.println("-----------------------------------------");
for(int l=1;l<=5;l++)
{
if(large<balance[l]{
large=balance[l];
pos++;
}
}
System.out.println("The The Largest Outastanding balance of Client
is: "+large);
System.out.println(client_names[pos]);
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.