write this program in simple java launguge using arrays Write a program that use
ID: 3865941 • 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.*;
public class A
{
public static void main(String args[])
{
int n;
int a[]=new int[n];
int b[]=new int[n];
double c[]=new double[n];
String [ ] d = new String [n];
Scanner in=new Scanner(System.in);
System.out.println("enter n value");
n=in.nextInt();
System.out.println("enter array of client IDs");
for (int i = 0; i <n; i++)
{
a[i] =in.nextInt();
}
System.out.println("enter array of pets");
for (int i = 0; i <n; i++)
{
b[i] =in.nextInt();
}
System.out.println("enter array of outstanding balance");
for (int i = 0; i <n; i++)
{
c[i] =in.nextDouble();
}
System.out.println("enter array of client names");
for (int i = 0; i <n; i++)
{
d[i] =in.nextLine();
}
int sum=0;
for(i=0;i<n;i++)
sum+=b[i];
double avg=sum/n;
System.out.println("average of pets:"+avg);
System.out.println("enter client ID:");
int k=in.nextInt();
for(i=0;i<n;i++)
{if(a[i]==k)
break;
else
{if(i==n)
System.out.println("ID not found");}
}
if(i<=n-1){
System.out.println("clients name:"+d[i];
System.out.println("no.of pets:"+b[i]);
System.out.println("outstanding balance:"+c[i]);
}
double high=0;
for(i=0;i<n;i++)
{
if(a[i]>high){
high=a[i];
int j=i;}
}
System.out.println("highest outstanding balance client name:"+d[j]+" outstanding balance:
import java.util.*;
public class HelloWorld
{
public static void main(String args[])
{
int n;
int a[]=new int[n];
int b[]=new int[n];
double c[]=new double[n];
String [ ] d = new String [n];
Scanner in=new Scanner(System.in);
System.out.println("enter n value");
n=in.nextInt();
System.out.println("enter array of client IDs");
for (int i = 0; i <n; i++)
{
a[i] =in.nextInt();
}
System.out.println("enter array of pets");
for (int i = 0; i <n; i++)
{
b[i] =in.nextInt();
}
System.out.println("enter array of outstanding balance");
for (int i = 0; i <n; i++)
{
c[i] =in.nextDouble();
}
System.out.println("enter array of client names");
for (int i = 0; i <n; i++)
{
d[i] =in.nextLine();
}
int sum=0;
for(i=0;i<n;i++)
sum+=b[i];
double avg=sum/n;
System.out.println("average of pets:"+avg);
System.out.println("enter client ID:");
int k=in.nextInt();
for(i=0;i<n;i++)
{if(a[i]==k)
break;
else
{if(i==n)
System.out.println("ID not found");}
}
if(i<=n-1){
System.out.println("clients name:"+d[i]);
System.out.println("no.of pets:"+b[i]);
System.out.println("outstanding balance:"+c[i]);
}
double high=0;
int j=0;
for(int i=0;i<n;i++)
{
if(c[i]>high)
{
high=c[i];
j=i;
}
}
System.out.println("highest outstanding balance client name:"+c[j]);
}
}
"+c[j]);
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.