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

Write this code in java. Include a header comment as shown below. Use meaningful

ID: 3907352 • Letter: W

Question

Write this code in java.

Include a header comment as shown below. Use meaningful variables names and inline comments, as well as good use of white space in your code.

/**

* Program Name

*Purpose: few sentences describing the program

* Pseudocode : Write the steps of the program.

*

*/

Program: Please the read the complete prompt before going into coding.

For this lab; you must write a program for a pet store.There will be two parts to complete.

Part 1: Have the program ask the user to enter the number of customers. The based on that value. The User will Be asked to enter each customers name, pet's name and type (such as a dog,cat,fish, etc.). All the information entered by the user must be stored, as this will be used in Part 2 of the program. *Hint: USE ARRAYS*

Part 2: This part, display a menu for user with 4 different options:

1. Search For Customer: This will ask user to enter a customers name.Search through the array, and if found , display that customers name, their pets name, and their pets type. If the customer does not exist, print "Unable to find Customer with that name." If there happen to be multiple customers with the same name, you only need to print the first one.

2. Search For Pet: This is similar to Option 1, however, it will search based on Pet Name, rather than Customer Name.

3. Pet Type Counter: Ask the user to enter a 'Pet Type' (such as dog,cat, etc.). The program will then search through the pet type array, and keep track of how many pet there are with the inputted 'type'. After searching through the entire array, display the total number of pets there are of the specified 'type'.

4. Quit: Allow the program to exit

Allow the user to keep choosing options from the menu until they choose quit.

Extra useful help: Add a 5th option in Part 2 called "New Customer". This will allow the user to add add a customer to the data, along with their Pets Name and type. The rest of Part 2 *The menu choices* should work with the added customers data as well.

Sample Run:

How many customers will be entered? 5

Enter Name 1: Tim

Enter Bob Pet: Chad

What kind of pet is Chad? Dog

Explanation / Answer


Given below is the code for the question.
To indent code in eclipse , select code by pressing ctrl+a and then indent using ctrl+i
Please do rate the answer if it was helpful. Thank you


Pets.java
--------
import java.util.Scanner;

public class Pets {
private static Scanner keyboard = new Scanner(System.in);
private static int menu(){
System.out.println("1. New customer");
System.out.println("2. Search for customer");
System.out.println("3. Search for pet");
System.out.println("4. Count pet type");
System.out.println("5. Quit");
System.out.print("Enter your choice: ");
int choice = keyboard.nextInt();
return choice;
}
public static void main(String[] args) {
int MAX_SIZE = 20;
int size = 0;
String[] customerNames = new String[MAX_SIZE];
String[] petNames = new String[MAX_SIZE];
String[] petTypes = new String[MAX_SIZE];
int choice = 0;
int index, count;
String search;

while(choice != 5){
choice = menu();
switch(choice){
case 1:
size = addCustomer(customerNames, petNames, petTypes, size);
break;
case 2:
System.out.print("Enter customer name to search: ");
search = keyboard.next();
index = searchCustomer(customerNames, size, search);
if(index == -1)
System.out.println("Unable to find Customer with that name.");
else {
System.out.println("Customer name: " + customerNames[index]);
System.out.println("Pet name: " + petNames[index]);
System.out.println("Pet kind: " + petTypes[index]);
}
break;
case 3:
System.out.print("Enter pet name to search: ");
search = keyboard.next();
index = searchPet(petNames, size, search);
if(index == -1)
System.out.println("Unable to find Pet with that name.");
else {
System.out.println("Customer name: " + customerNames[index]);
System.out.println("Pet name: " + petNames[index]);
System.out.println("Pet kind: " + petTypes[index]);
}
break;
case 4:
System.out.print("Which kind of pet to count? ");
search = keyboard.next();
count = countPetType(petTypes, size, search);
System.out.println("There are " + count + " " + search + "(s)");
break;
case 5:
break;
default:
System.out.println("Invalid choice!");
}
}


}
private static int countPetType(String[] petTypes, int size, String search) {
int count = 0;
for(int i = 0; i < size; i++){
if(petTypes[i].equalsIgnoreCase(search))
count++;
}
return count;
}
private static int searchPet(String[] petNames, int size, String search) {
for(int i = 0; i < size; i++){
if(petNames[i].equalsIgnoreCase(search))
return i;
}

return -1;
}
private static int searchCustomer(String[] customerNames, int size, String search) {
for(int i = 0; i < size; i++){
if(customerNames[i].equalsIgnoreCase(search))
return i;
}

return -1;
}

private static int addCustomer(String[] customerNames, String[] petNames, String[] petTypes, int size) {
System.out.print("Enter name: ");
customerNames[size] = keyboard.next();

System.out.print("Enter " + customerNames[size] + " pet: ");
petNames[size] = keyboard.next();

System.out.print("What kind of pet is " + petNames[size] + "? ");
petTypes[size] = keyboard.next();
return size+1;
}

}


output
----
1. New customer
2. Search for customer
3. Search for pet
4. Count pet type
5. Quit
Enter your choice: 1
Enter name: Tim
Enter Tim pet: Chad
What kind of pet is Chad? Dog
1. New customer
2. Search for customer
3. Search for pet
4. Count pet type
5. Quit
Enter your choice: 1
Enter name: Bob
Enter Bob pet: Browny
What kind of pet is Browny? Dog
1. New customer
2. Search for customer
3. Search for pet
4. Count pet type
5. Quit
Enter your choice: 1
Enter name: Alice
Enter Alice pet: Sweety
What kind of pet is Sweety? Cat
1. New customer
2. Search for customer
3. Search for pet
4. Count pet type
5. Quit
Enter your choice: 2
Enter customer name to search: Bob
Customer name: Bob
Pet name: Browny
Pet kind: Dog
1. New customer
2. Search for customer
3. Search for pet
4. Count pet type
5. Quit
Enter your choice: 2
Enter customer name to search: Alice
Customer name: Alice
Pet name: Sweety
Pet kind: Cat
1. New customer
2. Search for customer
3. Search for pet
4. Count pet type
5. Quit
Enter your choice: 3
Enter pet name to search: Dog
Unable to find Pet with that name.
1. New customer
2. Search for customer
3. Search for pet
4. Count pet type
5. Quit
Enter your choice: 3
Enter pet name to search: Browny
Customer name: Bob
Pet name: Browny
Pet kind: Dog
1. New customer
2. Search for customer
3. Search for pet
4. Count pet type
5. Quit
Enter your choice: 4
Which kind of pet to count? Dog
There are 2 Dog(s)
1. New customer
2. Search for customer
3. Search for pet
4. Count pet type
5. Quit
Enter your choice: 4
Which kind of pet to count? Cat
There are 1 Cat(s)
1. New customer
2. Search for customer
3. Search for pet
4. Count pet type
5. Quit
Enter your choice: 5