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

this portion of the lab during your labsession. Lab Exercise: Comple You\'ll be

ID: 3812361 • Letter: T

Question

this portion of the lab during your labsession. Lab Exercise: Comple You'll be writing a class called Lab11 that gets various information about three pets in Maggie's pet store from the key board, and then outputs some of the notable pets information to the console. The information you'll be getting is as follows: The name of each pet (collected in an array of strings) How old each pet is (collected in an array of ints) Each pet's weight (collected in an array of doubles) After getting all that information, your program should output the following: The age of the youngest pet The weight of the heaviest pet You'll have to implement the following methods: each pet. Also, implements the gesPetNames and getPetAges to read names and ages of each get PetNames o- an non-value-returning (void) method that populates the array with the names of each pet. get PetAges (1- an non-value-returning (void) method that populates the array with the ages of each pet. get?et Weights (1 an non-value-returning (void) method that populates the array with the ages of each pet. findYoungest pet o- a method that finds the youngest Pet and return its index in the array. findleaviestPeto-a method that finds the heaviest Pet and return its index in the array. A sample run of the program should look like the following (bold text indicates user input): Welcome to Maggie's Pet Shop Management Software Pet Names Please enter the name of pet Sparky Please enter the name of pet 2 Muffin elease erter the name of pet Kitty Pet Nges Please enter the age of pet 1

Explanation / Answer

//getPetNames
public static void getPetNames(String[] petNames, Scanner scan){

   System.out.println("Pet Names:");
   for(int i=0;i<3;i++){
       System.out.println("Please enter the name of pet #" +(i+1) +":");
       petNames[i]= scan.next();
   }
      
}

//getPetAges
public static void getPetAges(int[] petAges, Scanner scan){

   System.out.println("Pet Ages:");
   for(int i=0;i<3;i++){
       System.out.println("Please enter the age of pet #" +(i+1) +":");
       petAges[i]= scan.nextInt();
   }
      
}

//getPetWeights

public static void getPetWeights(double[] petWeights, Scanner scan){

   System.out.println("Pet Weights:");
   for(int i=0;i<3;i++){
       System.out.println("Please enter the weight of pet #" +(i+1) +":");
       petWeights[i]= scan.nextDouble();
   }
      
}

//findYoungestPet
public static int findYoungestPet(int[] petAges){
  
   int index=0,age=0;
   for(int i=0;i<3;i++){
      
       if(age>petAges[i]){
           age=petAges[i];
           index=i;
       }
   }
   return index;
      
}

//findHeaviesPet

public static int findHeaviestPet(double[] petWeights){
  
   int index=0;
   double weight=0;
   for(int i=0;i<3;i++){
      
       if(weight<petWeights[i]){
           weight=petWeights[i];
           index=i;
       }
   }
   return index;
      
}