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

Write Java program to do the following: Note: 1- Use array to read and print the

ID: 3667462 • Letter: W

Question

Write Java program to do the following: Note:

1- Use array to read and print the information,

2- Use GLOBAL variable.

- Write a method to read the information (name, Address, and gender) for a number of employee,

-Write a method to print the information of each employee,

-Write a method to write the name of the employees that live in Main st.

Your output should be like below:

Enter the No. of Employee

3

Enter the No. of Information

3

Enter information for employee 0 Name, Address, and Gender

Sara Main Female

Enter information for employee 1 Name, Address, and Gender

Lily Brooks Female

Enter information for employee 2 Name, Address, and Gender

Smith Main Male

The information for employee Sara: Sara Main Female

The information for employee Lily: Lily Brooks Female

The information for employee Smith: Smith Main Male

The Name of employee(s) who live(s) in Main st. is/are

Sara

Smith

Explanation / Answer

import java.util.Scanner;

/**
* @author Srinivas Palli
*
*/
public class EmployeeInfo {
   static String employeeNames[];
   static String employeeInfo[];

   /**
   * method to read data
   *
   * @param i
   */
   public static void readData(int i) {
       Scanner scanner = new Scanner(System.in);
       System.out.println("Enter information for employee " + i
               + " Name, Address, and Gender");
       employeeNames[i] = scanner.next();

       employeeInfo[i] = scanner.next();
       employeeInfo[i] += " " + scanner.next();

   }

   /**
   * method to display
   */
   public static void displayData() {
       for (int i = 0; i < employeeInfo.length; i++) {
           String name = employeeNames[i];
           System.out.println("The information for employee " + name + ": "
                   + name + " " + employeeInfo[i]);

       }

   }

   /**
   *
   * method to display by street name
   *
   * @param streetName
   */
   public static void displayDataStreet(String streetName) {

       System.out.println("The Name of employee(s) who live(s) in "
               + streetName + " st. is/are");
       for (int i = 0; i < employeeInfo.length; i++) {
           String name = employeeNames[i];
           if (employeeInfo[i].contains(streetName))
               System.out.println(name);

       }

   }

   public static void main(String[] args) {
       Scanner scanner = new Scanner(System.in);
       try {
           System.out.print("Enter the No. of Employee:");
           int noOfEmployees = scanner.nextInt();

           employeeNames = new String[noOfEmployees];
           System.out.print("Enter the No. of Information:");
           int noOfInfo = scanner.nextInt();
           employeeInfo = new String[noOfInfo];
           for (int i = 0; i < noOfEmployees; i++) {
               readData(i);
           }

           displayData();
           displayDataStreet("Main");

       } catch (Exception e) {
           // TODO: handle exception
       }

   }
}

OUTPUT:

Enter the No. of Employee:3
Enter the No. of Information:3
Enter information for employee 0 Name, Address, and Gender
Sara Main Female
Enter information for employee 1 Name, Address, and Gender
Lily Brooks Female
Enter information for employee 2 Name, Address, and Gender
Smith Main Male
The information for employee Sara: Sara Main Female
The information for employee Lily: Lily Brooks Female
The information for employee Smith: Smith Main Male
The Name of employee(s) who live(s) in Main st. is/are
Sara
Smith

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote