import java.util.Scanner; public class MaggiePetStore { public static void main(
ID: 3632212 • Letter: I
Question
import java.util.Scanner;public class MaggiePetStore
{
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
//create three arrays for names, ages, and weights
final int SIZE = 3;
String[] petNames = new String[SIZE];
int[] petAges = new int[3];
double[] petWeights = new double[SIZE];
System.out.println("Welcome to Maggie's Pet Shop Management Software!");
System.out.println("-------------------------------------------------");
//the following three methods will ask a user to enter
//names, ages, and weights
//respectively, and store their input into the arrays.
getPetNames(petNames, scan);
getPetAges(petAges, scan);
getPetWeights(petWeights, scan);
//the following two methods compute the youngest pet and
//the heaviest pet,
//and return their index.
int youngestIndex = findYougestPet(petAges);
int heaviestIndex = findHeaviestPet(petWeights);
//print out the results
System.out.println(" The youngest pet in Maggie's shop is "
+ petNames[youngestIndex]
+ ", who is only " + petAges[youngestIndex]
+ " year old.");
System.out.println("The heaviest pet in Maggie's shop is "
+ petNames[heaviestIndex]
+ ", who weights " + petWeights[heaviestIndex]
+ " pounds.");
}
public static void getPetNames(String[] petNames, Scanner scan)
{
//TO BE COMPLETED
}
public static void getPetAges(int[] petAges, Scanner scan)
{
//TO BE COMPLETED
}
public static void getPetWeights(double[] petWeights, Scanner scan)
{
//TO BE COMPLETED
}
public static int findYougestPet(int[] petAges)
{
//TO BE COMPLETED
}
public static int findHeaviestPet(double[] petWeights)
{
//TO BE COMPLETED
}
}
Explanation / Answer
//Method to find Youngest Pet's Index. public static int findYougestPet(int[] petAges) { int youngest=petAges[0]; int index_of_youngest=0; for(int i=0;ipetAges[i]) { youngest=petAges[i]; index_of_youngest=i; } } return index_of_youngest; } //Method to find Index of Heaviest Pet public static int findHeaviestPet(double[] petWeights) { double heaviest=petWeights[0]; int index_of_heaviest=0; for(int i=0;iRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.